Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CMakeList.txt): add plugin build support #257

Merged
merged 4 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_default_modules: ${rime_default_modules}")
set(list "")
foreach(mod ${rime_default_modules})
set(list "${list},Q(${mod})")
endforeach()
add_definitions(-DRIME_EXTRA_DEFAULT_MODULES=${list})

if(BUILD_SHARED_LIBS)
add_definitions(-DRIME_BUILD_SHARED_LIBS)
set(rime_library rime)
Expand Down
33 changes: 33 additions & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set(RIME_SOURCE_DIR ${PROJECT_SOURCE_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

unset(plugins_objs)
unset(plugins_deps)
unset(plugins_default_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_default_modules)
add_subdirectory(${file})
set(plugins_default_modules ${plugins_default_modules} ${plugin_default_modules})
if(BUILD_MERGED_PLUGINS)
set(plugins_objs ${plugins_objs} ${plugin_objs})
set(plugins_deps ${plugins_deps} ${plugin_deps})
else()
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_default_modules ${plugins_default_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
5 changes: 3 additions & 2 deletions src/rime/setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#include <rime/module.h>

namespace rime {

RIME_API RIME_MODULE_LIST(kDefaultModules, "default");
#define Q(x) #x
RIME_API RIME_MODULE_LIST(kDefaultModules, "default" RIME_EXTRA_DEFAULT_MODULES);
#undef Q
RIME_MODULE_LIST(kDeployerModules, "deployer");
RIME_MODULE_LIST(kLegacyModules, "legacy");

Expand Down