diff --git a/CMakeLists.txt b/CMakeLists.txt index d3a32f7684..52faf19d87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,22 +60,14 @@ if(Boost_FOUND) endif() if(ENABLE_LOGGING) - 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(WITH_STATIC_DEPS) add_definitions(-DGOOGLE_GLOG_DLL_DECL=) endif() - + set(RIME_ENABLE_LOGGING 1) - endif() find_package(Threads) @@ -97,27 +89,14 @@ if(BUILD_TEST) endif() find_package(YamlCpp REQUIRED) -if(YamlCpp_FOUND) - include_directories(${YamlCpp_INCLUDE_PATH}) -endif() 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(Marisa REQUIRED) -if(Marisa_FOUND) - include_directories(${Marisa_INCLUDE_PATH}) -endif() -find_package(Opencc REQUIRED) -if(Opencc_FOUND) -include_directories(${Opencc_INCLUDE_PATH}) -endif() +find_package(OpenCC REQUIRED) if(WITH_STATIC_DEPS) add_definitions(-DOpencc_BUILT_AS_STATIC) endif() diff --git a/cmake/FindGflags.cmake b/cmake/FindGflags.cmake index f149a75871..09e65d08f7 100644 --- a/cmake/FindGflags.cmake +++ b/cmake/FindGflags.cmake @@ -1,26 +1,25 @@ -set(_gflags_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) +# Find the gflags include directory and library +# +# GFLAGS_INCLUDE_DIR - Where to find +# GFLAGS_LIBRARIES - List of gflags libraries +# Gflags_FOUND - True if gflags found -find_path(Gflags_INCLUDE_PATH gflags/gflags.h) +# Find include directory +find_path(GFLAGS_INCLUDE_DIR NAMES gflags.h) -if (WITH_STATIC_DEPS) - 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 () -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) +# Find library +find_library(GFLAGS_LIBRARY NAMES gflags libgflags) -set(CMAKE_FIND_LIBRARY_SUFFIXES ${_gflags_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) +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 index d1849bb568..d5d440b235 100644 --- a/cmake/FindGlog.cmake +++ b/cmake/FindGlog.cmake @@ -1,26 +1,25 @@ -set(_glog_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) +# Find the glog include directory and library +# +# GLOG_INCLUDE_DIR - Where to find +# GLOG_LIBRARIES - List of glog libraries +# Glog_FOUND - True if glog found -find_path(Glog_INCLUDE_PATH glog/logging.h) +# Find include directory +find_path(GLOG_INCLUDE_DIR NAMES glog/logging.h) -if (WITH_STATIC_DEPS) - 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 () -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) +# Find library +find_library(GLOG_LIBRARY NAMES glog glogd libglog) -set(CMAKE_FIND_LIBRARY_SUFFIXES ${_glog_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) +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/FindIconv.cmake b/cmake/FindIconv.cmake index 76f2769683..928f521c06 100644 --- a/cmake/FindIconv.cmake +++ b/cmake/FindIconv.cmake @@ -1,6 +1,6 @@ # Find iconv library -# # Author: Eddy Xu +# Edit: WhiredPlanck # # Released under BSD license # diff --git a/cmake/FindLevelDb.cmake b/cmake/FindLevelDb.cmake index 3f6db89864..fbc7d96097 100644 --- a/cmake/FindLevelDb.cmake +++ b/cmake/FindLevelDb.cmake @@ -1,26 +1,25 @@ -set(_leveldb_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) +# Find the leveldb include directory and library +# +# LEVELDB_INCLUDE_DIR - Where to find +# LEVELDB_LIBRARIES - List of leveldb libraries +# LevelDb_FOUND - True if levedb found -find_path(LevelDb_INCLUDE_PATH leveldb/db.h) +# Find include directory +find_path(LEVELDB_INCLUDE_DIR NAMES leveldb/db.h) -if (WITH_STATIC_DEPS) - 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 () -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) +# Find library +find_library(LEVELDB_LIBRARY NAMES leveldb libleveldb) -set(CMAKE_FIND_LIBRARY_SUFFIXES ${_leveldb_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) +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/FindMarisa.cmake b/cmake/FindMarisa.cmake index 046e34e310..2ac501f92e 100644 --- a/cmake/FindMarisa.cmake +++ b/cmake/FindMarisa.cmake @@ -1,26 +1,25 @@ -set(_marisa_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) +# Find the marisa-trie include directory and library +# +# MARISA_INCLUDE_DIR - Where to find +# MARISA_LIBRARIES - List of marisa-trie libraries +# Marisa_FOUND - True if marisa-trie found -find_path(Marisa_INCLUDE_PATH marisa.h) +# Find include directory +find_path(MARISA_INCLUDE_DIR NAMES marisa.h) -if (WITH_STATIC_DEPS) - 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 () -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) +# Find library +find_library(MARISA_LIBRARY NAMES marisa libmarisa) -set(CMAKE_FIND_LIBRARY_SUFFIXES ${_marisa_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) +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() + +mark_as_advanced(MARISA_INCLUDE_DIR MARISA_LIBRARY) diff --git a/cmake/FindOpenCC.cmake b/cmake/FindOpenCC.cmake new file mode 100644 index 0000000000..94f4a51016 --- /dev/null +++ b/cmake/FindOpenCC.cmake @@ -0,0 +1,25 @@ +# Find the opencc include directory and library +# +# OPENCC_INCLUDE_DIR - Where to find +# OPENCC_LIBRARIES - List of opencc libraries +# OpenCC_FOUND - True if opencc found + +# Find include directory +find_path(OPENCC_INCLUDE_DIR NAMES opencc/opencc.h) + +# Find library +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 32c9235a5b..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 (WITH_STATIC_DEPS) - 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 () -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 9f26ec0d73..415e82bbc7 100644 --- a/cmake/FindYamlCpp.cmake +++ b/cmake/FindYamlCpp.cmake @@ -1,32 +1,28 @@ -set(_yamlcpp_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) +# Find the yaml-cpp include directory and library +# +# YAML_CPP_INCLUDE_DIR - Where to find +# YAML_CPP_LIBRARIES - List of yaml-cpp libraries +# YamlCpp_FOUND - True if yaml-cpp found -find_path(YamlCpp_INCLUDE_PATH yaml-cpp/yaml.h) +# Find include directory +find_path(YAML_CPP_INCLUDE_DIR NAMES yaml-cpp/yaml.h) -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() +# Find library +find_library(YAML_CPP_LIBRARY NAMES yaml-cpp libyaml-cpp) -if (WITH_STATIC_DEPS) - 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 () -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/src/CMakeLists.txt b/src/CMakeLists.txt index 6fc781e42d..8649b150ce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,7 +32,7 @@ else() endif() if(Gflags_FOUND) - list(APPEND rime_optional_deps ${Gflags_LIBRARY}) + list(APPEND rime_optional_deps Gflags::Gflags) endif() if(ENABLE_EXTERNAL_PLUGINS) list(APPEND rime_optional_deps dl) @@ -40,17 +40,17 @@ 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)