From dfa341b87067ffc896f302237e3620e708ad864b Mon Sep 17 00:00:00 2001 From: hchunhui Date: Thu, 7 Mar 2019 11:45:12 +0000 Subject: [PATCH] feat(CMakeList.txt): add plugin build support (#257) * feat(CMakeList.txt): add plugin build support * chore(CMakeLists.txt): rename macro RIME_EXTRA_MODULES * refactor(plugins/CMakeLists.txt): rename variable plugin_modules * fix: do not embed the list of plugin modules in "extra" group when BUILD_MERGED_PLUGINS=OFF --- CMakeLists.txt | 10 ++++++++++ Makefile.xcode | 2 +- plugins/CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 7 ++++--- src/rime/setup.cc | 11 +++++++---- 5 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 plugins/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index dbd14a7d9..aba0735bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ set(rime_soversion 1) add_definitions(-DRIME_VERSION="${rime_version}") option(BUILD_SHARED_LIBS "Build Rime as shared library" ON) +option(BUILD_MERGED_PLUGINS "Merge plugins into one Rime library" ON) option(BUILD_STATIC "Build with dependencies as static libraries" OFF) option(BUILD_DATA "Build data for Rime" OFF) option(BUILD_TEST "Build and run tests" ON) @@ -187,6 +188,15 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD|DragonFly") endif() endif() +add_subdirectory(plugins) +message(STATUS "rime_plugins_libs: ${rime_plugins_deps}") +message(STATUS "rime_plugins_modules: ${rime_plugins_modules}") +set(list "") +foreach(mod ${rime_plugins_modules}) + set(list "${list},Q(${mod})") +endforeach() +add_definitions(-DRIME_EXTRA_MODULES=${list}) + if(BUILD_SHARED_LIBS) add_definitions(-DRIME_BUILD_SHARED_LIBS) set(rime_library rime) diff --git a/Makefile.xcode b/Makefile.xcode index a6945783e..322510446 100644 --- a/Makefile.xcode +++ b/Makefile.xcode @@ -10,7 +10,7 @@ release: cmake --build xbuild --config Release debug: - cmake . -Bxdebug -GXcode -DBUILD_STATIC=ON -DBUILD_SEPARATE_LIBS=ON + cmake . -Bxdebug -GXcode -DBUILD_STATIC=ON cmake --build xdebug --config Debug clean: diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt new file mode 100644 index 000000000..9d11592c5 --- /dev/null +++ b/plugins/CMakeLists.txt @@ -0,0 +1,34 @@ +set(RIME_SOURCE_DIR ${PROJECT_SOURCE_DIR}) +set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) + +unset(plugins_objs) +unset(plugins_deps) +unset(plugins_modules) +file(GLOB plugin_files "*") +foreach(file ${plugin_files}) + if (IS_DIRECTORY ${file}) + message(STATUS "Found plugin: ${file}") + unset(plugin_name) + unset(plugin_objs) + unset(plugin_deps) + unset(plugin_modules) + add_subdirectory(${file}) + if(BUILD_MERGED_PLUGINS) + set(plugins_objs ${plugins_objs} ${plugin_objs}) + set(plugins_deps ${plugins_deps} ${plugin_deps}) + set(plugins_modules ${plugins_modules} ${plugin_modules}) + else() + message(STATUS "Plugin ${plugin_name} provides modules: ${plugin_modules}") + add_library(${plugin_name} ${plugin_objs}) + target_link_libraries(${plugin_name} ${plugin_deps}) + if(XCODE_VERSION) + set_target_properties(${plugin_name} PROPERTIES INSTALL_NAME_DIR "@rpath") + endif(XCODE_VERSION) + install(TARGETS ${plugin_name} DESTINATION ${LIB_INSTALL_DIR}) + endif() + endif() +endforeach(file) + +set(rime_plugins_objs ${plugins_objs} PARENT_SCOPE) +set(rime_plugins_deps ${plugins_deps} PARENT_SCOPE) +set(rime_plugins_modules ${plugins_modules} PARENT_SCOPE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 25dbee8af..bd5fb629d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,7 +39,8 @@ set(rime_core_deps ${Glog_LIBRARY} ${YamlCpp_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} - ${rime_optional_deps}) + ${rime_optional_deps} + ${rime_plugins_deps}) set(rime_extra_deps ${ICONV_LIBRARIES} ${LevelDb_LIBRARY} @@ -58,7 +59,7 @@ else() endif() if(BUILD_SHARED_LIBS) - add_library(rime ${rime_src}) + add_library(rime ${rime_plugins_objs} ${rime_src}) target_link_libraries(rime ${rime_deps}) set_target_properties(rime PROPERTIES DEFINE_SYMBOL "RIME_EXPORTS") set_target_properties(rime PROPERTIES VERSION ${rime_version} SOVERSION ${rime_soversion}) @@ -77,7 +78,7 @@ if(BUILD_SHARED_LIBS) install(TARGETS rime-gears DESTINATION ${LIB_INSTALL_DIR}) endif() else() - add_library(rime-static STATIC ${rime_src}) + add_library(rime-static STATIC ${rime_plugins_objs} ${rime_src}) target_link_libraries(rime-static ${rime_deps}) set_target_properties(rime-static PROPERTIES OUTPUT_NAME "rime" PREFIX "lib") install(TARGETS rime-static DESTINATION ${LIB_INSTALL_DIR}) diff --git a/src/rime/setup.cc b/src/rime/setup.cc index 61f2fadff..9d1b67d8e 100644 --- a/src/rime/setup.cc +++ b/src/rime/setup.cc @@ -11,13 +11,19 @@ #include #include +#include namespace rime { -RIME_API RIME_MODULE_LIST(kDefaultModules, "default"); +#define Q(x) #x +RIME_API RIME_MODULE_LIST(kDefaultModules, "default" RIME_EXTRA_MODULES); +#undef Q RIME_MODULE_LIST(kDeployerModules, "deployer"); RIME_MODULE_LIST(kLegacyModules, "legacy"); +RIME_REGISTER_MODULE_GROUP(default, "core", "dict", "gears") +RIME_REGISTER_MODULE_GROUP(deployer, "core", "dict", "levers") + RIME_API void LoadModules(const char* module_names[]) { ModuleManager& mm(ModuleManager::instance()); for (const char** m = module_names; *m; ++m) { @@ -33,7 +39,4 @@ RIME_API void SetupLogging(const char* app_name) { #endif // RIME_ENABLE_LOGGING } -RIME_REGISTER_MODULE_GROUP(default, "core", "dict", "gears") -RIME_REGISTER_MODULE_GROUP(deployer, "core", "dict", "levers") - } // namespace rime