blob: 372cbab75fef3b72bd19f34f5be41a11be83c555 [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 III278528c2019-01-11 12:17:44 -050019
20cmake_minimum_required(VERSION 3.3)
21project("thrift-compiler" VERSION ${PACKAGE_VERSION})
Pascal Bach6eb015a2014-04-17 16:19:07 +020022
Nobuaki Sukegawad8c6a842016-10-02 14:21:55 +090023configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h)
Pascal Bach6eb015a2014-04-17 16:19:07 +020024
25find_package(FLEX REQUIRED)
26find_package(BISON REQUIRED)
27
James E. King, III330b3f82017-01-23 08:52:04 -050028# create directory for thrifty and thriftl
29file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/thrift/)
30
Pascal Bach6eb015a2014-04-17 16:19:07 +020031# Create flex and bison files and build the lib parse static library
dtmuller052abc32016-07-26 11:58:28 +020032BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc)
33FLEX_TARGET(thriftl ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc)
Pascal Bach6eb015a2014-04-17 16:19:07 +020034ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty)
35
James E. King, III330b3f82017-01-23 08:52:04 -050036set(parse_SOURCES
dtmuller052abc32016-07-26 11:58:28 +020037 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc
38 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc
James E. King, III330b3f82017-01-23 08:52:04 -050039 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.hh
Pascal Bach6eb015a2014-04-17 16:19:07 +020040)
41
James E. King, III330b3f82017-01-23 08:52:04 -050042add_library(parse STATIC ${parse_SOURCES})
Pascal Bach6eb015a2014-04-17 16:19:07 +020043
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
nsrtvwls014f53f2018-09-28 08:11:21 -070058set(thrift_compiler_LANGS
59)
60
Pascal Bach6eb015a2014-04-17 16:19:07 +020061# This macro adds an option THRIFT_COMPILER_${NAME}
62# that allows enabling or disabling certain languages
63macro(THRIFT_ADD_COMPILER name description initial)
64 string(TOUPPER "THRIFT_COMPILER_${name}" enabler)
dtmuller052abc32016-07-26 11:58:28 +020065 set(src "src/thrift/generate/t_${name}_generator.cc")
Pascal Bach6eb015a2014-04-17 16:19:07 +020066 option(${enabler} ${description} ${initial})
67 if(${enabler})
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090068 list(APPEND thrift-compiler_SOURCES ${src})
nsrtvwls014f53f2018-09-28 08:11:21 -070069 list(APPEND thrift_compiler_LANGS ${name})
Pascal Bach6eb015a2014-04-17 16:19:07 +020070 endif()
71endmacro()
72
73# The following compiler can be enabled or disabled
Pascal Bach6eb015a2014-04-17 16:19:07 +020074THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" ON)
James E. King III278528c2019-01-11 12:17:44 -050075THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON)
76THRIFT_ADD_COMPILER(cl "Enable compiler for Common LISP" ON)
James E. King III278528c2019-01-11 12:17:44 -050077THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON)
78THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" ON)
79THRIFT_ADD_COMPILER(d "Enable compiler for D" ON)
80THRIFT_ADD_COMPILER(dart "Enable compiler for Dart" ON)
81THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" ON)
82THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" ON)
83THRIFT_ADD_COMPILER(go "Enable compiler for Go" ON)
84THRIFT_ADD_COMPILER(gv "Enable compiler for GraphViz" ON)
85THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020086THRIFT_ADD_COMPILER(hs "Enable compiler for Haskell" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020087THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" ON)
James E. King III278528c2019-01-11 12:17:44 -050088THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON)
89THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020090THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON)
Roger Meier1a74d9c2014-10-12 23:35:43 +020091THRIFT_ADD_COMPILER(json "Enable compiler for JSON" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020092THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON)
James E. King III278528c2019-01-11 12:17:44 -050093THRIFT_ADD_COMPILER(netcore "Enable compiler for .NET Core" ON)
94THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON)
95THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON)
96THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON)
97THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON)
98THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON)
Allen George8b96bfb2016-11-02 08:01:08 -040099THRIFT_ADD_COMPILER(rs "Enable compiler for Rust" ON)
James E. King III278528c2019-01-11 12:17:44 -0500100THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON)
101THRIFT_ADD_COMPILER(swift "Enable compiler for Cocoa Swift" ON)
Stig Bakken41e8cbf2016-02-12 16:33:12 +0100102THRIFT_ADD_COMPILER(xml "Enable compiler for XML" ON)
James E. King III278528c2019-01-11 12:17:44 -0500103THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200104
105# Thrift is looking for include files in the src directory
106# we also add the current binary directory for generated files
107include_directories(${CMAKE_CURRENT_BINARY_DIR} src)
108
louyl9c3d2d62018-12-10 17:20:07 +0800109if(NOT DEFINED WITH_PLUGIN OR NOT ${WITH_PLUGIN})
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900110 list(APPEND thrift-compiler_SOURCES ${compiler_core})
111endif()
James E. King, III330b3f82017-01-23 08:52:04 -0500112
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900113add_executable(thrift-compiler ${thrift-compiler_SOURCES})
114
115if(${WITH_PLUGIN})
116 add_executable(thrift-bootstrap ${compiler_core}
dtmuller052abc32016-07-26 11:58:28 +0200117 src/thrift/main.cc
118 src/thrift/audit/t_audit.cpp
119 src/thrift/generate/t_cpp_generator.cc
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900120 )
James E. King, III330b3f82017-01-23 08:52:04 -0500121 target_link_libraries(thrift-bootstrap parse)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900122
123 set(PLUGIN_GEN_SOURCES
dtmuller052abc32016-07-26 11:58:28 +0200124 ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_types.h
125 ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_types.cpp
126 ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_constants.h
127 ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_constants.cpp
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900128 )
129
dtmuller052abc32016-07-26 11:58:28 +0200130 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900131 add_custom_command(OUTPUT ${PLUGIN_GEN_SOURCES}
dtmuller052abc32016-07-26 11:58:28 +0200132 DEPENDS thrift-bootstrap src/thrift/plugin/plugin.thrift
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900133 COMMAND thrift-bootstrap -gen cpp
dtmuller052abc32016-07-26 11:58:28 +0200134 -out ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin
135 ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/plugin/plugin.thrift
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900136 )
137
138 include_directories(../../lib/cpp/src)
139
140 include(ThriftMacros)
141 ADD_LIBRARY_THRIFT(thriftc
142 ${compiler_core}
143 ${PLUGIN_GEN_SOURCES}
dtmuller052abc32016-07-26 11:58:28 +0200144 src/thrift/logging.cc
145 src/thrift/plugin/plugin_output.cc
146 src/thrift/plugin/plugin.cc
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900147 )
148 TARGET_INCLUDE_DIRECTORIES_THRIFT(thriftc PUBLIC ${Boost_INCLUDE_DIRS})
149 TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftc thrift PUBLIC)
150 target_compile_definitions(thrift-compiler PUBLIC THRIFT_ENABLE_PLUGIN)
151 LINK_AGAINST_THRIFT_LIBRARY(thrift-compiler thriftc)
152endif()
153
James E. King, III330b3f82017-01-23 08:52:04 -0500154set_target_properties(thrift-compiler PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin/)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100155set_target_properties(thrift-compiler PROPERTIES OUTPUT_NAME thrift)
Pascal Bach42be4e82014-04-23 18:19:06 +0200156
James E. King, III330b3f82017-01-23 08:52:04 -0500157target_link_libraries(thrift-compiler parse)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200158
James E. King, III330b3f82017-01-23 08:52:04 -0500159install(TARGETS thrift-compiler DESTINATION bin)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900160
dtmuller052abc32016-07-26 11:58:28 +0200161if(${WITH_PLUGIN})
162 # Install the headers
163 install(FILES
164 "src/thrift/common.h"
165 "src/thrift/globals.h"
166 "src/thrift/logging.h"
167 "src/thrift/main.h"
168 "src/thrift/platform.h"
Nobuaki Sukegawad8c6a842016-10-02 14:21:55 +0900169 "${CMAKE_BINARY_DIR}/compiler/cpp/thrift/version.h"
dtmuller052abc32016-07-26 11:58:28 +0200170 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift")
171 install(FILES
172 "src/thrift/audit/t_audit.h"
173 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/audit")
174 install(FILES
175 "src/thrift/generate/t_generator.h"
176 "src/thrift/generate/t_generator_registry.h"
177 "src/thrift/generate/t_html_generator.h"
178 "src/thrift/generate/t_oop_generator.h"
179 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/generate")
180 install(FILES
181 "src/thrift/parse/t_base_type.h"
182 "src/thrift/parse/t_const.h"
183 "src/thrift/parse/t_const_value.h"
184 "src/thrift/parse/t_container.h"
185 "src/thrift/parse/t_doc.h"
186 "src/thrift/parse/t_enum.h"
187 "src/thrift/parse/t_enum_value.h"
188 "src/thrift/parse/t_field.h"
189 "src/thrift/parse/t_function.h"
190 "src/thrift/parse/t_list.h"
191 "src/thrift/parse/t_map.h"
192 "src/thrift/parse/t_program.h"
193 "src/thrift/parse/t_scope.h"
194 "src/thrift/parse/t_service.h"
195 "src/thrift/parse/t_set.h"
196 "src/thrift/parse/t_struct.h"
197 "src/thrift/parse/t_typedef.h"
198 "src/thrift/parse/t_type.h"
199 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/parse")
200 install(FILES
201 "src/thrift/plugin/plugin.h"
202 "src/thrift/plugin/plugin_output.h"
203 "src/thrift/plugin/type_util.h"
204 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/plugin")
205if(MSVC)
206 install(FILES
207 "src/thrift/windows/config.h"
208 DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/windows")
dtmuller052abc32016-07-26 11:58:28 +0200209endif()
210endif()
211
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900212if(BUILD_TESTING)
213 add_subdirectory(test)
214endif()