blob: 48cadbc1d3de0ceea51bf69a1145c1dde3debff1 [file] [log] [blame]
Pascal Bach6eb015a2014-04-17 16:19:07 +02001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
Pascal Bach6eb015a2014-04-17 16:19:07 +020020# Windows has a different header
Pascal Bach569863a2014-06-10 13:15:40 +020021if(MSVC)
Pascal Bach6eb015a2014-04-17 16:19:07 +020022 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/windows/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
23else()
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090024 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
Pascal Bach6eb015a2014-04-17 16:19:07 +020025endif()
26
27find_package(FLEX REQUIRED)
28find_package(BISON REQUIRED)
29
30# Create flex and bison files and build the lib parse static library
31BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc)
Roger Meier86fded22015-05-15 12:01:38 +020032FLEX_TARGET(thriftl ${CMAKE_CURRENT_SOURCE_DIR}/src/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc)
Pascal Bach6eb015a2014-04-17 16:19:07 +020033ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty)
34
35# HACK: Work around the fact that bison crates a .hh file but we need a .h file
36add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
37 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
38 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh
39 )
40
41set(libparse_SOURCES
42 ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc
43 ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc
44 ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
45)
46
47add_library(libparse STATIC ${libparse_SOURCES})
48
49# Create the thrift compiler
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090050set(compiler_core
51 src/common.cc
Pascal Bach6eb015a2014-04-17 16:19:07 +020052 src/generate/t_generator.cc
Pascal Bach6eb015a2014-04-17 16:19:07 +020053 src/parse/t_typedef.cc
Pascal Bach6eb015a2014-04-17 16:19:07 +020054 src/parse/parse.cc
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090055 ${CMAKE_CURRENT_BINARY_DIR}/version.h
56)
57
58set(thrift-compiler_SOURCES
59 src/main.cc
60 src/audit/t_audit.cpp
Pascal Bach6eb015a2014-04-17 16:19:07 +020061)
62
63# This macro adds an option THRIFT_COMPILER_${NAME}
64# that allows enabling or disabling certain languages
65macro(THRIFT_ADD_COMPILER name description initial)
66 string(TOUPPER "THRIFT_COMPILER_${name}" enabler)
67 set(src "src/generate/t_${name}_generator.cc")
68 option(${enabler} ${description} ${initial})
69 if(${enabler})
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090070 list(APPEND thrift-compiler_SOURCES ${src})
Pascal Bach6eb015a2014-04-17 16:19:07 +020071 endif()
72endmacro()
73
74# The following compiler can be enabled or disabled
75THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON)
76THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON)
77THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON)
78THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" ON)
Mark Erickson932c4702015-08-29 10:46:51 -050079THRIFT_ADD_COMPILER(dart "Enable compiler for Dart" ON)
Jens Geyerbd52f1a2014-07-28 01:25:30 +020080THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020081THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" ON)
82THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON)
83THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON)
84THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON)
85THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON)
86THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" ON)
87THRIFT_ADD_COMPILER(cocoa "Enable compiler for Cocoa Objective-C" ON)
Jens Geyer56e5b9b2015-10-09 22:01:55 +020088THRIFT_ADD_COMPILER(swift "Enable compiler for Cocoa Swift" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020089THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON)
90THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON)
91THRIFT_ADD_COMPILER(hs "Enable compiler for Haskell" ON)
92THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON)
93THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" ON)
94THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON)
Roger Meier1a74d9c2014-10-12 23:35:43 +020095THRIFT_ADD_COMPILER(json "Enable compiler for JSON" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020096THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON)
97THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" ON)
98THRIFT_ADD_COMPILER(go "Enable compiler for Go" ON)
99THRIFT_ADD_COMPILER(d "Enable compiler for D" ON)
100THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON)
Stig Bakken41e8cbf2016-02-12 16:33:12 +0100101THRIFT_ADD_COMPILER(gv "Enable compiler for GraphViz" ON)
102THRIFT_ADD_COMPILER(xml "Enable compiler for XML" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200103
104# Thrift is looking for include files in the src directory
105# we also add the current binary directory for generated files
106include_directories(${CMAKE_CURRENT_BINARY_DIR} src)
107
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900108if(NOT ${WITH_PLUGIN})
109 list(APPEND thrift-compiler_SOURCES ${compiler_core})
110endif()
111add_executable(thrift-compiler ${thrift-compiler_SOURCES})
112
113if(${WITH_PLUGIN})
114 add_executable(thrift-bootstrap ${compiler_core}
115 src/main.cc
116 src/audit/t_audit.cpp
117 src/generate/t_cpp_generator.cc
118 )
119 target_link_libraries(thrift-bootstrap libparse)
120
121 set(PLUGIN_GEN_SOURCES
122 ${CMAKE_CURRENT_BINARY_DIR}/plugin/plugin_types.h
123 ${CMAKE_CURRENT_BINARY_DIR}/plugin/plugin_types.cpp
124 ${CMAKE_CURRENT_BINARY_DIR}/plugin/plugin_constants.h
125 ${CMAKE_CURRENT_BINARY_DIR}/plugin/plugin_constants.cpp
126 )
127
128 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/plugin)
129 add_custom_command(OUTPUT ${PLUGIN_GEN_SOURCES}
130 DEPENDS thrift-bootstrap src/plugin/plugin.thrift
131 COMMAND thrift-bootstrap -gen cpp
132 -out ${CMAKE_CURRENT_BINARY_DIR}/plugin
133 ${CMAKE_CURRENT_SOURCE_DIR}/src/plugin/plugin.thrift
134 )
135
136 include_directories(../../lib/cpp/src)
137
138 include(ThriftMacros)
139 ADD_LIBRARY_THRIFT(thriftc
140 ${compiler_core}
141 ${PLUGIN_GEN_SOURCES}
142 src/logging.cc
143 src/plugin/plugin_output.cc
144 src/plugin/plugin.cc
145 )
146 TARGET_INCLUDE_DIRECTORIES_THRIFT(thriftc PUBLIC ${Boost_INCLUDE_DIRS})
147 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftc thrift PUBLIC)
148 target_compile_definitions(thrift-compiler PUBLIC THRIFT_ENABLE_PLUGIN)
149 LINK_AGAINST_THRIFT_LIBRARY(thrift-compiler thriftc)
150endif()
151
Pascal Bachd5f87e12014-12-12 15:59:17 +0100152set_target_properties(thrift-compiler PROPERTIES OUTPUT_NAME thrift)
Pascal Bach42be4e82014-04-23 18:19:06 +0200153
Pascal Bachd5f87e12014-12-12 15:59:17 +0100154target_link_libraries(thrift-compiler libparse)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200155
Pascal Bachd5f87e12014-12-12 15:59:17 +0100156install(TARGETS thrift-compiler DESTINATION "${BIN_INSTALL_DIR}")
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900157
158if(BUILD_TESTING)
159 add_subdirectory(test)
160endif()