blob: e61887704ecf0d7b70cbbe0ca645822446414d16 [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#
James E. King, III330b3f82017-01-23 08:52:04 -050019cmake_minimum_required(VERSION 2.8.12)
Pascal Bach6eb015a2014-04-17 16:19:07 +020020
Nobuaki Sukegawad8c6a842016-10-02 14:21:55 +090021configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h)
James E. King, III7edc8fa2017-01-20 10:11:41 -050022if(MSVC)
23 # The winflexbison generator outputs some macros that conflict with the Visual Studio 2010 copy of stdint.h
24 # This might be fixed in later versions of Visual Studio, but an easy solution is to include stdint.h first
25 if(HAVE_STDINT_H)
James E. King, IIId7142b72017-09-01 13:00:36 -070026 add_definitions(-D__STDC_FORMAT_MACROS)
James E. King, III7edc8fa2017-01-20 10:11:41 -050027 add_definitions(-D__STDC_LIMIT_MACROS)
28 add_definitions(/FI"stdint.h")
29 endif(HAVE_STDINT_H)
30endif()
Pascal Bach6eb015a2014-04-17 16:19:07 +020031
32find_package(FLEX REQUIRED)
33find_package(BISON REQUIRED)
34
James E. King, III330b3f82017-01-23 08:52:04 -050035# create directory for thrifty and thriftl
36file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/thrift/)
37
Pascal Bach6eb015a2014-04-17 16:19:07 +020038# Create flex and bison files and build the lib parse static library
dtmuller052abc32016-07-26 11:58:28 +020039BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc)
40FLEX_TARGET(thriftl ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc)
Pascal Bach6eb015a2014-04-17 16:19:07 +020041ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty)
42
James E. King, III330b3f82017-01-23 08:52:04 -050043set(parse_SOURCES
dtmuller052abc32016-07-26 11:58:28 +020044 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc
45 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc
James E. King, III330b3f82017-01-23 08:52:04 -050046 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.hh
Pascal Bach6eb015a2014-04-17 16:19:07 +020047)
48
James E. King, III330b3f82017-01-23 08:52:04 -050049add_library(parse STATIC ${parse_SOURCES})
Pascal Bach6eb015a2014-04-17 16:19:07 +020050
51# Create the thrift compiler
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090052set(compiler_core
dtmuller052abc32016-07-26 11:58:28 +020053 src/thrift/common.cc
54 src/thrift/generate/t_generator.cc
55 src/thrift/parse/t_typedef.cc
56 src/thrift/parse/parse.cc
57 ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090058)
59
60set(thrift-compiler_SOURCES
dtmuller052abc32016-07-26 11:58:28 +020061 src/thrift/main.cc
62 src/thrift/audit/t_audit.cpp
Pascal Bach6eb015a2014-04-17 16:19:07 +020063)
64
nsrtvwls014f53f2018-09-28 08:11:21 -070065set(thrift_compiler_LANGS
66)
67
Pascal Bach6eb015a2014-04-17 16:19:07 +020068# This macro adds an option THRIFT_COMPILER_${NAME}
69# that allows enabling or disabling certain languages
70macro(THRIFT_ADD_COMPILER name description initial)
71 string(TOUPPER "THRIFT_COMPILER_${name}" enabler)
dtmuller052abc32016-07-26 11:58:28 +020072 set(src "src/thrift/generate/t_${name}_generator.cc")
Pascal Bach6eb015a2014-04-17 16:19:07 +020073 option(${enabler} ${description} ${initial})
74 if(${enabler})
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090075 list(APPEND thrift-compiler_SOURCES ${src})
nsrtvwls014f53f2018-09-28 08:11:21 -070076 list(APPEND thrift_compiler_LANGS ${name})
Pascal Bach6eb015a2014-04-17 16:19:07 +020077 endif()
78endmacro()
79
80# The following compiler can be enabled or disabled
81THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON)
82THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON)
83THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON)
84THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" ON)
Mark Erickson932c4702015-08-29 10:46:51 -050085THRIFT_ADD_COMPILER(dart "Enable compiler for Dart" ON)
Jens Geyerbd52f1a2014-07-28 01:25:30 +020086THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020087THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" ON)
Volodymyr Gotrab587a122016-09-14 19:18:48 -050088THRIFT_ADD_COMPILER(netcore "Enable compiler for .NET Core" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020089THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON)
90THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON)
91THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON)
92THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON)
93THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" ON)
94THRIFT_ADD_COMPILER(cocoa "Enable compiler for Cocoa Objective-C" ON)
Jens Geyer56e5b9b2015-10-09 22:01:55 +020095THRIFT_ADD_COMPILER(swift "Enable compiler for Cocoa Swift" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020096THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON)
97THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON)
98THRIFT_ADD_COMPILER(hs "Enable compiler for Haskell" ON)
99THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON)
100THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" ON)
101THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON)
Roger Meier1a74d9c2014-10-12 23:35:43 +0200102THRIFT_ADD_COMPILER(json "Enable compiler for JSON" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200103THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON)
104THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" ON)
105THRIFT_ADD_COMPILER(go "Enable compiler for Go" ON)
106THRIFT_ADD_COMPILER(d "Enable compiler for D" ON)
107THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON)
Stig Bakken41e8cbf2016-02-12 16:33:12 +0100108THRIFT_ADD_COMPILER(gv "Enable compiler for GraphViz" ON)
Allen George8b96bfb2016-11-02 08:01:08 -0400109THRIFT_ADD_COMPILER(rs "Enable compiler for Rust" ON)
Stig Bakken41e8cbf2016-02-12 16:33:12 +0100110THRIFT_ADD_COMPILER(xml "Enable compiler for XML" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200111
112# Thrift is looking for include files in the src directory
113# we also add the current binary directory for generated files
114include_directories(${CMAKE_CURRENT_BINARY_DIR} src)
115
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900116if(NOT ${WITH_PLUGIN})
117 list(APPEND thrift-compiler_SOURCES ${compiler_core})
118endif()
James E. King, III330b3f82017-01-23 08:52:04 -0500119
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900120add_executable(thrift-compiler ${thrift-compiler_SOURCES})
121
122if(${WITH_PLUGIN})
123 add_executable(thrift-bootstrap ${compiler_core}
dtmuller052abc32016-07-26 11:58:28 +0200124 src/thrift/main.cc
125 src/thrift/audit/t_audit.cpp
126 src/thrift/generate/t_cpp_generator.cc
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900127 )
James E. King, III330b3f82017-01-23 08:52:04 -0500128 target_link_libraries(thrift-bootstrap parse)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900129
130 set(PLUGIN_GEN_SOURCES
dtmuller052abc32016-07-26 11:58:28 +0200131 ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_types.h
132 ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_types.cpp
133 ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_constants.h
134 ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_constants.cpp
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900135 )
136
dtmuller052abc32016-07-26 11:58:28 +0200137 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900138 add_custom_command(OUTPUT ${PLUGIN_GEN_SOURCES}
dtmuller052abc32016-07-26 11:58:28 +0200139 DEPENDS thrift-bootstrap src/thrift/plugin/plugin.thrift
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900140 COMMAND thrift-bootstrap -gen cpp
dtmuller052abc32016-07-26 11:58:28 +0200141 -out ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin
142 ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/plugin/plugin.thrift
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900143 )
144
145 include_directories(../../lib/cpp/src)
146
147 include(ThriftMacros)
148 ADD_LIBRARY_THRIFT(thriftc
149 ${compiler_core}
150 ${PLUGIN_GEN_SOURCES}
dtmuller052abc32016-07-26 11:58:28 +0200151 src/thrift/logging.cc
152 src/thrift/plugin/plugin_output.cc
153 src/thrift/plugin/plugin.cc
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900154 )
155 TARGET_INCLUDE_DIRECTORIES_THRIFT(thriftc PUBLIC ${Boost_INCLUDE_DIRS})
156 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftc thrift PUBLIC)
157 target_compile_definitions(thrift-compiler PUBLIC THRIFT_ENABLE_PLUGIN)
158 LINK_AGAINST_THRIFT_LIBRARY(thrift-compiler thriftc)
159endif()
160
James E. King, III330b3f82017-01-23 08:52:04 -0500161set_target_properties(thrift-compiler PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin/)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100162set_target_properties(thrift-compiler PROPERTIES OUTPUT_NAME thrift)
Pascal Bach42be4e82014-04-23 18:19:06 +0200163
James E. King, III330b3f82017-01-23 08:52:04 -0500164target_link_libraries(thrift-compiler parse)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200165
James E. King, III330b3f82017-01-23 08:52:04 -0500166install(TARGETS thrift-compiler DESTINATION bin)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900167
dtmuller052abc32016-07-26 11:58:28 +0200168if(${WITH_PLUGIN})
169 # Install the headers
170 install(FILES
171 "src/thrift/common.h"
172 "src/thrift/globals.h"
173 "src/thrift/logging.h"
174 "src/thrift/main.h"
175 "src/thrift/platform.h"
Nobuaki Sukegawad8c6a842016-10-02 14:21:55 +0900176 "${CMAKE_BINARY_DIR}/compiler/cpp/thrift/version.h"
dtmuller052abc32016-07-26 11:58:28 +0200177 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift")
178 install(FILES
179 "src/thrift/audit/t_audit.h"
180 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/audit")
181 install(FILES
182 "src/thrift/generate/t_generator.h"
183 "src/thrift/generate/t_generator_registry.h"
184 "src/thrift/generate/t_html_generator.h"
185 "src/thrift/generate/t_oop_generator.h"
186 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/generate")
187 install(FILES
188 "src/thrift/parse/t_base_type.h"
189 "src/thrift/parse/t_const.h"
190 "src/thrift/parse/t_const_value.h"
191 "src/thrift/parse/t_container.h"
192 "src/thrift/parse/t_doc.h"
193 "src/thrift/parse/t_enum.h"
194 "src/thrift/parse/t_enum_value.h"
195 "src/thrift/parse/t_field.h"
196 "src/thrift/parse/t_function.h"
197 "src/thrift/parse/t_list.h"
198 "src/thrift/parse/t_map.h"
199 "src/thrift/parse/t_program.h"
200 "src/thrift/parse/t_scope.h"
201 "src/thrift/parse/t_service.h"
202 "src/thrift/parse/t_set.h"
203 "src/thrift/parse/t_struct.h"
204 "src/thrift/parse/t_typedef.h"
205 "src/thrift/parse/t_type.h"
206 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/parse")
207 install(FILES
208 "src/thrift/plugin/plugin.h"
209 "src/thrift/plugin/plugin_output.h"
210 "src/thrift/plugin/type_util.h"
211 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/plugin")
212if(MSVC)
213 install(FILES
214 "src/thrift/windows/config.h"
215 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/windows")
dtmuller052abc32016-07-26 11:58:28 +0200216endif()
217endif()
218
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900219if(BUILD_TESTING)
220 add_subdirectory(test)
221endif()