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 | |
Pascal Bach | 42be4e8 | 2014-04-23 18:19:06 +0200 | [diff] [blame] | 25 | # Read the version information from the Autoconf file |
| 26 | file (STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/../../configure.ac" CONFIGURE_AC REGEX "AC_INIT\\(.*\\)" ) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 27 | |
| 28 | # The following variable is used in the version.h.in file |
Pascal Bach | 42be4e8 | 2014-04-23 18:19:06 +0200 | [diff] [blame] | 29 | string(REGEX REPLACE "AC_INIT\\(\\[.*\\], \\[([0-9]+\\.[0-9]+\\.[0-9]+(-dev)?)\\]\\)" "\\1" PACKAGE_VERSION ${CONFIGURE_AC}) |
| 30 | message(STATUS "Thrift package version: ${PACKAGE_VERSION}") |
| 31 | |
| 32 | # These are internal to CMake |
| 33 | string(REGEX REPLACE "([0-9]+\\.[0-9]+\\.[0-9]+)(-dev)?" "\\1" thrift_VERSION ${PACKAGE_VERSION}) |
| 34 | string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" thrift_VERSION_MAJOR ${thrift_VERSION}) |
| 35 | string(REGEX REPLACE "[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" thrift_VERSION_MINOR ${thrift_VERSION}) |
| 36 | string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" thrift_VERSION_PATCH ${thrift_VERSION}) |
| 37 | message(STATUS "Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})") |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 38 | |
| 39 | # Windows has a different header |
Pascal Bach | 569863a | 2014-06-10 13:15:40 +0200 | [diff] [blame] | 40 | if(MSVC) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 41 | set(FLEX_FLAGS "--wincompat") # Don't use unistd.h on windows |
| 42 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/windows/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h) |
| 43 | else() |
| 44 | set(FLEX_FLAGS " ") |
| 45 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h) |
| 46 | endif() |
| 47 | |
| 48 | find_package(FLEX REQUIRED) |
| 49 | find_package(BISON REQUIRED) |
| 50 | |
| 51 | # Create flex and bison files and build the lib parse static library |
| 52 | BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc) |
| 53 | FLEX_TARGET(thriftl ${CMAKE_CURRENT_SOURCE_DIR}/src/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc COMPILE_FLAGS ${FLEX_FLAGS}) |
| 54 | ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty) |
| 55 | |
| 56 | # HACK: Work around the fact that bison crates a .hh file but we need a .h file |
| 57 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h |
| 58 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h |
| 59 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh |
| 60 | ) |
| 61 | |
| 62 | set(libparse_SOURCES |
| 63 | ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc |
| 64 | ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc |
| 65 | ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h |
| 66 | ) |
| 67 | |
| 68 | add_library(libparse STATIC ${libparse_SOURCES}) |
| 69 | |
| 70 | # Create the thrift compiler |
| 71 | set( thrift_SOURCES |
| 72 | src/main.cc |
| 73 | src/md5.c |
| 74 | src/generate/t_generator.cc |
| 75 | src/generate/t_generator_registry.h |
| 76 | src/globals.h |
| 77 | src/main.h |
| 78 | src/platform.h |
| 79 | src/md5.h |
| 80 | src/parse/t_doc.h |
| 81 | src/parse/t_type.h |
| 82 | src/parse/t_base_type.h |
| 83 | src/parse/t_enum.h |
| 84 | src/parse/t_enum_value.h |
| 85 | src/parse/t_typedef.h |
| 86 | src/parse/t_typedef.cc |
| 87 | src/parse/t_container.h |
| 88 | src/parse/t_list.h |
| 89 | src/parse/t_set.h |
| 90 | src/parse/t_map.h |
| 91 | src/parse/t_struct.h |
| 92 | src/parse/t_field.h |
| 93 | src/parse/t_service.h |
| 94 | src/parse/t_function.h |
| 95 | src/parse/t_program.h |
| 96 | src/parse/t_scope.h |
| 97 | src/parse/t_const.h |
| 98 | src/parse/t_const_value.h |
| 99 | src/parse/parse.cc |
| 100 | src/generate/t_generator.h |
| 101 | src/generate/t_oop_generator.h |
| 102 | src/generate/t_html_generator.h |
| 103 | src/windows/config.h |
| 104 | version.h |
| 105 | ) |
| 106 | |
| 107 | # This macro adds an option THRIFT_COMPILER_${NAME} |
| 108 | # that allows enabling or disabling certain languages |
| 109 | macro(THRIFT_ADD_COMPILER name description initial) |
| 110 | string(TOUPPER "THRIFT_COMPILER_${name}" enabler) |
| 111 | set(src "src/generate/t_${name}_generator.cc") |
| 112 | option(${enabler} ${description} ${initial}) |
| 113 | if(${enabler}) |
| 114 | list(APPEND thrift_SOURCES ${src}) |
| 115 | endif() |
| 116 | endmacro() |
| 117 | |
| 118 | # The following compiler can be enabled or disabled |
| 119 | THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON) |
| 120 | THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON) |
| 121 | THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON) |
| 122 | THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" ON) |
| 123 | THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" ON) |
| 124 | THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON) |
| 125 | THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON) |
| 126 | THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON) |
| 127 | THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON) |
| 128 | THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" ON) |
| 129 | THRIFT_ADD_COMPILER(cocoa "Enable compiler for Cocoa Objective-C" ON) |
| 130 | THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON) |
| 131 | THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON) |
| 132 | THRIFT_ADD_COMPILER(hs "Enable compiler for Haskell" ON) |
| 133 | THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON) |
| 134 | THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" ON) |
| 135 | THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON) |
| 136 | THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON) |
| 137 | THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" ON) |
| 138 | THRIFT_ADD_COMPILER(go "Enable compiler for Go" ON) |
| 139 | THRIFT_ADD_COMPILER(d "Enable compiler for D" ON) |
| 140 | THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON) |
| 141 | |
| 142 | # Thrift is looking for include files in the src directory |
| 143 | # we also add the current binary directory for generated files |
| 144 | include_directories(${CMAKE_CURRENT_BINARY_DIR} src) |
| 145 | |
| 146 | add_executable(thrift ${thrift_SOURCES}) |
Pascal Bach | 42be4e8 | 2014-04-23 18:19:06 +0200 | [diff] [blame] | 147 | |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 148 | target_link_libraries(thrift libparse) |
| 149 | |
Roger Meier | 8720260 | 2014-08-15 22:16:02 +0200 | [diff] [blame] | 150 | install(TARGETS thrift DESTINATION bin) |
| 151 | |
Roger Meier | 311f715 | 2014-08-17 22:24:30 +0200 | [diff] [blame^] | 152 | # mingw32 does not support c++0x features |
| 153 | if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 154 | set(CMAKE_CXX_FLAGS "-std=c++0x") |
| 155 | endif() |
| 156 | |
Roger Meier | 8720260 | 2014-08-15 22:16:02 +0200 | [diff] [blame] | 157 | # create a Distribution Package for the Apache Thrift Compiler |
| 158 | set(CPACK_PACKAGE_NAME "Apache Thrift") |
| 159 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Apache Thrift Compiler") |
| 160 | set(CPACK_PACKAGE_VENDOR "Apache Software Foundation" ) |
| 161 | set(CPACK_PACKAGE_CONTACT "dev@thrift.apache.org") |
| 162 | set(CPACK_PACKAGE_VERSION ${thrift_VERSION}) |
| 163 | set(CPACK_PACKAGE_VERSION_MAJOR ${thrift_VERSION_MAJOR} ) |
| 164 | set(CPACK_PACKAGE_VERSION_MINOR ${thrift_VERSION_MINOR} ) |
| 165 | set(CPACK_PACKAGE_VERSION_PATCH ${thrift_VERSION_PATCH} ) |
| 166 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../../LICENSE") |
| 167 | |
| 168 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 169 | set(CPACK_GENERATOR "NSIS") |
| 170 | set(CPACK_NSIS_HELP_LINK "http://thrift.apache.org") |
| 171 | set(CPACK_NSIS_MENU_LINKS |
| 172 | "http://thrift.apache.org" "Apache Thrift - Web Site" |
| 173 | "https://issues.apache.org/jira/browse/THRIFT" "Apache Thrift - Issues") |
| 174 | set(CPACK_NSIS_CONTACT ${CPACK_PACKAGE_CONTACT}) |
| 175 | set(CPACK_NSIS_MODIFY_PATH "ON") |
| 176 | set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}) |
| 177 | else() |
| 178 | set(CPACK_GENERATOR "DEB" ) |
| 179 | set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT}) |
Pascal Bach | 6eb015a | 2014-04-17 16:19:07 +0200 | [diff] [blame] | 180 | endif() |
Roger Meier | 8720260 | 2014-08-15 22:16:02 +0200 | [diff] [blame] | 181 | include(CPack) |