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 |
| 49 | src/thrift/parse/t_typedef.cc |
| 50 | src/thrift/parse/parse.cc |
Jens Geyer | 7199741 | 2019-10-19 21:22:59 +0200 | [diff] [blame] | 51 | src/thrift/version.h |
Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 52 | ) |
| 53 | |
| 54 | set(thrift-compiler_SOURCES |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 55 | src/thrift/main.cc |
| 56 | src/thrift/audit/t_audit.cpp |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 57 | ) |
| 58 | |
nsrtvwls | 014f53f | 2018-09-28 08:11:21 -0700 | [diff] [blame] | 59 | set(thrift_compiler_LANGS |
| 60 | ) |
| 61 | |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 62 | # This macro adds an option THRIFT_COMPILER_${NAME} |
| 63 | # that allows enabling or disabling certain languages |
| 64 | macro(THRIFT_ADD_COMPILER name description initial) |
| 65 | string(TOUPPER "THRIFT_COMPILER_${name}" enabler) |
dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 66 | set(src "src/thrift/generate/t_${name}_generator.cc") |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 67 | option(${enabler} ${description} ${initial}) |
| 68 | if(${enabler}) |
Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 69 | list(APPEND thrift-compiler_SOURCES ${src}) |
nsrtvwls | 014f53f | 2018-09-28 08:11:21 -0700 | [diff] [blame] | 70 | list(APPEND thrift_compiler_LANGS ${name}) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 71 | endif() |
| 72 | endmacro() |
| 73 | |
| 74 | # The following compiler can be enabled or disabled |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 75 | THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON) |
Max-Gerd Retzlaff | 04057ac | 2022-08-23 17:38:34 +0200 | [diff] [blame] | 76 | THRIFT_ADD_COMPILER(cl "Enable compiler for Common LISP" ON) |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 77 | THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON) |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 78 | THRIFT_ADD_COMPILER(d "Enable compiler for D" ON) |
| 79 | THRIFT_ADD_COMPILER(dart "Enable compiler for Dart" ON) |
| 80 | THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" ON) |
| 81 | THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" ON) |
| 82 | THRIFT_ADD_COMPILER(go "Enable compiler for Go" ON) |
| 83 | THRIFT_ADD_COMPILER(gv "Enable compiler for GraphViz" ON) |
| 84 | THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" ON) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 85 | THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" ON) |
Kashirin Alex | 330482b | 2020-09-22 05:38:52 +0200 | [diff] [blame] | 86 | THRIFT_ADD_COMPILER(markdown "Enable compiler for Markdown Documentation" ON) |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 87 | THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON) |
| 88 | THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 89 | THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON) |
Roger Meier | 1a74d9c | 2014-10-12 23:35:43 +0200 | [diff] [blame] | 90 | THRIFT_ADD_COMPILER(json "Enable compiler for JSON" ON) |
Jiayu Liu | 49b2d6b | 2022-04-06 16:49:09 +0800 | [diff] [blame] | 91 | THRIFT_ADD_COMPILER(kotlin "Enable compiler for Kotlin" ON) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 92 | THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON) |
Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame] | 93 | THRIFT_ADD_COMPILER(netstd "Enable compiler for .NET Standard" ON) |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 94 | THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON) |
| 95 | THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON) |
| 96 | THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON) |
| 97 | THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON) |
| 98 | THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON) |
Allen George | 8b96bfb | 2016-11-02 08:01:08 -0400 | [diff] [blame] | 99 | THRIFT_ADD_COMPILER(rs "Enable compiler for Rust" ON) |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 100 | THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON) |
| 101 | THRIFT_ADD_COMPILER(swift "Enable compiler for Cocoa Swift" ON) |
Stig Bakken | 41e8cbf | 2016-02-12 16:33:12 +0100 | [diff] [blame] | 102 | THRIFT_ADD_COMPILER(xml "Enable compiler for XML" ON) |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 103 | THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 104 | |
| 105 | # Thrift is looking for include files in the src directory |
| 106 | # we also add the current binary directory for generated files |
| 107 | include_directories(${CMAKE_CURRENT_BINARY_DIR} src) |
| 108 | |
James E. King III | 29f7f8f | 2019-01-26 09:15:19 -0500 | [diff] [blame] | 109 | list(APPEND thrift-compiler_SOURCES ${compiler_core}) |
James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 110 | |
Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 111 | add_executable(thrift-compiler ${thrift-compiler_SOURCES}) |
| 112 | |
James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 113 | set_target_properties(thrift-compiler PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin/) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 114 | set_target_properties(thrift-compiler PROPERTIES OUTPUT_NAME thrift) |
Pascal Bach | 42be4e8 | 2014-04-23 18:19:06 +0200 | [diff] [blame] | 115 | |
James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 116 | target_link_libraries(thrift-compiler parse) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 117 | |
Mario Emmenlauer | 93171d2 | 2019-10-23 17:32:34 +0200 | [diff] [blame] | 118 | add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/thrift${CMAKE_EXECUTABLE_SUFFIX}" |
| 119 | DEPENDS thrift-compiler |
| 120 | COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:thrift-compiler>" "${CMAKE_CURRENT_SOURCE_DIR}/" |
| 121 | COMMENT "Copying the thrift compiler to the source tree for use by downstream targets") |
| 122 | add_custom_target(copy-thrift-compiler |
| 123 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/thrift${CMAKE_EXECUTABLE_SUFFIX}") |
| 124 | |
James E. King, III | 330b3f8 | 2017-01-23 08:52:04 -0500 | [diff] [blame] | 125 | install(TARGETS thrift-compiler DESTINATION bin) |
Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 126 | |
| 127 | if(BUILD_TESTING) |
| 128 | add_subdirectory(test) |
| 129 | endif() |