2014-04-17 14:19:07 +00:00
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
# or more contributor license agreements. See the NOTICE file
|
|
|
|
# distributed with this work for additional information
|
|
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
|
|
# to you under the Apache License, Version 2.0 (the
|
|
|
|
# "License"); you may not use this file except in compliance
|
|
|
|
# with the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing,
|
|
|
|
# software distributed under the License is distributed on an
|
|
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
# KIND, either express or implied. See the License for the
|
|
|
|
# specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
#
|
2017-01-23 13:52:04 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8.12)
|
2014-04-17 14:19:07 +00:00
|
|
|
|
2016-10-02 05:21:55 +00:00
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h)
|
2017-01-20 15:11:41 +00:00
|
|
|
if(MSVC)
|
|
|
|
# The winflexbison generator outputs some macros that conflict with the Visual Studio 2010 copy of stdint.h
|
|
|
|
# This might be fixed in later versions of Visual Studio, but an easy solution is to include stdint.h first
|
|
|
|
if(HAVE_STDINT_H)
|
2017-09-01 20:00:36 +00:00
|
|
|
add_definitions(-D__STDC_FORMAT_MACROS)
|
2017-01-20 15:11:41 +00:00
|
|
|
add_definitions(-D__STDC_LIMIT_MACROS)
|
|
|
|
add_definitions(/FI"stdint.h")
|
|
|
|
endif(HAVE_STDINT_H)
|
|
|
|
endif()
|
2014-04-17 14:19:07 +00:00
|
|
|
|
|
|
|
find_package(FLEX REQUIRED)
|
|
|
|
find_package(BISON REQUIRED)
|
|
|
|
|
2017-01-23 13:52:04 +00:00
|
|
|
# create directory for thrifty and thriftl
|
|
|
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/thrift/)
|
|
|
|
|
2014-04-17 14:19:07 +00:00
|
|
|
# Create flex and bison files and build the lib parse static library
|
2016-07-26 09:58:28 +00:00
|
|
|
BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc)
|
|
|
|
FLEX_TARGET(thriftl ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc)
|
2014-04-17 14:19:07 +00:00
|
|
|
ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty)
|
|
|
|
|
2017-01-23 13:52:04 +00:00
|
|
|
set(parse_SOURCES
|
2016-07-26 09:58:28 +00:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc
|
2017-01-23 13:52:04 +00:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.hh
|
2014-04-17 14:19:07 +00:00
|
|
|
)
|
|
|
|
|
2017-01-23 13:52:04 +00:00
|
|
|
add_library(parse STATIC ${parse_SOURCES})
|
2014-04-17 14:19:07 +00:00
|
|
|
|
|
|
|
# Create the thrift compiler
|
2016-09-10 05:02:19 +00:00
|
|
|
set(compiler_core
|
2016-07-26 09:58:28 +00:00
|
|
|
src/thrift/common.cc
|
|
|
|
src/thrift/generate/t_generator.cc
|
|
|
|
src/thrift/parse/t_typedef.cc
|
|
|
|
src/thrift/parse/parse.cc
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h
|
2016-09-10 05:02:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
set(thrift-compiler_SOURCES
|
2016-07-26 09:58:28 +00:00
|
|
|
src/thrift/main.cc
|
|
|
|
src/thrift/audit/t_audit.cpp
|
2014-04-17 14:19:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# This macro adds an option THRIFT_COMPILER_${NAME}
|
|
|
|
# that allows enabling or disabling certain languages
|
|
|
|
macro(THRIFT_ADD_COMPILER name description initial)
|
|
|
|
string(TOUPPER "THRIFT_COMPILER_${name}" enabler)
|
2016-07-26 09:58:28 +00:00
|
|
|
set(src "src/thrift/generate/t_${name}_generator.cc")
|
2014-04-17 14:19:07 +00:00
|
|
|
option(${enabler} ${description} ${initial})
|
|
|
|
if(${enabler})
|
2016-09-10 05:02:19 +00:00
|
|
|
list(APPEND thrift-compiler_SOURCES ${src})
|
2014-04-17 14:19:07 +00:00
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
# The following compiler can be enabled or disabled
|
|
|
|
THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON)
|
|
|
|
THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON)
|
|
|
|
THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON)
|
|
|
|
THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" ON)
|
2015-08-29 15:46:51 +00:00
|
|
|
THRIFT_ADD_COMPILER(dart "Enable compiler for Dart" ON)
|
2014-07-27 23:25:30 +00:00
|
|
|
THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" ON)
|
2014-04-17 14:19:07 +00:00
|
|
|
THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" ON)
|
2016-09-15 00:18:48 +00:00
|
|
|
THRIFT_ADD_COMPILER(netcore "Enable compiler for .NET Core" ON)
|
2014-04-17 14:19:07 +00:00
|
|
|
THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON)
|
|
|
|
THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON)
|
|
|
|
THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON)
|
|
|
|
THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON)
|
|
|
|
THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" ON)
|
|
|
|
THRIFT_ADD_COMPILER(cocoa "Enable compiler for Cocoa Objective-C" ON)
|
2015-10-09 20:01:55 +00:00
|
|
|
THRIFT_ADD_COMPILER(swift "Enable compiler for Cocoa Swift" ON)
|
2014-04-17 14:19:07 +00:00
|
|
|
THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON)
|
|
|
|
THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON)
|
|
|
|
THRIFT_ADD_COMPILER(hs "Enable compiler for Haskell" ON)
|
|
|
|
THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON)
|
|
|
|
THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" ON)
|
|
|
|
THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON)
|
2014-10-12 21:35:43 +00:00
|
|
|
THRIFT_ADD_COMPILER(json "Enable compiler for JSON" ON)
|
2014-04-17 14:19:07 +00:00
|
|
|
THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON)
|
|
|
|
THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" ON)
|
|
|
|
THRIFT_ADD_COMPILER(go "Enable compiler for Go" ON)
|
|
|
|
THRIFT_ADD_COMPILER(d "Enable compiler for D" ON)
|
|
|
|
THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON)
|
2016-02-12 15:33:12 +00:00
|
|
|
THRIFT_ADD_COMPILER(gv "Enable compiler for GraphViz" ON)
|
2016-11-02 12:01:08 +00:00
|
|
|
THRIFT_ADD_COMPILER(rs "Enable compiler for Rust" ON)
|
2016-02-12 15:33:12 +00:00
|
|
|
THRIFT_ADD_COMPILER(xml "Enable compiler for XML" ON)
|
2014-04-17 14:19:07 +00:00
|
|
|
|
|
|
|
# Thrift is looking for include files in the src directory
|
|
|
|
# we also add the current binary directory for generated files
|
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR} src)
|
|
|
|
|
2016-09-10 05:02:19 +00:00
|
|
|
if(NOT ${WITH_PLUGIN})
|
|
|
|
list(APPEND thrift-compiler_SOURCES ${compiler_core})
|
|
|
|
endif()
|
2017-01-23 13:52:04 +00:00
|
|
|
|
2016-09-10 05:02:19 +00:00
|
|
|
add_executable(thrift-compiler ${thrift-compiler_SOURCES})
|
|
|
|
|
|
|
|
if(${WITH_PLUGIN})
|
|
|
|
add_executable(thrift-bootstrap ${compiler_core}
|
2016-07-26 09:58:28 +00:00
|
|
|
src/thrift/main.cc
|
|
|
|
src/thrift/audit/t_audit.cpp
|
|
|
|
src/thrift/generate/t_cpp_generator.cc
|
2016-09-10 05:02:19 +00:00
|
|
|
)
|
2017-01-23 13:52:04 +00:00
|
|
|
target_link_libraries(thrift-bootstrap parse)
|
2016-09-10 05:02:19 +00:00
|
|
|
|
|
|
|
set(PLUGIN_GEN_SOURCES
|
2016-07-26 09:58:28 +00:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_types.h
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_types.cpp
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_constants.h
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin/plugin_constants.cpp
|
2016-09-10 05:02:19 +00:00
|
|
|
)
|
|
|
|
|
2016-07-26 09:58:28 +00:00
|
|
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin)
|
2016-09-10 05:02:19 +00:00
|
|
|
add_custom_command(OUTPUT ${PLUGIN_GEN_SOURCES}
|
2016-07-26 09:58:28 +00:00
|
|
|
DEPENDS thrift-bootstrap src/thrift/plugin/plugin.thrift
|
2016-09-10 05:02:19 +00:00
|
|
|
COMMAND thrift-bootstrap -gen cpp
|
2016-07-26 09:58:28 +00:00
|
|
|
-out ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/plugin/plugin.thrift
|
2016-09-10 05:02:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
include_directories(../../lib/cpp/src)
|
|
|
|
|
|
|
|
include(ThriftMacros)
|
|
|
|
ADD_LIBRARY_THRIFT(thriftc
|
|
|
|
${compiler_core}
|
|
|
|
${PLUGIN_GEN_SOURCES}
|
2016-07-26 09:58:28 +00:00
|
|
|
src/thrift/logging.cc
|
|
|
|
src/thrift/plugin/plugin_output.cc
|
|
|
|
src/thrift/plugin/plugin.cc
|
2016-09-10 05:02:19 +00:00
|
|
|
)
|
|
|
|
TARGET_INCLUDE_DIRECTORIES_THRIFT(thriftc PUBLIC ${Boost_INCLUDE_DIRS})
|
|
|
|
TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftc thrift PUBLIC)
|
|
|
|
target_compile_definitions(thrift-compiler PUBLIC THRIFT_ENABLE_PLUGIN)
|
|
|
|
LINK_AGAINST_THRIFT_LIBRARY(thrift-compiler thriftc)
|
|
|
|
endif()
|
|
|
|
|
2017-01-23 13:52:04 +00:00
|
|
|
set_target_properties(thrift-compiler PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin/)
|
2014-12-12 14:59:17 +00:00
|
|
|
set_target_properties(thrift-compiler PROPERTIES OUTPUT_NAME thrift)
|
2014-04-23 16:19:06 +00:00
|
|
|
|
2017-01-23 13:52:04 +00:00
|
|
|
target_link_libraries(thrift-compiler parse)
|
2014-08-17 20:24:30 +00:00
|
|
|
|
2017-01-23 13:52:04 +00:00
|
|
|
install(TARGETS thrift-compiler DESTINATION bin)
|
2016-09-10 05:02:19 +00:00
|
|
|
|
2016-07-26 09:58:28 +00:00
|
|
|
if(${WITH_PLUGIN})
|
|
|
|
# Install the headers
|
|
|
|
install(FILES
|
|
|
|
"src/thrift/common.h"
|
|
|
|
"src/thrift/globals.h"
|
|
|
|
"src/thrift/logging.h"
|
|
|
|
"src/thrift/main.h"
|
|
|
|
"src/thrift/platform.h"
|
2016-10-02 05:21:55 +00:00
|
|
|
"${CMAKE_BINARY_DIR}/compiler/cpp/thrift/version.h"
|
2016-07-26 09:58:28 +00:00
|
|
|
DESTINATION "${INCLUDE_INSTALL_DIR}/thrift")
|
|
|
|
install(FILES
|
|
|
|
"src/thrift/audit/t_audit.h"
|
|
|
|
DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/audit")
|
|
|
|
install(FILES
|
|
|
|
"src/thrift/generate/t_generator.h"
|
|
|
|
"src/thrift/generate/t_generator_registry.h"
|
|
|
|
"src/thrift/generate/t_html_generator.h"
|
|
|
|
"src/thrift/generate/t_oop_generator.h"
|
|
|
|
DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/generate")
|
|
|
|
install(FILES
|
|
|
|
"src/thrift/parse/t_base_type.h"
|
|
|
|
"src/thrift/parse/t_const.h"
|
|
|
|
"src/thrift/parse/t_const_value.h"
|
|
|
|
"src/thrift/parse/t_container.h"
|
|
|
|
"src/thrift/parse/t_doc.h"
|
|
|
|
"src/thrift/parse/t_enum.h"
|
|
|
|
"src/thrift/parse/t_enum_value.h"
|
|
|
|
"src/thrift/parse/t_field.h"
|
|
|
|
"src/thrift/parse/t_function.h"
|
|
|
|
"src/thrift/parse/t_list.h"
|
|
|
|
"src/thrift/parse/t_map.h"
|
|
|
|
"src/thrift/parse/t_program.h"
|
|
|
|
"src/thrift/parse/t_scope.h"
|
|
|
|
"src/thrift/parse/t_service.h"
|
|
|
|
"src/thrift/parse/t_set.h"
|
|
|
|
"src/thrift/parse/t_struct.h"
|
|
|
|
"src/thrift/parse/t_typedef.h"
|
|
|
|
"src/thrift/parse/t_type.h"
|
|
|
|
DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/parse")
|
|
|
|
install(FILES
|
|
|
|
"src/thrift/plugin/plugin.h"
|
|
|
|
"src/thrift/plugin/plugin_output.h"
|
|
|
|
"src/thrift/plugin/type_util.h"
|
|
|
|
DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/plugin")
|
|
|
|
if(MSVC)
|
|
|
|
install(FILES
|
|
|
|
"src/thrift/windows/config.h"
|
|
|
|
DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/windows")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2016-09-10 05:02:19 +00:00
|
|
|
if(BUILD_TESTING)
|
|
|
|
add_subdirectory(test)
|
|
|
|
endif()
|