Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 1 | # |
| 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 III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 19 | |
| 20 | cmake_minimum_required(VERSION 3.3) |
| 21 | project("thrift-compiler" VERSION ${PACKAGE_VERSION}) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 22 | |
Jens Geyer | 7199741 | 2019-10-19 21:22:59 +0200 | [diff] [blame] | 23 | # 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 Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 25 | |
| 26 | find_package(FLEX REQUIRED) |
| 27 | find_package(BISON REQUIRED) |
| 28 | |
James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 29 | # create directory for thrifty and thriftl |
| 30 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/thrift/) |
| 31 | |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 32 | # Create flex and bison files and build the lib parse static library |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 33 | BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc) |
| 34 | FLEX_TARGET(thriftl ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 35 | ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty) |
| 36 | |
James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 37 | set(parse_SOURCES |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 38 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc |
| 39 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc |
James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 40 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.hh |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 41 | ) |
| 42 | |
James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 43 | add_library(parse STATIC ${parse_SOURCES}) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 44 | |
| 45 | # Create the thrift compiler |
Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 46 | set(compiler_core |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 47 | src/thrift/common.cc |
| 48 | src/thrift/generate/t_generator.cc |
Simon Wang | d5927a9 | 2021-09-13 19:50:45 +0800 | [diff] [blame] | 49 | src/thrift/generate/validator_parser.cc |
| 50 | src/thrift/generate/validator_parser.h |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 51 | src/thrift/parse/t_typedef.cc |
| 52 | src/thrift/parse/parse.cc |
Jens Geyer | 7199741 | 2019-10-19 21:22:59 +0200 | [diff] [blame] | 53 | src/thrift/version.h |
Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 54 | ) |
| 55 | |
| 56 | set(thrift-compiler_SOURCES |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 57 | src/thrift/main.cc |
| 58 | src/thrift/audit/t_audit.cpp |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 59 | ) |
| 60 | |
nsrtvwls | 014f53f | 2018-09-28 08:11:21 -0700 | [diff] [blame] | 61 | set(thrift_compiler_LANGS |
| 62 | ) |
| 63 | |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 64 | # This macro adds an option THRIFT_COMPILER_${NAME} |
| 65 | # that allows enabling or disabling certain languages |
| 66 | macro(THRIFT_ADD_COMPILER name description initial) |
| 67 | string(TOUPPER "THRIFT_COMPILER_${name}" enabler) |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 68 | set(src "src/thrift/generate/t_${name}_generator.cc") |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 69 | option(${enabler} ${description} ${initial}) |
| 70 | if(${enabler}) |
Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 71 | list(APPEND thrift-compiler_SOURCES ${src}) |
nsrtvwls | 014f53f | 2018-09-28 08:11:21 -0700 | [diff] [blame] | 72 | list(APPEND thrift_compiler_LANGS ${name}) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 73 | endif() |
| 74 | endmacro() |
| 75 | |
Simon Wang | d5927a9 | 2021-09-13 19:50:45 +0800 | [diff] [blame] | 76 | # This macro adds an option THRIFT_VALIDATOR_COMPILER_${NAME} |
| 77 | # that allows enabling or disabling certain languages' validator |
| 78 | macro(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() |
| 86 | endmacro() |
| 87 | |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 88 | # The following compiler can be enabled or disabled |
Simon Wang | d5927a9 | 2021-09-13 19:50:45 +0800 | [diff] [blame] | 89 | THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON) |
| 90 | THRIFT_ADD_COMPILER(cl "Enable compiler for Common LISP" ON) |
| 91 | THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON) |
| 92 | THRIFT_ADD_COMPILER(d "Enable compiler for D" ON) |
| 93 | THRIFT_ADD_COMPILER(dart "Enable compiler for Dart" ON) |
| 94 | THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" ON) |
| 95 | THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" ON) |
| 96 | THRIFT_ADD_COMPILER(go "Enable compiler for Go" ON) |
| 97 | THRIFT_ADD_COMPILER(gv "Enable compiler for GraphViz" ON) |
| 98 | THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" ON) |
| 99 | THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" ON) |
| 100 | THRIFT_ADD_COMPILER(markdown "Enable compiler for Markdown Documentation" ON) |
| 101 | THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON) |
| 102 | THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON) |
| 103 | THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON) |
| 104 | THRIFT_ADD_COMPILER(json "Enable compiler for JSON" ON) |
| 105 | THRIFT_ADD_COMPILER(kotlin "Enable compiler for Kotlin" ON) |
| 106 | THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON) |
| 107 | THRIFT_ADD_COMPILER(netstd "Enable compiler for .NET Standard" ON) |
| 108 | THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON) |
| 109 | THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON) |
| 110 | THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON) |
| 111 | THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON) |
| 112 | THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON) |
| 113 | THRIFT_ADD_COMPILER(rs "Enable compiler for Rust" ON) |
| 114 | THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON) |
| 115 | THRIFT_ADD_COMPILER(swift "Enable compiler for Cocoa Swift" ON) |
| 116 | THRIFT_ADD_COMPILER(xml "Enable compiler for XML" ON) |
| 117 | THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON) |
| 118 | |
| 119 | # The following compiler can be enabled or disabled by enabling or disabling certain languages |
| 120 | THRIFT_ADD_VALIDATOR_COMPILER(go "Enable validator compiler for Go" ON) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 121 | |
| 122 | # Thrift is looking for include files in the src directory |
| 123 | # we also add the current binary directory for generated files |
| 124 | include_directories(${CMAKE_CURRENT_BINARY_DIR} src) |
| 125 | |
James E. King III | 29f7f8f | 2019-01-26 09:15:19 -0500 | [diff] [blame] | 126 | list(APPEND thrift-compiler_SOURCES ${compiler_core}) |
James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 127 | |
Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 128 | add_executable(thrift-compiler ${thrift-compiler_SOURCES}) |
| 129 | |
James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 130 | set_target_properties(thrift-compiler PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin/) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 131 | set_target_properties(thrift-compiler PROPERTIES OUTPUT_NAME thrift) |
Pascal Bach | 42be4e8 | 2014-04-23 18:19:06 +0200 | [diff] [blame] | 132 | |
James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 133 | target_link_libraries(thrift-compiler parse) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 134 | |
Mario Emmenlauer | 93171d2 | 2019-10-23 17:32:34 +0200 | [diff] [blame] | 135 | add_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") |
| 139 | add_custom_target(copy-thrift-compiler |
| 140 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/thrift${CMAKE_EXECUTABLE_SUFFIX}") |
| 141 | |
James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 142 | install(TARGETS thrift-compiler DESTINATION bin) |
Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 143 | |
| 144 | if(BUILD_TESTING) |
| 145 | add_subdirectory(test) |
| 146 | endif() |