blob: 0675f0eaa52e3a64cdce431ac9df962b7b4fe89c [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
49 src/thrift/parse/t_typedef.cc
50 src/thrift/parse/parse.cc
Jens Geyer71997412019-10-19 21:22:59 +020051 src/thrift/version.h
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090052)
53
54set(thrift-compiler_SOURCES
dtmuller052abc32016-07-26 11:58:28 +020055 src/thrift/main.cc
56 src/thrift/audit/t_audit.cpp
Pascal Bach6eb015a2014-04-17 16:19:07 +020057)
58
nsrtvwls014f53f2018-09-28 08:11:21 -070059set(thrift_compiler_LANGS
60)
61
Pascal Bach6eb015a2014-04-17 16:19:07 +020062# This macro adds an option THRIFT_COMPILER_${NAME}
63# that allows enabling or disabling certain languages
64macro(THRIFT_ADD_COMPILER name description initial)
65 string(TOUPPER "THRIFT_COMPILER_${name}" enabler)
dtmuller052abc32016-07-26 11:58:28 +020066 set(src "src/thrift/generate/t_${name}_generator.cc")
Pascal Bach6eb015a2014-04-17 16:19:07 +020067 option(${enabler} ${description} ${initial})
68 if(${enabler})
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +090069 list(APPEND thrift-compiler_SOURCES ${src})
nsrtvwls014f53f2018-09-28 08:11:21 -070070 list(APPEND thrift_compiler_LANGS ${name})
Pascal Bach6eb015a2014-04-17 16:19:07 +020071 endif()
72endmacro()
73
74# The following compiler can be enabled or disabled
Pascal Bach6eb015a2014-04-17 16:19:07 +020075THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" ON)
James E. King III278528c2019-01-11 12:17:44 -050076THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON)
77THRIFT_ADD_COMPILER(cl "Enable compiler for Common LISP" ON)
James E. King III278528c2019-01-11 12:17:44 -050078THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON)
James E. King III278528c2019-01-11 12:17:44 -050079THRIFT_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)
Kashirin Alex330482b2020-09-22 05:38:52 +020088THRIFT_ADD_COMPILER(markdown "Enable compiler for Markdown Documentation" ON)
James E. King III278528c2019-01-11 12:17:44 -050089THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON)
90THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020091THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON)
Roger Meier1a74d9c2014-10-12 23:35:43 +020092THRIFT_ADD_COMPILER(json "Enable compiler for JSON" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +020093THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON)
Jens Geyeraa0c8b32019-01-28 23:27:45 +010094THRIFT_ADD_COMPILER(netstd "Enable compiler for .NET Standard" ON)
James E. King III278528c2019-01-11 12:17:44 -050095THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON)
96THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON)
97THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON)
98THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON)
99THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON)
Allen George8b96bfb2016-11-02 08:01:08 -0400100THRIFT_ADD_COMPILER(rs "Enable compiler for Rust" ON)
James E. King III278528c2019-01-11 12:17:44 -0500101THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON)
102THRIFT_ADD_COMPILER(swift "Enable compiler for Cocoa Swift" ON)
Stig Bakken41e8cbf2016-02-12 16:33:12 +0100103THRIFT_ADD_COMPILER(xml "Enable compiler for XML" ON)
James E. King III278528c2019-01-11 12:17:44 -0500104THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200105
106# Thrift is looking for include files in the src directory
107# we also add the current binary directory for generated files
108include_directories(${CMAKE_CURRENT_BINARY_DIR} src)
109
James E. King III29f7f8f2019-01-26 09:15:19 -0500110list(APPEND thrift-compiler_SOURCES ${compiler_core})
James E. King, III330b3f82017-01-23 08:52:04 -0500111
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900112add_executable(thrift-compiler ${thrift-compiler_SOURCES})
113
James E. King, III330b3f82017-01-23 08:52:04 -0500114set_target_properties(thrift-compiler PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin/)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100115set_target_properties(thrift-compiler PROPERTIES OUTPUT_NAME thrift)
Pascal Bach42be4e82014-04-23 18:19:06 +0200116
James E. King, III330b3f82017-01-23 08:52:04 -0500117target_link_libraries(thrift-compiler parse)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200118
Mario Emmenlauer93171d22019-10-23 17:32:34 +0200119add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/thrift${CMAKE_EXECUTABLE_SUFFIX}"
120 DEPENDS thrift-compiler
121 COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:thrift-compiler>" "${CMAKE_CURRENT_SOURCE_DIR}/"
122 COMMENT "Copying the thrift compiler to the source tree for use by downstream targets")
123add_custom_target(copy-thrift-compiler
124 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/thrift${CMAKE_EXECUTABLE_SUFFIX}")
125
James E. King, III330b3f82017-01-23 08:52:04 -0500126install(TARGETS thrift-compiler DESTINATION bin)
Nobuaki Sukegawa11da87e2016-09-10 14:02:19 +0900127
128if(BUILD_TESTING)
129 add_subdirectory(test)
130endif()