blob: b0f123555d80936d2483e6ba75ac36a47fbbec77 [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
Jens Geyer71997412019-10-19 21:22:59 +020023# version.h now handled via veralign.sh
24#configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h)
Pascal Bach6eb015a2014-04-17 16:19:07 +020025
26find_package(FLEX REQUIRED)
27find_package(BISON REQUIRED)
28
James E. King, III330b3f82017-01-23 08:52:04 -050029# create directory for thrifty and thriftl
30file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/thrift/)
31
Pascal Bach6eb015a2014-04-17 16:19:07 +020032# Create flex and bison files and build the lib parse static library
dtmuller052abc32016-07-26 11:58:28 +020033BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc)
34FLEX_TARGET(thriftl ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc)
Pascal Bach6eb015a2014-04-17 16:19:07 +020035ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty)
36
James E. King, III330b3f82017-01-23 08:52:04 -050037set(parse_SOURCES
dtmuller052abc32016-07-26 11:58:28 +020038 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc
39 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc
James E. King, III330b3f82017-01-23 08:52:04 -050040 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.hh
Pascal Bach6eb015a2014-04-17 16:19:07 +020041)
42
James E. King, III330b3f82017-01-23 08:52:04 -050043add_library(parse STATIC ${parse_SOURCES})
Pascal Bach6eb015a2014-04-17 16:19:07 +020044
45# Create the thrift compiler
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090046set(compiler_core
dtmuller052abc32016-07-26 11:58:28 +020047 src/thrift/common.cc
48 src/thrift/generate/t_generator.cc
Simon Wangd5927a92021-09-13 19:50:45 +080049 src/thrift/generate/validator_parser.cc
50 src/thrift/generate/validator_parser.h
dtmuller052abc32016-07-26 11:58:28 +020051 src/thrift/parse/t_typedef.cc
52 src/thrift/parse/parse.cc
Jens Geyer71997412019-10-19 21:22:59 +020053 src/thrift/version.h
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090054)
55
56set(thrift-compiler_SOURCES
dtmuller052abc32016-07-26 11:58:28 +020057 src/thrift/main.cc
58 src/thrift/audit/t_audit.cpp
Pascal Bach6eb015a2014-04-17 16:19:07 +020059)
60
nsrtvwls014f53f2018-09-28 08:11:21 -070061set(thrift_compiler_LANGS
62)
63
Pascal Bach6eb015a2014-04-17 16:19:07 +020064# This macro adds an option THRIFT_COMPILER_${NAME}
65# that allows enabling or disabling certain languages
66macro(THRIFT_ADD_COMPILER name description initial)
67 string(TOUPPER "THRIFT_COMPILER_${name}" enabler)
dtmuller052abc32016-07-26 11:58:28 +020068 set(src "src/thrift/generate/t_${name}_generator.cc")
Pascal Bach6eb015a2014-04-17 16:19:07 +020069 option(${enabler} ${description} ${initial})
70 if(${enabler})
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090071 list(APPEND thrift-compiler_SOURCES ${src})
nsrtvwls014f53f2018-09-28 08:11:21 -070072 list(APPEND thrift_compiler_LANGS ${name})
Pascal Bach6eb015a2014-04-17 16:19:07 +020073 endif()
74endmacro()
75
Simon Wangd5927a92021-09-13 19:50:45 +080076# This macro adds an option THRIFT_VALIDATOR_COMPILER_${NAME}
77# that allows enabling or disabling certain languages' validator
78macro(THRIFT_ADD_VALIDATOR_COMPILER name description initial)
79 string(TOUPPER "THRIFT_COMPILER_${name}" enabler)
80 set(src "src/thrift/generate/${name}_validator_generator.cc")
81 list(APPEND "src/thrift/generate/${name}_validator_generator.h")
82 option(${enabler} ${description} ${initial})
83 if(${enabler})
84 list(APPEND thrift-compiler_SOURCES ${src})
85 endif()
86endmacro()
87
Pascal Bach6eb015a2014-04-17 16:19:07 +020088# The following compiler can be enabled or disabled
Simon Wangd5927a92021-09-13 19:50:45 +080089THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON)
90THRIFT_ADD_COMPILER(cl "Enable compiler for Common LISP" ON)
91THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON)
92THRIFT_ADD_COMPILER(d "Enable compiler for D" ON)
93THRIFT_ADD_COMPILER(dart "Enable compiler for Dart" ON)
94THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" ON)
95THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" ON)
96THRIFT_ADD_COMPILER(go "Enable compiler for Go" ON)
97THRIFT_ADD_COMPILER(gv "Enable compiler for GraphViz" ON)
98THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" ON)
99THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" ON)
100THRIFT_ADD_COMPILER(markdown "Enable compiler for Markdown Documentation" ON)
101THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON)
102THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON)
103THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON)
104THRIFT_ADD_COMPILER(json "Enable compiler for JSON" ON)
105THRIFT_ADD_COMPILER(kotlin "Enable compiler for Kotlin" ON)
106THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON)
107THRIFT_ADD_COMPILER(netstd "Enable compiler for .NET Standard" ON)
108THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON)
109THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON)
110THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON)
111THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON)
112THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON)
113THRIFT_ADD_COMPILER(rs "Enable compiler for Rust" ON)
114THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON)
115THRIFT_ADD_COMPILER(swift "Enable compiler for Cocoa Swift" ON)
116THRIFT_ADD_COMPILER(xml "Enable compiler for XML" ON)
117THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON)
118
119# The following compiler can be enabled or disabled by enabling or disabling certain languages
120THRIFT_ADD_VALIDATOR_COMPILER(go "Enable validator compiler for Go" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200121
122# Thrift is looking for include files in the src directory
123# we also add the current binary directory for generated files
124include_directories(${CMAKE_CURRENT_BINARY_DIR} src)
125
James E. King III29f7f8f2019-01-26 09:15:19 -0500126list(APPEND thrift-compiler_SOURCES ${compiler_core})
James E. King, III330b3f82017-01-23 08:52:04 -0500127
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900128add_executable(thrift-compiler ${thrift-compiler_SOURCES})
129
James E. King, III330b3f82017-01-23 08:52:04 -0500130set_target_properties(thrift-compiler PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin/)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100131set_target_properties(thrift-compiler PROPERTIES OUTPUT_NAME thrift)
Pascal Bach42be4e82014-04-23 18:19:06 +0200132
James E. King, III330b3f82017-01-23 08:52:04 -0500133target_link_libraries(thrift-compiler parse)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200134
Mario Emmenlauer93171d22019-10-23 17:32:34 +0200135add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/thrift${CMAKE_EXECUTABLE_SUFFIX}"
136 DEPENDS thrift-compiler
137 COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:thrift-compiler>" "${CMAKE_CURRENT_SOURCE_DIR}/"
138 COMMENT "Copying the thrift compiler to the source tree for use by downstream targets")
139add_custom_target(copy-thrift-compiler
140 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/thrift${CMAKE_EXECUTABLE_SUFFIX}")
141
James E. King, III330b3f82017-01-23 08:52:04 -0500142install(TARGETS thrift-compiler DESTINATION bin)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900143
144if(BUILD_TESTING)
145 add_subdirectory(test)
146endif()