-
Notifications
You must be signed in to change notification settings - Fork 589
feat(cmake): make BUILD_SEPARATE_LIBS work with BUILD_MERGED_PLUGINS #260
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
Changes from all commits
412ce6c
0cab2b8
e951f47
6023e8d
e6859fd
33877b9
26d8f90
fccdcbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Empty file to work around a CMake issue. | ||
// Somehow a C++ source file (in addition to rime_plugins_objs) is required | ||
// by CMake (3.13.3) to create shared rime-plugins library on macOS. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,34 @@ | ||
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) | ||
|
||
aux_source_directory(. rime_src_api) | ||
aux_source_directory(rime rime_src_base) | ||
aux_source_directory(rime/algo rime_src_algo) | ||
aux_source_directory(rime/config rime_src_config) | ||
aux_source_directory(rime/dict rime_src_dict) | ||
aux_source_directory(rime/gear rime_src_gear) | ||
aux_source_directory(rime/lever rime_src_lever) | ||
aux_source_directory(. rime_api_src) | ||
aux_source_directory(rime rime_base_src) | ||
aux_source_directory(rime/algo rime_algo_src) | ||
aux_source_directory(rime/config rime_config_src) | ||
aux_source_directory(rime/dict rime_dict_src) | ||
aux_source_directory(rime/gear rime_gears_src) | ||
aux_source_directory(rime/lever rime_levers_src) | ||
if(rime_plugins_library) | ||
aux_source_directory(../plugins rime_plugins_src) | ||
endif() | ||
|
||
if(BUILD_SEPARATE_LIBS) | ||
set(rime_src | ||
${rime_src_api} | ||
${rime_src_base} | ||
${rime_src_config}) | ||
set(librime_gears_src | ||
${rime_src_algo} | ||
${rime_src_dict} | ||
${rime_src_gear} | ||
${rime_src_lever}) | ||
set(rime_core_module_src | ||
${rime_api_src} | ||
${rime_base_src} | ||
${rime_config_src}) | ||
set(rime_dict_module_src | ||
${rime_algo_src} | ||
${rime_dict_src}) | ||
|
||
if(BUILD_SHARED_LIBS AND BUILD_SEPARATE_LIBS) | ||
set(rime_src ${rime_core_module_src}) | ||
else() | ||
set(rime_src | ||
${rime_src_api} | ||
${rime_src_base} | ||
${rime_src_algo} | ||
${rime_src_config} | ||
${rime_src_dict} | ||
${rime_src_gear} | ||
${rime_src_lever}) | ||
${rime_core_module_src} | ||
${rime_dict_module_src} | ||
${rime_gears_src} | ||
${rime_levers_src} | ||
${rime_plugins_src} | ||
${rime_plugins_objs}) | ||
endif() | ||
|
||
set(rime_optional_deps "") | ||
|
@@ -39,54 +41,102 @@ set(rime_core_deps | |
${Glog_LIBRARY} | ||
${YamlCpp_LIBRARY} | ||
${CMAKE_THREAD_LIBS_INIT} | ||
${rime_optional_deps} | ||
${rime_plugins_deps}) | ||
set(rime_extra_deps | ||
${ICONV_LIBRARIES} | ||
${rime_optional_deps}) | ||
set(rime_dict_deps | ||
${LevelDb_LIBRARY} | ||
${Marisa_LIBRARY} | ||
${Marisa_LIBRARY}) | ||
set(rime_gears_deps | ||
${ICONV_LIBRARIES} | ||
${Opencc_LIBRARY}) | ||
set(rime_levers_deps "") | ||
|
||
if(MINGW) | ||
set(rime_core_deps ${rime_core_deps} wsock32 ws2_32) | ||
endif() | ||
|
||
if(BUILD_SEPARATE_LIBS) | ||
set(rime_deps ${rime_core_deps}) | ||
set(rime_gears_deps ${rime_library} ${rime_extra_deps}) | ||
else() | ||
set(rime_deps ${rime_core_deps} ${rime_extra_deps}) | ||
set(rime_deps | ||
${rime_core_deps} | ||
${rime_dict_deps} | ||
${rime_gears_deps} | ||
${rime_levers_deps} | ||
${rime_plugins_deps}) | ||
endif() | ||
|
||
if(BUILD_SHARED_LIBS) | ||
add_library(rime ${rime_plugins_objs} ${rime_src}) | ||
add_library(rime ${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}) | ||
set_target_properties(rime PROPERTIES | ||
DEFINE_SYMBOL "RIME_EXPORTS" | ||
VERSION ${rime_version} | ||
SOVERSION ${rime_soversion}) | ||
if(XCODE_VERSION) | ||
set_target_properties(rime PROPERTIES INSTALL_NAME_DIR "@rpath") | ||
endif() | ||
install(TARGETS rime DESTINATION ${LIB_INSTALL_DIR}) | ||
|
||
if(BUILD_SEPARATE_LIBS) | ||
add_library(rime-gears ${librime_gears_src}) | ||
target_link_libraries(rime-gears ${rime_gears_deps}) | ||
add_dependencies(rime-gears ${rime_library}) | ||
set_target_properties(rime-gears PROPERTIES VERSION ${rime_version} SOVERSION ${rime_soversion}) | ||
add_library(rime-dict ${rime_dict_module_src}) | ||
target_link_libraries(rime-dict | ||
${rime_dict_deps} | ||
${rime_library}) | ||
set_target_properties(rime-dict PROPERTIES | ||
VERSION ${rime_version} | ||
SOVERSION ${rime_soversion}) | ||
if(XCODE_VERSION) | ||
set_target_properties(rime-dict PROPERTIES INSTALL_NAME_DIR "@rpath") | ||
endif() | ||
install(TARGETS rime-dict DESTINATION ${LIB_INSTALL_DIR}) | ||
|
||
add_library(rime-gears ${rime_gears_src}) | ||
target_link_libraries(rime-gears | ||
${rime_gears_deps} | ||
${rime_library} | ||
${rime_dict_library}) | ||
set_target_properties(rime-gears PROPERTIES | ||
VERSION ${rime_version} | ||
SOVERSION ${rime_soversion}) | ||
if(XCODE_VERSION) | ||
set_target_properties(rime-gears PROPERTIES INSTALL_NAME_DIR "@rpath") | ||
endif() | ||
install(TARGETS rime-gears DESTINATION ${LIB_INSTALL_DIR}) | ||
|
||
add_library(rime-levers ${rime_levers_src}) | ||
target_link_libraries(rime-levers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
${rime_levers_deps} | ||
${rime_library} | ||
${rime_dict_library}) | ||
set_target_properties(rime-levers PROPERTIES | ||
VERSION ${rime_version} | ||
SOVERSION ${rime_soversion}) | ||
if(XCODE_VERSION) | ||
set_target_properties(rime-levers PROPERTIES INSTALL_NAME_DIR "@rpath") | ||
endif() | ||
install(TARGETS rime-levers DESTINATION ${LIB_INSTALL_DIR}) | ||
|
||
if(rime_plugins_library) | ||
add_library(rime-plugins | ||
${rime_plugins_src} | ||
${rime_plugins_objs}) | ||
target_link_libraries(rime-plugins | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. Just link ${rime_plugins_deps} |
||
${rime_plugins_deps} | ||
${rime_library} | ||
${rime_dict_library} | ||
${rime_gears_library}) | ||
set_target_properties(rime-plugins PROPERTIES | ||
VERSION ${rime_version} | ||
SOVERSION ${rime_soversion}) | ||
if(XCODE_VERSION) | ||
set_target_properties(rime-plugins PROPERTIES INSTALL_NAME_DIR "@rpath") | ||
endif() | ||
install(TARGETS rime-plugins DESTINATION ${LIB_INSTALL_DIR}) | ||
endif() | ||
endif() | ||
else() | ||
add_library(rime-static STATIC ${rime_plugins_objs} ${rime_src}) | ||
add_library(rime-static STATIC ${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}) | ||
if(BUILD_SEPARATE_LIBS) | ||
add_library(rime-gears-static STATIC ${librime_gears_src}) | ||
target_link_libraries(rime-gears-static ${rime_gears_deps}) | ||
add_dependencies(rime-gears-static ${rime_library}) | ||
set_target_properties(rime-gears-static PROPERTIES OUTPUT_NAME "rime-gears" PREFIX "lib") | ||
install(TARGETS rime-gears-static DESTINATION ${LIB_INSTALL_DIR}) | ||
endif() | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,31 +2,44 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) | |
|
||
set(rime_api_console_src "rime_api_console.cc") | ||
add_executable(rime_api_console ${rime_api_console_src}) | ||
target_link_libraries(rime_api_console ${rime_library} ${rime_gears_library}) | ||
add_dependencies(rime_api_console ${rime_library} ${rime_gears_library}) | ||
target_link_libraries(rime_api_console | ||
${rime_library} | ||
${rime_dict_library} | ||
${rime_gears_library} | ||
${rime_levers_library} | ||
${rime_plugins_library}) | ||
|
||
set(rime_patch_src "rime_patch.cc") | ||
add_executable(rime_patch ${rime_patch_src}) | ||
target_link_libraries(rime_patch ${rime_library} ${rime_gears_library}) | ||
add_dependencies(rime_patch ${rime_library} ${rime_gears_library}) | ||
target_link_libraries(rime_patch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My test shows rime_patch depends on |
||
${rime_library} | ||
${rime_levers_library}) | ||
|
||
# msvc doesn't export all symbols | ||
if(NOT (WIN32 AND BUILD_SHARED_LIBS)) | ||
|
||
set(rime_console_src "rime_console.cc") | ||
add_executable(rime_console ${rime_console_src}) | ||
target_link_libraries(rime_console ${rime_library} ${rime_gears_library}) | ||
add_dependencies(rime_console ${rime_library} ${rime_gears_library}) | ||
target_link_libraries(rime_console | ||
${rime_library} | ||
${rime_dict_library} | ||
${rime_gears_library} | ||
${rime_levers_library} | ||
${rime_plugins_library}) | ||
|
||
set(rime_dict_manager_src "rime_dict_manager.cc") | ||
add_executable(rime_dict_manager ${rime_dict_manager_src}) | ||
target_link_libraries(rime_dict_manager ${rime_library} ${rime_gears_library}) | ||
add_dependencies(rime_dict_manager ${rime_library} ${rime_gears_library}) | ||
target_link_libraries(rime_dict_manager | ||
${rime_library} | ||
${rime_dict_library} | ||
${rime_levers_library}) | ||
|
||
set(rime_deployer_src "rime_deployer.cc") | ||
add_executable(rime_deployer ${rime_deployer_src}) | ||
target_link_libraries(rime_deployer ${rime_library} ${rime_gears_library}) | ||
add_dependencies(rime_deployer ${rime_library} ${rime_gears_library}) | ||
target_link_libraries(rime_deployer | ||
${rime_library} | ||
${rime_dict_library} | ||
${rime_levers_library}) | ||
|
||
install(TARGETS rime_dict_manager DESTINATION ${BIN_INSTALL_DIR}) | ||
install(TARGETS rime_deployer DESTINATION ${BIN_INSTALL_DIR}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to link
${rime_library}
,${rime_gears_deps}
,${rime_dict_library}
.I have tested it in Linux, and it should work in macOS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this doesn't work for the macOS build.
Errors were cannot find symbol in rime libraries it depends on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the solution is
References:
[1] https://stackoverflow.com/questions/42722759/portable-plugins-with-cmake
[2] https://stackoverflow.com/questions/36662920/xcode-clang-link-build-dynamic-framework-or-dylib-not-embed-dependencies