| 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 | # | 
|  | 19 |  | 
| Nobuaki Sukegawa | d8c6a84 | 2016-10-02 14:21:55 +0900 | [diff] [blame] | 20 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h) | 
| James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame^] | 21 | if(MSVC) | 
|  | 22 | # The winflexbison generator outputs some macros that conflict with the Visual Studio 2010 copy of stdint.h | 
|  | 23 | # This might be fixed in later versions of Visual Studio, but an easy solution is to include stdint.h first | 
|  | 24 | if(HAVE_STDINT_H) | 
|  | 25 | add_definitions(-D__STDC_LIMIT_MACROS) | 
|  | 26 | add_definitions(/FI"stdint.h") | 
|  | 27 | endif(HAVE_STDINT_H) | 
|  | 28 | endif() | 
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 29 |  | 
|  | 30 | find_package(FLEX REQUIRED) | 
|  | 31 | find_package(BISON REQUIRED) | 
|  | 32 |  | 
|  | 33 | # Create flex and bison files and build the lib parse static library | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 34 | BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc) | 
|  | 35 | 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] | 36 | ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty) | 
|  | 37 |  | 
|  | 38 | # HACK: Work around the fact that bison crates a .hh file but we need a .h file | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 39 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.h | 
|  | 40 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.hh ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.h | 
|  | 41 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.hh | 
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 42 | ) | 
|  | 43 |  | 
|  | 44 | set(libparse_SOURCES | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 45 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc | 
|  | 46 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc | 
|  | 47 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.h | 
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 48 | ) | 
|  | 49 |  | 
|  | 50 | add_library(libparse STATIC ${libparse_SOURCES}) | 
|  | 51 |  | 
|  | 52 | # Create the thrift compiler | 
| Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 53 | set(compiler_core | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 54 | src/thrift/common.cc | 
|  | 55 | src/thrift/generate/t_generator.cc | 
|  | 56 | src/thrift/parse/t_typedef.cc | 
|  | 57 | src/thrift/parse/parse.cc | 
|  | 58 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h | 
| Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 59 | ) | 
|  | 60 |  | 
|  | 61 | set(thrift-compiler_SOURCES | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 62 | src/thrift/main.cc | 
|  | 63 | src/thrift/audit/t_audit.cpp | 
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 64 | ) | 
|  | 65 |  | 
|  | 66 | # This macro adds an option THRIFT_COMPILER_${NAME} | 
|  | 67 | # that allows enabling or disabling certain languages | 
|  | 68 | macro(THRIFT_ADD_COMPILER name description initial) | 
|  | 69 | string(TOUPPER "THRIFT_COMPILER_${name}" enabler) | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 70 | set(src "src/thrift/generate/t_${name}_generator.cc") | 
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 71 | option(${enabler} ${description} ${initial}) | 
|  | 72 | if(${enabler}) | 
| Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 73 | list(APPEND thrift-compiler_SOURCES ${src}) | 
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 74 | endif() | 
|  | 75 | endmacro() | 
|  | 76 |  | 
|  | 77 | # The following compiler can be enabled or disabled | 
|  | 78 | THRIFT_ADD_COMPILER(c_glib  "Enable compiler for C with Glib" ON) | 
|  | 79 | THRIFT_ADD_COMPILER(cpp     "Enable compiler for C++" ON) | 
|  | 80 | THRIFT_ADD_COMPILER(java    "Enable compiler for Java"   ON) | 
|  | 81 | THRIFT_ADD_COMPILER(as3     "Enable compiler for ActionScript 3" ON) | 
| Mark Erickson | 932c470 | 2015-08-29 10:46:51 -0500 | [diff] [blame] | 82 | THRIFT_ADD_COMPILER(dart    "Enable compiler for Dart" ON) | 
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 83 | THRIFT_ADD_COMPILER(haxe    "Enable compiler for Haxe" ON) | 
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 84 | THRIFT_ADD_COMPILER(csharp  "Enable compiler for C#" ON) | 
| Volodymyr Gotra | b587a12 | 2016-09-14 19:18:48 -0500 | [diff] [blame] | 85 | THRIFT_ADD_COMPILER(netcore "Enable compiler for .NET Core" ON) | 
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 86 | THRIFT_ADD_COMPILER(py      "Enable compiler for Python 2.0" ON) | 
|  | 87 | THRIFT_ADD_COMPILER(rb      "Enable compiler for Ruby" ON) | 
|  | 88 | THRIFT_ADD_COMPILER(perl    "Enable compiler for Perl" ON) | 
|  | 89 | THRIFT_ADD_COMPILER(php     "Enable compiler for PHP" ON) | 
|  | 90 | THRIFT_ADD_COMPILER(erl     "Enable compiler for Erlang" ON) | 
|  | 91 | THRIFT_ADD_COMPILER(cocoa   "Enable compiler for Cocoa Objective-C" ON) | 
| Jens Geyer | 56e5b9b | 2015-10-09 22:01:55 +0200 | [diff] [blame] | 92 | THRIFT_ADD_COMPILER(swift   "Enable compiler for Cocoa Swift" ON) | 
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 93 | THRIFT_ADD_COMPILER(st      "Enable compiler for Smalltalk" ON) | 
|  | 94 | THRIFT_ADD_COMPILER(ocaml   "Enable compiler for OCaml" ON) | 
|  | 95 | THRIFT_ADD_COMPILER(hs      "Enable compiler for Haskell" ON) | 
|  | 96 | THRIFT_ADD_COMPILER(xsd     "Enable compiler for XSD" ON) | 
|  | 97 | THRIFT_ADD_COMPILER(html    "Enable compiler for HTML Documentation" ON) | 
|  | 98 | THRIFT_ADD_COMPILER(js      "Enable compiler for JavaScript" ON) | 
| Roger Meier | 1a74d9c | 2014-10-12 23:35:43 +0200 | [diff] [blame] | 99 | THRIFT_ADD_COMPILER(json    "Enable compiler for JSON" ON) | 
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 100 | THRIFT_ADD_COMPILER(javame  "Enable compiler for Java ME" ON) | 
|  | 101 | THRIFT_ADD_COMPILER(delphi  "Enable compiler for Delphi" ON) | 
|  | 102 | THRIFT_ADD_COMPILER(go      "Enable compiler for Go" ON) | 
|  | 103 | THRIFT_ADD_COMPILER(d       "Enable compiler for D" ON) | 
|  | 104 | THRIFT_ADD_COMPILER(lua     "Enable compiler for Lua" ON) | 
| Stig Bakken | 41e8cbf | 2016-02-12 16:33:12 +0100 | [diff] [blame] | 105 | THRIFT_ADD_COMPILER(gv      "Enable compiler for GraphViz" ON) | 
|  | 106 | THRIFT_ADD_COMPILER(xml     "Enable compiler for XML" ON) | 
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 107 |  | 
|  | 108 | # Thrift is looking for include files in the src directory | 
|  | 109 | # we also add the current binary directory for generated files | 
|  | 110 | include_directories(${CMAKE_CURRENT_BINARY_DIR} src) | 
|  | 111 |  | 
| Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 112 | if(NOT ${WITH_PLUGIN}) | 
|  | 113 | list(APPEND thrift-compiler_SOURCES ${compiler_core}) | 
|  | 114 | endif() | 
|  | 115 | add_executable(thrift-compiler ${thrift-compiler_SOURCES}) | 
|  | 116 |  | 
|  | 117 | if(${WITH_PLUGIN}) | 
|  | 118 | add_executable(thrift-bootstrap ${compiler_core} | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 119 | src/thrift/main.cc | 
|  | 120 | src/thrift/audit/t_audit.cpp | 
|  | 121 | src/thrift/generate/t_cpp_generator.cc | 
| Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 122 | ) | 
|  | 123 | target_link_libraries(thrift-bootstrap libparse) | 
|  | 124 |  | 
|  | 125 | set(PLUGIN_GEN_SOURCES | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 126 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_types.h | 
|  | 127 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_types.cpp | 
|  | 128 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_constants.h | 
|  | 129 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_constants.cpp | 
| Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 130 | ) | 
|  | 131 |  | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 132 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin) | 
| Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 133 | add_custom_command(OUTPUT ${PLUGIN_GEN_SOURCES} | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 134 | DEPENDS thrift-bootstrap src/thrift/plugin/plugin.thrift | 
| Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 135 | COMMAND thrift-bootstrap -gen cpp | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 136 | -out ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin | 
|  | 137 | ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/plugin/plugin.thrift | 
| Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 138 | ) | 
|  | 139 |  | 
|  | 140 | include_directories(../../lib/cpp/src) | 
|  | 141 |  | 
|  | 142 | include(ThriftMacros) | 
|  | 143 | ADD_LIBRARY_THRIFT(thriftc | 
|  | 144 | ${compiler_core} | 
|  | 145 | ${PLUGIN_GEN_SOURCES} | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 146 | src/thrift/logging.cc | 
|  | 147 | src/thrift/plugin/plugin_output.cc | 
|  | 148 | src/thrift/plugin/plugin.cc | 
| Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 149 | ) | 
|  | 150 | TARGET_INCLUDE_DIRECTORIES_THRIFT(thriftc PUBLIC ${Boost_INCLUDE_DIRS}) | 
|  | 151 | TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftc thrift PUBLIC) | 
|  | 152 | target_compile_definitions(thrift-compiler PUBLIC THRIFT_ENABLE_PLUGIN) | 
|  | 153 | LINK_AGAINST_THRIFT_LIBRARY(thrift-compiler thriftc) | 
|  | 154 | endif() | 
|  | 155 |  | 
| Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 156 | set_target_properties(thrift-compiler PROPERTIES OUTPUT_NAME thrift) | 
| Pascal Bach | 42be4e8 | 2014-04-23 18:19:06 +0200 | [diff] [blame] | 157 |  | 
| Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 158 | target_link_libraries(thrift-compiler libparse) | 
| Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 159 |  | 
| Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 160 | install(TARGETS thrift-compiler DESTINATION "${BIN_INSTALL_DIR}") | 
| Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 161 |  | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 162 | if(${WITH_PLUGIN}) | 
|  | 163 | # Install the headers | 
|  | 164 | install(FILES | 
|  | 165 | "src/thrift/common.h" | 
|  | 166 | "src/thrift/globals.h" | 
|  | 167 | "src/thrift/logging.h" | 
|  | 168 | "src/thrift/main.h" | 
|  | 169 | "src/thrift/platform.h" | 
| Nobuaki Sukegawa | d8c6a84 | 2016-10-02 14:21:55 +0900 | [diff] [blame] | 170 | "${CMAKE_BINARY_DIR}/compiler/cpp/thrift/version.h" | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 171 | DESTINATION "${INCLUDE_INSTALL_DIR}/thrift") | 
|  | 172 | install(FILES | 
|  | 173 | "src/thrift/audit/t_audit.h" | 
|  | 174 | DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/audit") | 
|  | 175 | install(FILES | 
|  | 176 | "src/thrift/generate/t_generator.h" | 
|  | 177 | "src/thrift/generate/t_generator_registry.h" | 
|  | 178 | "src/thrift/generate/t_html_generator.h" | 
|  | 179 | "src/thrift/generate/t_oop_generator.h" | 
|  | 180 | DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/generate") | 
|  | 181 | install(FILES | 
|  | 182 | "src/thrift/parse/t_base_type.h" | 
|  | 183 | "src/thrift/parse/t_const.h" | 
|  | 184 | "src/thrift/parse/t_const_value.h" | 
|  | 185 | "src/thrift/parse/t_container.h" | 
|  | 186 | "src/thrift/parse/t_doc.h" | 
|  | 187 | "src/thrift/parse/t_enum.h" | 
|  | 188 | "src/thrift/parse/t_enum_value.h" | 
|  | 189 | "src/thrift/parse/t_field.h" | 
|  | 190 | "src/thrift/parse/t_function.h" | 
|  | 191 | "src/thrift/parse/t_list.h" | 
|  | 192 | "src/thrift/parse/t_map.h" | 
|  | 193 | "src/thrift/parse/t_program.h" | 
|  | 194 | "src/thrift/parse/t_scope.h" | 
|  | 195 | "src/thrift/parse/t_service.h" | 
|  | 196 | "src/thrift/parse/t_set.h" | 
|  | 197 | "src/thrift/parse/t_struct.h" | 
|  | 198 | "src/thrift/parse/t_typedef.h" | 
|  | 199 | "src/thrift/parse/t_type.h" | 
|  | 200 | DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/parse") | 
|  | 201 | install(FILES | 
|  | 202 | "src/thrift/plugin/plugin.h" | 
|  | 203 | "src/thrift/plugin/plugin_output.h" | 
|  | 204 | "src/thrift/plugin/type_util.h" | 
|  | 205 | DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/plugin") | 
|  | 206 | if(MSVC) | 
|  | 207 | install(FILES | 
|  | 208 | "src/thrift/windows/config.h" | 
|  | 209 | DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/windows") | 
| dtmuller | 052abc3 | 2016-07-26 11:58:28 +0200 | [diff] [blame] | 210 | endif() | 
|  | 211 | endif() | 
|  | 212 |  | 
| Nobuaki Sukegawa | 11da87e | 2016-09-10 14:02:19 +0900 | [diff] [blame] | 213 | if(BUILD_TESTING) | 
|  | 214 | add_subdirectory(test) | 
|  | 215 | endif() |