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