THRIFT-2835 Add possibility to distribute generators separately from thrift core, and load them dynamically
Deploy headers needed to build plugins
Restructure source tree to match lib and to make sure headers are
deployed to INCLUDE_DIR/thrift.
This closes #368 and closes #1039
diff --git a/compiler/cpp/CMakeLists.txt b/compiler/cpp/CMakeLists.txt
index 48cadbc..2d9529a 100644
--- a/compiler/cpp/CMakeLists.txt
+++ b/compiler/cpp/CMakeLists.txt
@@ -19,52 +19,52 @@
# Windows has a different header
if(MSVC)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/windows/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/windows/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h)
else()
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h)
endif()
find_package(FLEX REQUIRED)
find_package(BISON REQUIRED)
# Create flex and bison files and build the lib parse static library
-BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc)
-FLEX_TARGET(thriftl ${CMAKE_CURRENT_SOURCE_DIR}/src/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc)
+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)
ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty)
# HACK: Work around the fact that bison crates a .hh file but we need a .h file
-add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
- DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh
+add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.h
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.hh ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.h
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.hh
)
set(libparse_SOURCES
- ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc
- ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc
- ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
+ ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc
+ ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc
+ ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.h
)
add_library(libparse STATIC ${libparse_SOURCES})
# Create the thrift compiler
set(compiler_core
- src/common.cc
- src/generate/t_generator.cc
- src/parse/t_typedef.cc
- src/parse/parse.cc
- ${CMAKE_CURRENT_BINARY_DIR}/version.h
+ 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
)
set(thrift-compiler_SOURCES
- src/main.cc
- src/audit/t_audit.cpp
+ src/thrift/main.cc
+ src/thrift/audit/t_audit.cpp
)
# 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)
- set(src "src/generate/t_${name}_generator.cc")
+ set(src "src/thrift/generate/t_${name}_generator.cc")
option(${enabler} ${description} ${initial})
if(${enabler})
list(APPEND thrift-compiler_SOURCES ${src})
@@ -112,25 +112,25 @@
if(${WITH_PLUGIN})
add_executable(thrift-bootstrap ${compiler_core}
- src/main.cc
- src/audit/t_audit.cpp
- src/generate/t_cpp_generator.cc
+ src/thrift/main.cc
+ src/thrift/audit/t_audit.cpp
+ src/thrift/generate/t_cpp_generator.cc
)
target_link_libraries(thrift-bootstrap libparse)
set(PLUGIN_GEN_SOURCES
- ${CMAKE_CURRENT_BINARY_DIR}/plugin/plugin_types.h
- ${CMAKE_CURRENT_BINARY_DIR}/plugin/plugin_types.cpp
- ${CMAKE_CURRENT_BINARY_DIR}/plugin/plugin_constants.h
- ${CMAKE_CURRENT_BINARY_DIR}/plugin/plugin_constants.cpp
+ ${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
)
- file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/plugin)
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin)
add_custom_command(OUTPUT ${PLUGIN_GEN_SOURCES}
- DEPENDS thrift-bootstrap src/plugin/plugin.thrift
+ DEPENDS thrift-bootstrap src/thrift/plugin/plugin.thrift
COMMAND thrift-bootstrap -gen cpp
- -out ${CMAKE_CURRENT_BINARY_DIR}/plugin
- ${CMAKE_CURRENT_SOURCE_DIR}/src/plugin/plugin.thrift
+ -out ${CMAKE_CURRENT_BINARY_DIR}/thrift/plugin
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/thrift/plugin/plugin.thrift
)
include_directories(../../lib/cpp/src)
@@ -139,9 +139,9 @@
ADD_LIBRARY_THRIFT(thriftc
${compiler_core}
${PLUGIN_GEN_SOURCES}
- src/logging.cc
- src/plugin/plugin_output.cc
- src/plugin/plugin.cc
+ src/thrift/logging.cc
+ src/thrift/plugin/plugin_output.cc
+ src/thrift/plugin/plugin.cc
)
TARGET_INCLUDE_DIRECTORIES_THRIFT(thriftc PUBLIC ${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thriftc thrift PUBLIC)
@@ -155,6 +155,63 @@
install(TARGETS thrift-compiler DESTINATION "${BIN_INSTALL_DIR}")
+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"
+ 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")
+ install(FILES
+ "${CMAKE_BINARY_DIR}/compiler/cpp/thrift/windows/version.h"
+ DESTINATION "${INCLUDE_INSTALL_DIR}/thrift/windows")
+else()
+ install(FILES
+ "${CMAKE_BINARY_DIR}/compiler/cpp/thrift/version.h"
+ DESTINATION "${INCLUDE_INSTALL_DIR}/thrift")
+endif()
+endif()
+
if(BUILD_TESTING)
add_subdirectory(test)
endif()