diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 460581d5a2..6ebb7c9db3 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -167,20 +167,17 @@ jobs: -DCMAKE_BUILD_TYPE:STRING=Release \ -DENABLE_LOGGING:BOOL=ON \ -DBUILD_TEST:BOOL=ON \ - -DBUILD_STATIC:BOOL=ON \ + -DWITH_STATIC_DEPS:BOOL=ON \ -DBUILD_SHARED_LIBS:BOOL=ON cmake --build build cmake --install build - cd build && cp ./lib/librime.dll ./test + cd build ctest --output-on-failure - name: Create distributable run: | tar -cjvf rime-${{ env.git_ref_name }}-${{ runner.os }}-mingw.tar.bz2 \ dist version-info.txt - tar -cjvf rime-deps-${{ env.git_ref_name }}-${{ runner.os }}-mingw.tar.bz2 \ - --exclude '*/.placeholder' \ - bin include lib share - name: Upload artifacts uses: actions/upload-artifact@v3 diff --git a/CMakeLists.txt b/CMakeLists.txt index 3630168958..def83db676 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,7 @@ include(GNUInstallDirs) 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(WITH_STATIC_DEPS "Build with static dependency libraries" OFF) option(BUILD_SAMPLE "Build sample Rime plugin" OFF) option(BUILD_TEST "Build and run tests" ON) option(BUILD_SEPARATE_LIBS "Build separate rime-* libraries" OFF) @@ -29,29 +28,15 @@ option(ENABLE_TIMESTAMP "Embed timestamp to schema artifacts" ON) set(RIME_DATA_DIR "${CMAKE_INSTALL_FULL_DATADIR}/rime-data" CACHE STRING "Target directory for Rime data") set(RIME_PLUGINS_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/rime-plugins" CACHE STRING "Target directory for externally built Rime plugins") -if(WIN32) - set(ext ".exe") -endif(WIN32) - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${PROJECT_SOURCE_DIR}") if (ENABLE_ASAN) - set(asan_cflags "-fsanitize=address -fno-omit-frame-pointer") - set(asan_lflags "-fsanitize=address -lasan") - set(CMAKE_C_FLAGS "${asan_cflags} ${CMAKE_C_FLAGS}") - set(CMAKE_CXX_FLAGS "${asan_cflags} ${CMAKE_CXX_FLAGS}") - set(CMAKE_EXE_LINKER_FLAGS "${asan_lflags} ${CMAKE_EXE_LINKER_FLAGS}") - set(CMAKE_SHARED_LINKER_FLAGS "${asan_lflags} ${CMAKE_SHARED_LINKER_FLAGS}") + add_compile_options(-fsanitize=address -fno-omit-frame-pointer) + add_link_options(-fsanitize=address -lasan) endif() -set(Boost_USE_STATIC_LIBS ${BUILD_STATIC}) -set(Gflags_STATIC ${BUILD_STATIC}) -set(Glog_STATIC ${BUILD_STATIC}) -set(LevelDb_STATIC ${BUILD_STATIC}) -set(Marisa_STATIC ${BUILD_STATIC}) -set(Opencc_STATIC ${BUILD_STATIC}) -set(YamlCpp_STATIC ${BUILD_STATIC}) +set(Boost_USE_STATIC_LIBS ${WITH_STATIC_DEPS}) set(Boost_USE_MULTITHREADED ON) if(MSVC) @@ -70,22 +55,14 @@ if(Boost_FOUND) endif() if(ENABLE_LOGGING) + find_package(GFlags) + find_package(GLog REQUIRED) - find_package(Gflags) - if(Gflags_FOUND) - include_directories(${Gflags_INCLUDE_PATH}) - endif() - - find_package(Glog REQUIRED) - if(Glog_FOUND) - include_directories(${Glog_INCLUDE_PATH}) - endif() - if(Glog_STATIC) + if(WITH_STATIC_DEPS) add_definitions(-DGOOGLE_GLOG_DLL_DECL=) endif() - + set(RIME_ENABLE_LOGGING 1) - endif() find_package(Threads) @@ -102,33 +79,19 @@ if(BUILD_TEST) find_package(GTest REQUIRED) if(GTEST_FOUND) enable_testing() - include_directories(${GTEST_INCLUDE_DIRS}) endif() endif() find_package(YamlCpp REQUIRED) -if(YamlCpp_FOUND) - include_directories(${YamlCpp_INCLUDE_PATH}) -endif() -if(YamlCpp_STATIC) +if(WITH_STATIC_DEPS) add_definitions(-DYAML_CPP_STATIC_DEFINE) endif() -find_package(LevelDb REQUIRED) -if(LevelDb_FOUND) - include_directories(${LevelDb_INCLUDE_PATH}) -endif() - +find_package(LevelDB REQUIRED) find_package(Marisa REQUIRED) -if(Marisa_FOUND) - include_directories(${Marisa_INCLUDE_PATH}) -endif() -find_package(Opencc REQUIRED) -if(Opencc_FOUND) -include_directories(${Opencc_INCLUDE_PATH}) -endif() -if(Opencc_STATIC) +find_package(OpenCC REQUIRED) +if(WITH_STATIC_DEPS) add_definitions(-DOpencc_BUILT_AS_STATIC) endif() @@ -186,14 +149,8 @@ configure_file( add_custom_target(remove COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD|DragonFly|GNU" OR MINGW) - set(prefix "${CMAKE_INSTALL_PREFIX}") - set(exec_prefix "${CMAKE_INSTALL_PREFIX}") - set(bindir "${CMAKE_INSTALL_FULL_BINDIR}") - set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") - set(pkgdatadir "${RIME_DATA_DIR}") - set(pluginsdir "${RIME_PLUGINS_DIR}") - set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") +# Android doesn't support PkgConfig yet +if(NOT ANDROID) configure_file( ${PROJECT_SOURCE_DIR}/rime.pc.in ${PROJECT_BINARY_DIR}/rime.pc @@ -222,11 +179,6 @@ if(INSTALL_PRIVATE_HEADERS) endforeach() endif() -if(BUILD_DATA) - file(GLOB rime_preset_data_files ${PROJECT_SOURCE_DIR}/data/preset/*.yaml) - install(FILES ${rime_preset_data_files} DESTINATION ${RIME_DATA_DIR}) -endif() - if(BUILD_SHARED_LIBS) add_definitions(-DRIME_BUILD_SHARED_LIBS) set(rime_library rime) @@ -242,11 +194,11 @@ 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})") + list(APPEND qmods "Q(${mod})") endforeach() -add_definitions(-DRIME_EXTRA_MODULES=${list}) +list(JOIN qmods "," extra_mods) +add_definitions(-DRIME_EXTRA_MODULES=${extra_mods}) if(BUILD_SHARED_LIBS AND BUILD_SEPARATE_LIBS AND rime_plugins_objs) set(rime_plugins_library rime-plugins) endif() diff --git a/Dockerfile b/Dockerfile index e2cac26328..babb1b4cf6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,7 +28,7 @@ RUN cmake -B build -G Ninja \ -DCMAKE_BUILD_TYPE:STRING=Release \ -DENABLE_LOGGING:BOOL=ON \ -DBUILD_TEST:BOOL=ON \ - -DBUILD_STATIC:BOOL=OFF \ + -DWITH_STATIC_DEPS:BOOL=OFF \ -DBUILD_SHARED_LIBS:BOOL=ON RUN cmake --build build diff --git a/Makefile b/Makefile index 9d61ac9693..25fc95ff03 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ librime-static: cmake . -B$(build) \ -DCMAKE_INSTALL_PREFIX=$(prefix) \ -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_STATIC=ON \ + -DWITH_STATIC_DEPS=ON \ -DBUILD_SHARED_LIBS=OFF cmake --build $(build) diff --git a/bin/.placeholder b/bin/.placeholder deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/build-clang.bat b/build-clang.bat index 44772c7a44..df82df464d 100644 --- a/build-clang.bat +++ b/build-clang.bat @@ -114,7 +114,7 @@ if %build_deps% == 1 ( ) set rime_cmake_flags=%common_cmake_flags%^ - -DBUILD_STATIC:BOOL=ON^ + -DWITH_STATIC_DEPS:BOOL=ON^ -DBUILD_SHARED_LIBS:BOOL=ON^ -DBUILD_TEST:BOOL="%build_test%"^ -DENABLE_LOGGING:BOOL=ON^ diff --git a/build.bat b/build.bat index 80e8e2022e..0ea56d84fd 100644 --- a/build.bat +++ b/build.bat @@ -176,7 +176,7 @@ if %build_deps% == 1 ( if %build_librime% == 0 goto exit set rime_cmake_flags=%common_cmake_flags%^ - -DBUILD_STATIC=ON^ + -DWITH_STATIC_DEPS=ON^ -DBUILD_SHARED_LIBS=%build_shared%^ -DBUILD_TEST=%build_test%^ -DENABLE_LOGGING=%enable_logging%^ diff --git a/cmake/FindGFlags.cmake b/cmake/FindGFlags.cmake new file mode 100644 index 0000000000..9a06798db1 --- /dev/null +++ b/cmake/FindGFlags.cmake @@ -0,0 +1,17 @@ +find_path(GFLAGS_INCLUDE_DIR NAMES gflags.h) + +find_library(GFLAGS_LIBRARY NAMES gflags libgflags) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GFlags + DEFAULT_MSG GFLAGS_LIBRARY GFLAGS_INCLUDE_DIR +) +if(GFLAGS_FOUND AND NOT TARGET GFlags::GFlags) + add_library(GFlags::GFlags UNKNOWN IMPORTED) + set_target_properties(GFlags::GFlags PROPERTIES + IMPORTED_LOCATION "${GFLAGS_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${GFLAGS_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced(GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY) diff --git a/cmake/FindGLog.cmake b/cmake/FindGLog.cmake new file mode 100644 index 0000000000..45099d64f4 --- /dev/null +++ b/cmake/FindGLog.cmake @@ -0,0 +1,17 @@ +find_path(GLOG_INCLUDE_DIR NAMES glog/logging.h) + +find_library(GLOG_LIBRARY NAMES glog glogd libglog) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GLog + DEFAULT_MSG GLOG_LIBRARY GLOG_INCLUDE_DIR +) +if(GLOG_FOUND AND NOT TARGET GLog::GLog) + add_library(GLog::GLog UNKNOWN IMPORTED) + set_target_properties(GLog::GLog PROPERTIES + IMPORTED_LOCATION "${GLOG_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${GLOG_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced(GLOG_INCLUDE_DIR GLOG_LIBRARY) diff --git a/cmake/FindGflags.cmake b/cmake/FindGflags.cmake deleted file mode 100644 index c20b9abd20..0000000000 --- a/cmake/FindGflags.cmake +++ /dev/null @@ -1,26 +0,0 @@ -set(_gflags_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - -find_path(Gflags_INCLUDE_PATH gflags/gflags.h) - -if (Gflags_STATIC) - if (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) - else (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - endif (WIN32) -endif (Gflags_STATIC) -find_library(Gflags_LIBRARY NAMES gflags libgflags) -if(Gflags_INCLUDE_PATH AND Gflags_LIBRARY) - set(Gflags_FOUND TRUE) -endif(Gflags_INCLUDE_PATH AND Gflags_LIBRARY) -if(Gflags_FOUND) - if(NOT Gflags_FIND_QUIETLY) - message(STATUS "Found gflags: ${Gflags_LIBRARY}") - endif(NOT Gflags_FIND_QUIETLY) -else(Gflags_FOUND) - if(Gflags_FIND_REQUIRED) - message(FATAL_ERROR "Could not find gflags library.") - endif(Gflags_FIND_REQUIRED) -endif(Gflags_FOUND) - -set(CMAKE_FIND_LIBRARY_SUFFIXES ${_gflags_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) diff --git a/cmake/FindGlog.cmake b/cmake/FindGlog.cmake deleted file mode 100644 index d0a15c54a3..0000000000 --- a/cmake/FindGlog.cmake +++ /dev/null @@ -1,26 +0,0 @@ -set(_glog_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - -find_path(Glog_INCLUDE_PATH glog/logging.h) - -if (Glog_STATIC) - if (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) - else (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - endif (WIN32) -endif (Glog_STATIC) -find_library(Glog_LIBRARY NAMES glog glogd libglog) -if(Glog_INCLUDE_PATH AND Glog_LIBRARY) - set(Glog_FOUND TRUE) -endif(Glog_INCLUDE_PATH AND Glog_LIBRARY) -if(Glog_FOUND) - if(NOT Glog_FIND_QUIETLY) - message(STATUS "Found glog: ${Glog_LIBRARY}") - endif(NOT Glog_FIND_QUIETLY) -else(Glog_FOUND) - if(Glog_FIND_REQUIRED) - message(FATAL_ERROR "Could not find glog library.") - endif(Glog_FIND_REQUIRED) -endif(Glog_FOUND) - -set(CMAKE_FIND_LIBRARY_SUFFIXES ${_glog_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) diff --git a/cmake/FindIconv.cmake b/cmake/FindIconv.cmake deleted file mode 100644 index 76f2769683..0000000000 --- a/cmake/FindIconv.cmake +++ /dev/null @@ -1,43 +0,0 @@ -# Find iconv library -# -# Author: Eddy Xu -# -# Released under BSD license -# -# ICONV_INCLUDE_DIRS - where to find iconv.h, etc -# ICONV_LIBRARIES - Lists of libraries when using iconv -# ICONV_FOUND - True if iconv found - - -# Look for the header file -FIND_PATH( ICONV_INCLUDE_DIR NAMES iconv.h ) -MARK_AS_ADVANCED( ICONV_INCLUDE_DIR ) - -# Look for the library -FIND_LIBRARY( ICONV_LIBRARY NAMES iconv ) -MARK_AS_ADVANCED( ICONV_LIBRARY ) - -# Copy the result to output variables -IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARY) - SET(ICONV_FOUND 1) - SET(ICONV_LIBRARIES ${ICONV_LIBRARY}) - SET(ICONV_INCLUDE_DIRS ${ICONV_INCLUDE_DIR}) -ELSE(ICONV_INCLUDE_DIR AND ICONV_LIBRARY) - SET(ICONV_FOUND 0) - SET(ICONV_LIBRARIES) - SET(ICONV_INCLUDE_DIRS) -ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARY) - -# Report results -IF(NOT ICONV_FOUND) - SET(ICONV_DIR_MESSAGE - "Iconv was not found. Make sure ICONV_LIBRARY and ICONV_INCLUDE_DIR are -set.") - IF(NOT ICONV_FIND_QUIETLY) - MESSAGE(STATUS ${ICONV_DIR_MESSAGE}) - ELSE(NOT ICONV_FIND_QUIETLY) - IF(ICONV_FIND_REQUIRED) - MESSAGE(FETAL_ERROR ${ICONV_DIR_MESSAGE}) - ENDIF(ICONV_FIND_REQUIRED) - ENDIF(NOT ICONV_FIND_QUIETLY) -ENDIF(NOT ICONV_FOUND) diff --git a/cmake/FindLevelDB.cmake b/cmake/FindLevelDB.cmake new file mode 100644 index 0000000000..972637176e --- /dev/null +++ b/cmake/FindLevelDB.cmake @@ -0,0 +1,17 @@ +find_path(LEVELDB_INCLUDE_DIR NAMES leveldb/db.h) + +find_library(LEVELDB_LIBRARY NAMES leveldb libleveldb) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LevelDB + DEFAULT_MSG LEVELDB_LIBRARY LEVELDB_INCLUDE_DIR +) +if(LEVELDB_FOUND AND NOT TARGET LevelDB::LevelDB) + add_library(LevelDB::LevelDB UNKNOWN IMPORTED) + set_target_properties(LevelDB::LevelDB PROPERTIES + IMPORTED_LOCATION "${LEVELDB_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${LEVELDB_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced(LEVELDB_INCLUDE_DIR LEVELDB_LIBRARY) diff --git a/cmake/FindLevelDb.cmake b/cmake/FindLevelDb.cmake deleted file mode 100644 index 7c3cefc300..0000000000 --- a/cmake/FindLevelDb.cmake +++ /dev/null @@ -1,26 +0,0 @@ -set(_leveldb_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - -find_path(LevelDb_INCLUDE_PATH leveldb/db.h) - -if (LevelDb_STATIC) - if (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) - else (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - endif (WIN32) -endif (LevelDb_STATIC) -find_library(LevelDb_LIBRARY NAMES leveldb libleveldb) -if(LevelDb_INCLUDE_PATH AND LevelDb_LIBRARY) - set(LevelDb_FOUND TRUE) -endif(LevelDb_INCLUDE_PATH AND LevelDb_LIBRARY) -if(LevelDb_FOUND) - if(NOT LevelDb_FIND_QUIETLY) - message(STATUS "Found leveldb: ${LevelDb_LIBRARY}") - endif(NOT LevelDb_FIND_QUIETLY) -else(LevelDb_FOUND) - if(LevelDb_FIND_REQUIRED) - message(FATAL_ERROR "Could not find leveldb library.") - endif(LevelDb_FIND_REQUIRED) -endif(LevelDb_FOUND) - -set(CMAKE_FIND_LIBRARY_SUFFIXES ${_leveldb_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) diff --git a/cmake/FindMarisa.cmake b/cmake/FindMarisa.cmake index 9a9851b436..59e3ae2b76 100644 --- a/cmake/FindMarisa.cmake +++ b/cmake/FindMarisa.cmake @@ -1,26 +1,17 @@ -set(_marisa_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) +find_path(MARISA_INCLUDE_DIR NAMES marisa.h) -find_path(Marisa_INCLUDE_PATH marisa.h) +find_library(MARISA_LIBRARY NAMES marisa libmarisa) -if (Marisa_STATIC) - if (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) - else (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - endif (WIN32) -endif (Marisa_STATIC) -find_library(Marisa_LIBRARY NAMES marisa libmarisa) -if(Marisa_INCLUDE_PATH AND Marisa_LIBRARY) - set(Marisa_FOUND TRUE) -endif(Marisa_INCLUDE_PATH AND Marisa_LIBRARY) -if(Marisa_FOUND) - if(NOT Marisa_FIND_QUIETLY) - message(STATUS "Found marisa: ${Marisa_LIBRARY}") - endif(NOT Marisa_FIND_QUIETLY) -else(Marisa_FOUND) - if(Marisa_FIND_REQUIRED) - message(FATAL_ERROR "Could not find marisa library.") - endif(Marisa_FIND_REQUIRED) -endif(Marisa_FOUND) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Marisa + DEFAULT_MSG MARISA_LIBRARY MARISA_INCLUDE_DIR +) +if(MARISA_FOUND AND NOT TARGET Marisa::Marisa) + add_library(Marisa::Marisa UNKNOWN IMPORTED) + set_target_properties(Marisa::Marisa PROPERTIES + IMPORTED_LOCATION "${MARISA_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${MARISA_INCLUDE_DIR}" + ) +endif() -set(CMAKE_FIND_LIBRARY_SUFFIXES ${_marisa_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) +mark_as_advanced(MARISA_INCLUDE_DIR MARISA_LIBRARY) diff --git a/cmake/FindOpenCC.cmake b/cmake/FindOpenCC.cmake new file mode 100644 index 0000000000..eae70fb2e9 --- /dev/null +++ b/cmake/FindOpenCC.cmake @@ -0,0 +1,17 @@ +find_path(OPENCC_INCLUDE_DIR NAMES opencc/opencc.h) + +find_library(OPENCC_LIBRARY NAMES opencc) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(OpenCC + DEFAULT_MSG OPENCC_LIBRARY OPENCC_INCLUDE_DIR +) +if(OPENCC_FOUND AND NOT TARGET OpenCC::OpenCC) + add_library(OpenCC::OpenCC UNKNOWN IMPORTED) + set_target_properties(OpenCC::OpenCC PROPERTIES + IMPORTED_LOCATION "${OPENCC_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${OPENCC_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced(OPENCC_INCLUDE_DIR OPENCC_LIBRARY) diff --git a/cmake/FindOpencc.cmake b/cmake/FindOpencc.cmake deleted file mode 100644 index ea7f40707a..0000000000 --- a/cmake/FindOpencc.cmake +++ /dev/null @@ -1,26 +0,0 @@ -set(_opencc_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - -find_path(Opencc_INCLUDE_PATH opencc/opencc.h) - -if (Opencc_STATIC) - if (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) - else (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - endif (WIN32) -endif (Opencc_STATIC) -find_library(Opencc_LIBRARY NAMES opencc) -if(Opencc_INCLUDE_PATH AND Opencc_LIBRARY) - set(Opencc_FOUND TRUE) -endif(Opencc_INCLUDE_PATH AND Opencc_LIBRARY) -if(Opencc_FOUND) - if(NOT Opencc_FIND_QUIETLY) - message(STATUS "Found opencc: ${Opencc_LIBRARY}") - endif(NOT Opencc_FIND_QUIETLY) -else(Opencc_FOUND) - if(Opencc_FIND_REQUIRED) - message(FATAL_ERROR "Could not find opencc library.") - endif(Opencc_FIND_REQUIRED) -endif(Opencc_FOUND) - -set(CMAKE_FIND_LIBRARY_SUFFIXES ${_opencc_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) diff --git a/cmake/FindYamlCpp.cmake b/cmake/FindYamlCpp.cmake index 030a4a2efc..e68a3a5be0 100644 --- a/cmake/FindYamlCpp.cmake +++ b/cmake/FindYamlCpp.cmake @@ -1,32 +1,21 @@ -set(_yamlcpp_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) +find_path(YAML_CPP_INCLUDE_DIR NAMES yaml-cpp/yaml.h) -find_path(YamlCpp_INCLUDE_PATH yaml-cpp/yaml.h) +# Find library +find_library(YAML_CPP_LIBRARY NAMES yaml-cpp libyaml-cpp) -find_path(YamlCpp_NEW_API yaml-cpp/node/node.h) -if(YamlCpp_INCLUDE_PATH AND NOT YamlCpp_NEW_API) - message(FATAL_ERROR "The new yaml-cpp 0.5 API is not available.") -endif() - -if (YamlCpp_STATIC) - if (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) - else (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - endif (WIN32) -endif (YamlCpp_STATIC) -find_library(YamlCpp_LIBRARY NAMES libyaml-cppmt libyaml-cppmtd yaml-cpp) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(YamlCpp + DEFAULT_MSG YAML_CPP_LIBRARY YAML_CPP_INCLUDE_DIR +) -if(YamlCpp_INCLUDE_PATH AND YamlCpp_LIBRARY) - set(YamlCpp_FOUND TRUE) -endif(YamlCpp_INCLUDE_PATH AND YamlCpp_LIBRARY) -if(YamlCpp_FOUND) - if(NOT YamlCpp_FIND_QUIETLY) - message(STATUS "Found yaml-cpp: ${YamlCpp_LIBRARY}") - endif(NOT YamlCpp_FIND_QUIETLY) -else(YamlCpp_FOUND) - if(YamlCpp_FIND_REQUIRED) - message(FATAL_ERROR "Could not find yaml-cpp library.") - endif(YamlCpp_FIND_REQUIRED) -endif(YamlCpp_FOUND) +if(YAMLCPP_FOUND AND NOT TARGET YamlCpp::YamlCpp) + set(YAML_CPP_LIBRARIES ${YAML_CPP_LIBRARY}) + add_library(YamlCpp::YamlCpp UNKNOWN IMPORTED) + set_target_properties(YamlCpp::YamlCpp PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + IMPORTED_LOCATION "${YAML_CPP_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${YAML_CPP_INCLUDE_DIR}" + ) +endif() -set(CMAKE_FIND_LIBRARY_SUFFIXES ${_yamlcpp_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) +mark_as_advanced(YAML_CPP_INCLUDE_DIR YAML_CPP_LIBRARY) diff --git a/lib/.placeholder b/lib/.placeholder deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/rime.pc.in b/rime.pc.in index 1a8c543183..9d08a5b0ff 100644 --- a/rime.pc.in +++ b/rime.pc.in @@ -1,9 +1,9 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ -pkgdatadir=@pkgdatadir@ -pluginsdir=@pluginsdir@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ +pkgdatadir=@RIME_DATA_DIR@ +pluginsdir=@RIME_PLUGINS_DIR@ Name: Rime Description: Rime Input Method Engine diff --git a/share/.placeholder b/share/.placeholder deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6364e1c8e8..edfd4e4fb5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,33 +31,32 @@ else() ${rime_plugins_objs}) endif() -set(rime_optional_deps "") if(Gflags_FOUND) - set(rime_optional_deps ${rime_optional_deps} ${Gflags_LIBRARY}) + list(APPEND rime_optional_deps GFlags::GFlags) endif() if(ENABLE_EXTERNAL_PLUGINS) - set(rime_optional_deps ${rime_optional_deps} dl) + list(APPEND rime_optional_deps dl) endif() set(rime_core_deps ${Boost_LIBRARIES} - ${Glog_LIBRARY} - ${YamlCpp_LIBRARY} + GLog::GLog + YamlCpp::YamlCpp ${CMAKE_THREAD_LIBS_INIT} ${rime_optional_deps}) set(rime_dict_deps - ${LevelDb_LIBRARY} - ${Marisa_LIBRARY}) + LevelDB::LevelDB + Marisa::Marisa) set(rime_gears_deps ${ICONV_LIBRARIES} ${ICU_LIBRARIES} - ${Opencc_LIBRARY}) + OpenCC::OpenCC) set(rime_levers_deps "") if(MINGW) # fix: bcrypt for boost uuid issue # https://github.com/boostorg/uuid/issues/68 - set(rime_core_deps ${rime_core_deps} wsock32 ws2_32 bcrypt) + list(APPEND rime_core_deps wsock32 ws2_32 bcrypt) endif() if(BUILD_SEPARATE_LIBS) diff --git a/src/rime/setup.cc b/src/rime/setup.cc index 3091838783..7cae457b30 100644 --- a/src/rime/setup.cc +++ b/src/rime/setup.cc @@ -26,7 +26,7 @@ namespace fs = std::filesystem; namespace rime { #define Q(x) #x -RIME_API RIME_MODULE_LIST(kDefaultModules, "default" RIME_EXTRA_MODULES); +RIME_API RIME_MODULE_LIST(kDefaultModules, "default", RIME_EXTRA_MODULES); #undef Q RIME_API RIME_MODULE_LIST(kDeployerModules, "deployer"); RIME_MODULE_LIST(kLegacyModules, "legacy"); diff --git a/src/rime_api.h b/src/rime_api.h index ae4467abc8..c8f4b6f77f 100644 --- a/src/rime_api.h +++ b/src/rime_api.h @@ -712,7 +712,7 @@ RIME_API RimeApi* rime_get_api(void); /*! * Defines a constant for a list of module names. */ -#define RIME_MODULE_LIST(var, ...) const char* var[] = {__VA_ARGS__, NULL} +#define RIME_MODULE_LIST(var, ...) const char* var[] = {__VA_ARGS__} /*! * Register a phony module which, when loaded, will load a list of modules. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 80fb5ddd8f..01c1c89a44 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,17 +1,33 @@ +if(WIN32) + if(BUILD_SHARED_LIBS AND BUILD_SEPARATE_LIBS) + add_custom_target(copy_librime_to_test + COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Copying librime (separated) to test" + ) + else() + add_custom_target(copy_librime_to_test + COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Copying librime (full) to test" + ) + endif() +endif() + aux_source_directory(. rime_test_src) -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/test) add_executable(rime_test ${rime_test_src}) target_link_libraries(rime_test ${rime_library} ${rime_dict_library} ${rime_gears_library} - ${GTEST_LIBRARIES}) + GTest::gtest + GTest::gtest_main) if(BUILD_SHARED_LIBS) target_compile_definitions(rime_test PRIVATE RIME_IMPORTS) endif(BUILD_SHARED_LIBS) -file(GLOB test_data_files ${PROJECT_SOURCE_DIR}/data/test/*.yaml) -file(COPY ${test_data_files} DESTINATION ${EXECUTABLE_OUTPUT_PATH}) - -set(rime_test_executable ${EXECUTABLE_OUTPUT_PATH}/rime_test${ext}) -add_test(rime_test ${rime_test_executable}) +add_test(NAME rime_test COMMAND rime_test + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/data/test") +if(WIN32) + add_dependencies(rime_test copy_librime_to_test) +endif()