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 | |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 20 | # Windows has a different header |
Pascal Bach | 569863a | 2014-06-10 13:15:40 +0200 | [diff] [blame] | 21 | if(MSVC) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 22 | set(FLEX_FLAGS "--wincompat") # Don't use unistd.h on windows |
| 23 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/windows/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h) |
| 24 | else() |
| 25 | set(FLEX_FLAGS " ") |
| 26 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h) |
| 27 | endif() |
| 28 | |
| 29 | find_package(FLEX REQUIRED) |
| 30 | find_package(BISON REQUIRED) |
| 31 | |
| 32 | # Create flex and bison files and build the lib parse static library |
| 33 | BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc) |
| 34 | FLEX_TARGET(thriftl ${CMAKE_CURRENT_SOURCE_DIR}/src/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc COMPILE_FLAGS ${FLEX_FLAGS}) |
| 35 | ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty) |
| 36 | |
| 37 | # HACK: Work around the fact that bison crates a .hh file but we need a .h file |
| 38 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h |
| 39 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h |
| 40 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh |
| 41 | ) |
| 42 | |
| 43 | set(libparse_SOURCES |
| 44 | ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc |
| 45 | ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc |
| 46 | ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h |
| 47 | ) |
| 48 | |
| 49 | add_library(libparse STATIC ${libparse_SOURCES}) |
| 50 | |
| 51 | # Create the thrift compiler |
Roger Meier | 5af78c8 | 2015-04-12 21:43:12 +0200 | [diff] [blame] | 52 | set( thrift_SOURCES |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 53 | src/main.cc |
| 54 | src/md5.c |
| 55 | src/generate/t_generator.cc |
| 56 | src/generate/t_generator_registry.h |
| 57 | src/globals.h |
| 58 | src/main.h |
| 59 | src/platform.h |
| 60 | src/md5.h |
| 61 | src/parse/t_doc.h |
| 62 | src/parse/t_type.h |
| 63 | src/parse/t_base_type.h |
| 64 | src/parse/t_enum.h |
| 65 | src/parse/t_enum_value.h |
| 66 | src/parse/t_typedef.h |
| 67 | src/parse/t_typedef.cc |
| 68 | src/parse/t_container.h |
| 69 | src/parse/t_list.h |
| 70 | src/parse/t_set.h |
| 71 | src/parse/t_map.h |
| 72 | src/parse/t_struct.h |
| 73 | src/parse/t_field.h |
| 74 | src/parse/t_service.h |
| 75 | src/parse/t_function.h |
| 76 | src/parse/t_program.h |
| 77 | src/parse/t_scope.h |
| 78 | src/parse/t_const.h |
| 79 | src/parse/t_const_value.h |
| 80 | src/parse/parse.cc |
| 81 | src/generate/t_generator.h |
| 82 | src/generate/t_oop_generator.h |
| 83 | src/generate/t_html_generator.h |
| 84 | src/windows/config.h |
| 85 | version.h |
| 86 | ) |
| 87 | |
| 88 | # This macro adds an option THRIFT_COMPILER_${NAME} |
| 89 | # that allows enabling or disabling certain languages |
| 90 | macro(THRIFT_ADD_COMPILER name description initial) |
| 91 | string(TOUPPER "THRIFT_COMPILER_${name}" enabler) |
| 92 | set(src "src/generate/t_${name}_generator.cc") |
| 93 | option(${enabler} ${description} ${initial}) |
| 94 | if(${enabler}) |
| 95 | list(APPEND thrift_SOURCES ${src}) |
| 96 | endif() |
| 97 | endmacro() |
| 98 | |
| 99 | # The following compiler can be enabled or disabled |
| 100 | THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON) |
| 101 | THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON) |
| 102 | THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON) |
| 103 | THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" ON) |
Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 104 | THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" ON) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 105 | THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" ON) |
| 106 | THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON) |
| 107 | THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON) |
| 108 | THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON) |
| 109 | THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON) |
| 110 | THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" ON) |
| 111 | THRIFT_ADD_COMPILER(cocoa "Enable compiler for Cocoa Objective-C" ON) |
| 112 | THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON) |
| 113 | THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON) |
| 114 | THRIFT_ADD_COMPILER(hs "Enable compiler for Haskell" ON) |
| 115 | THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON) |
| 116 | THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" ON) |
| 117 | THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON) |
Roger Meier | 1a74d9c | 2014-10-12 23:35:43 +0200 | [diff] [blame] | 118 | THRIFT_ADD_COMPILER(json "Enable compiler for JSON" ON) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 119 | THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON) |
| 120 | THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" ON) |
| 121 | THRIFT_ADD_COMPILER(go "Enable compiler for Go" ON) |
| 122 | THRIFT_ADD_COMPILER(d "Enable compiler for D" ON) |
| 123 | THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON) |
| 124 | |
| 125 | # Thrift is looking for include files in the src directory |
| 126 | # we also add the current binary directory for generated files |
| 127 | include_directories(${CMAKE_CURRENT_BINARY_DIR} src) |
| 128 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 129 | add_executable(thrift-compiler ${thrift_SOURCES}) |
| 130 | set_target_properties(thrift-compiler PROPERTIES OUTPUT_NAME thrift) |
Pascal Bach | 42be4e8 | 2014-04-23 18:19:06 +0200 | [diff] [blame] | 131 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 132 | target_link_libraries(thrift-compiler libparse) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 133 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 134 | install(TARGETS thrift-compiler DESTINATION "${BIN_INSTALL_DIR}") |