blob: 02ed78c6488359f5a8b9f3a1a55271c4f6da4e08 [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
Nobuaki Sukegawad8c6a842016-10-02 14:21:55 +090020configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h)
Pascal Bach6eb015a2014-04-17 16:19:07 +020021
22find_package(FLEX REQUIRED)
23find_package(BISON REQUIRED)
24
25# Create flex and bison files and build the lib parse static library
dtmuller052abc32016-07-26 11:58:28 +020026BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc)
27FLEX_TARGET(thriftl ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc)
Pascal Bach6eb015a2014-04-17 16:19:07 +020028ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty)
29
30# HACK: Work around the fact that bison crates a .hh file but we need a .h file
dtmuller052abc32016-07-26 11:58:28 +020031add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.h
32 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.hh ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.h
33 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.hh
Pascal Bach6eb015a2014-04-17 16:19:07 +020034 )
35
36set(libparse_SOURCES
dtmuller052abc32016-07-26 11:58:28 +020037 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc
38 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc
39 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.h
Pascal Bach6eb015a2014-04-17 16:19:07 +020040)
41
42add_library(libparse STATIC ${libparse_SOURCES})
43
44# Create the thrift compiler
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090045set(compiler_core
dtmuller052abc32016-07-26 11:58:28 +020046 src/thrift/common.cc
47 src/thrift/generate/t_generator.cc
48 src/thrift/parse/t_typedef.cc
49 src/thrift/parse/parse.cc
50 ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090051)
52
53set(thrift-compiler_SOURCES
dtmuller052abc32016-07-26 11:58:28 +020054 src/thrift/main.cc
55 src/thrift/audit/t_audit.cpp
Pascal Bach6eb015a2014-04-17 16:19:07 +020056)
57
58# This macro adds an option THRIFT_COMPILER_${NAME}
59# that allows enabling or disabling certain languages
60macro(THRIFT_ADD_COMPILER name description initial)
61 string(TOUPPER "THRIFT_COMPILER_${name}" enabler)
dtmuller052abc32016-07-26 11:58:28 +020062 set(src "src/thrift/generate/t_${name}_generator.cc")
Pascal Bach6eb015a2014-04-17 16:19:07 +020063 option(${enabler} ${description} ${initial})
64 if(${enabler})
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090065 list(APPEND thrift-compiler_SOURCES ${src})
Pascal Bach6eb015a2014-04-17 16:19:07 +020066 endif()
67endmacro()
68
69# The following compiler can be enabled or disabled
70THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON)
71THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON)
72THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON)
73THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" ON)
Mark Erickson932c4702015-08-29 10:46:51 -050074THRIFT_ADD_COMPILER(dart "Enable compiler for Dart" ON)
Jens Geyerbd52f1a2014-07-28 01:25:30 +020075THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020076THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" ON)
77THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON)
78THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON)
79THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON)
80THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON)
81THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" ON)
82THRIFT_ADD_COMPILER(cocoa "Enable compiler for Cocoa Objective-C" ON)
Jens Geyer56e5b9b2015-10-09 22:01:55 +020083THRIFT_ADD_COMPILER(swift "Enable compiler for Cocoa Swift" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020084THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON)
85THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON)
86THRIFT_ADD_COMPILER(hs "Enable compiler for Haskell" ON)
87THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON)
88THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" ON)
89THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON)
Roger Meier1a74d9c2014-10-12 23:35:43 +020090THRIFT_ADD_COMPILER(json "Enable compiler for JSON" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020091THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON)
92THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" ON)
93THRIFT_ADD_COMPILER(go "Enable compiler for Go" ON)
94THRIFT_ADD_COMPILER(d "Enable compiler for D" ON)
95THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON)
Stig Bakken41e8cbf2016-02-12 16:33:12 +010096THRIFT_ADD_COMPILER(gv "Enable compiler for GraphViz" ON)
97THRIFT_ADD_COMPILER(xml "Enable compiler for XML" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020098
99# Thrift is looking for include files in the src directory
100# we also add the current binary directory for generated files
101include_directories(${CMAKE_CURRENT_BINARY_DIR} src)
102
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900103if(NOT ${WITH_PLUGIN})
104 list(APPEND thrift-compiler_SOURCES ${compiler_core})
105endif()
106add_executable(thrift-compiler ${thrift-compiler_SOURCES})
107
108if(${WITH_PLUGIN})
109 add_executable(thrift-bootstrap ${compiler_core}
dtmuller052abc32016-07-26 11:58:28 +0200110 src/thrift/main.cc
111 src/thrift/audit/t_audit.cpp
112 src/thrift/generate/t_cpp_generator.cc
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900113 )
114 target_link_libraries(thrift-bootstrap libparse)
115
116 set(PLUGIN_GEN_SOURCES
dtmuller052abc32016-07-26 11:58:28 +0200117 ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_types.h
118 ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_types.cpp
119 ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_constants.h
120 ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_constants.cpp
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900121 )
122
dtmuller052abc32016-07-26 11:58:28 +0200123 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900124 add_custom_command(OUTPUT ${PLUGIN_GEN_SOURCES}
dtmuller052abc32016-07-26 11:58:28 +0200125 DEPENDS thrift-bootstrap src/thrift/plugin/plugin.thrift
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900126 COMMAND thrift-bootstrap -gen cpp
dtmuller052abc32016-07-26 11:58:28 +0200127 -out ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin
128 ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/plugin/plugin.thrift
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900129 )
130
131 include_directories(../../lib/cpp/src)
132
133 include(ThriftMacros)
134 ADD_LIBRARY_THRIFT(thriftc
135 ${compiler_core}
136 ${PLUGIN_GEN_SOURCES}
dtmuller052abc32016-07-26 11:58:28 +0200137 src/thrift/logging.cc
138 src/thrift/plugin/plugin_output.cc
139 src/thrift/plugin/plugin.cc
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900140 )
141 TARGET_INCLUDE_DIRECTORIES_THRIFT(thriftc PUBLIC ${Boost_INCLUDE_DIRS})
142 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftc thrift PUBLIC)
143 target_compile_definitions(thrift-compiler PUBLIC THRIFT_ENABLE_PLUGIN)
144 LINK_AGAINST_THRIFT_LIBRARY(thrift-compiler thriftc)
145endif()
146
Pascal Bachd5f87e12014-12-12 15:59:17 +0100147set_target_properties(thrift-compiler PROPERTIES OUTPUT_NAME thrift)
Pascal Bach42be4e82014-04-23 18:19:06 +0200148
Pascal Bachd5f87e12014-12-12 15:59:17 +0100149target_link_libraries(thrift-compiler libparse)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200150
Pascal Bachd5f87e12014-12-12 15:59:17 +0100151install(TARGETS thrift-compiler DESTINATION "${BIN_INSTALL_DIR}")
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900152
dtmuller052abc32016-07-26 11:58:28 +0200153if(${WITH_PLUGIN})
154 # Install the headers
155 install(FILES
156 "src/thrift/common.h"
157 "src/thrift/globals.h"
158 "src/thrift/logging.h"
159 "src/thrift/main.h"
160 "src/thrift/platform.h"
Nobuaki Sukegawad8c6a842016-10-02 14:21:55 +0900161 "${CMAKE_BINARY_DIR}/compiler/cpp/thrift/version.h"
dtmuller052abc32016-07-26 11:58:28 +0200162 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift")
163 install(FILES
164 "src/thrift/audit/t_audit.h"
165 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/audit")
166 install(FILES
167 "src/thrift/generate/t_generator.h"
168 "src/thrift/generate/t_generator_registry.h"
169 "src/thrift/generate/t_html_generator.h"
170 "src/thrift/generate/t_oop_generator.h"
171 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/generate")
172 install(FILES
173 "src/thrift/parse/t_base_type.h"
174 "src/thrift/parse/t_const.h"
175 "src/thrift/parse/t_const_value.h"
176 "src/thrift/parse/t_container.h"
177 "src/thrift/parse/t_doc.h"
178 "src/thrift/parse/t_enum.h"
179 "src/thrift/parse/t_enum_value.h"
180 "src/thrift/parse/t_field.h"
181 "src/thrift/parse/t_function.h"
182 "src/thrift/parse/t_list.h"
183 "src/thrift/parse/t_map.h"
184 "src/thrift/parse/t_program.h"
185 "src/thrift/parse/t_scope.h"
186 "src/thrift/parse/t_service.h"
187 "src/thrift/parse/t_set.h"
188 "src/thrift/parse/t_struct.h"
189 "src/thrift/parse/t_typedef.h"
190 "src/thrift/parse/t_type.h"
191 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/parse")
192 install(FILES
193 "src/thrift/plugin/plugin.h"
194 "src/thrift/plugin/plugin_output.h"
195 "src/thrift/plugin/type_util.h"
196 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/plugin")
197if(MSVC)
198 install(FILES
199 "src/thrift/windows/config.h"
200 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/windows")
dtmuller052abc32016-07-26 11:58:28 +0200201endif()
202endif()
203
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900204if(BUILD_TESTING)
205 add_subdirectory(test)
206endif()