Skip to content

Commit

Permalink
feat(CMakeList.txt): add plugin build support (#257)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
hchunhui authored and lotem committed Mar 7, 2019
1 parent 316a659 commit dfa341b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Makefile.xcode
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 34 additions & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 4 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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})
Expand All @@ -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})
Expand Down
11 changes: 7 additions & 4 deletions src/rime/setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@

#include <rime_api.h>
#include <rime/module.h>
#include <rime/setup.h>

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) {
Expand All @@ -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

0 comments on commit dfa341b

Please sign in to comment.