Skip to content

Commit

Permalink
build: more neat cmake find modules
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Oct 29, 2023
1 parent 48a2341 commit 4ba55d0
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 185 deletions.
31 changes: 5 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,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(WITH_STATIC_DEPS)
add_definitions(-DGOOGLE_GLOG_DLL_DECL=)
endif()

set(RIME_ENABLE_LOGGING 1)

endif()

find_package(Threads)
Expand All @@ -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(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()
find_package(OpenCC REQUIRED)
if(WITH_STATIC_DEPS)
add_definitions(-DOpencc_BUILT_AS_STATIC)
endif()
Expand Down
21 changes: 21 additions & 0 deletions cmake/FindGFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
find_path(GFLAGS_INCLUDE_DIR NAMES gflags.h)

find_library(GFLAGS_LIBRARY NAMES gflags libgflags)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GFlags
FOUND_VAR
GFLAGS_FOUND
REQUIRED_VARS
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)
21 changes: 21 additions & 0 deletions cmake/FindGLog.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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
FOUND_VAR
GLOG_FOUND
REQUIRED_VARS
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)
26 changes: 0 additions & 26 deletions cmake/FindGflags.cmake

This file was deleted.

26 changes: 0 additions & 26 deletions cmake/FindGlog.cmake

This file was deleted.

41 changes: 18 additions & 23 deletions cmake/FindLevelDb.cmake
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
set(_leveldb_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
find_path(LEVELDB_INCLUDE_DIR NAMES leveldb/db.h)

find_path(LevelDb_INCLUDE_PATH leveldb/db.h)
find_library(LEVELDB_LIBRARY NAMES leveldb libleveldb)

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)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LevelDB
FOUND_VAR
LEVELDB_FOUND
REQUIRED_VARS
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()

set(CMAKE_FIND_LIBRARY_SUFFIXES ${_leveldb_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
mark_as_advanced(LEVELDB_INCLUDE_DIR LEVELDB_LIBRARY)
41 changes: 18 additions & 23 deletions cmake/FindMarisa.cmake
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
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 (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)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Marisa
FOUND_VAR
MARISA_FOUND
REQUIRED_VARS
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)
21 changes: 21 additions & 0 deletions cmake/FindOpenCC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
find_path(OPENCC_INCLUDE_DIR NAMES opencc/opencc.h)

find_library(OPENCC_LIBRARY NAMES opencc)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenCC
FOUND_VAR
OPENCC_FOUND
REQUIRED_VARS
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)
26 changes: 0 additions & 26 deletions cmake/FindOpencc.cmake

This file was deleted.

48 changes: 20 additions & 28 deletions cmake/FindYamlCpp.cmake
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
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(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 (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
FOUND_VAR
YAML_CPP_FOUND
REQUIRED_VARS
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(YAML_CPP_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)
14 changes: 7 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@ else()
${rime_plugins_objs})
endif()

if(Gflags_FOUND)
list(APPEND rime_optional_deps ${Gflags_LIBRARY})
if(GFLGAS_FOUND)
list(APPEND rime_optional_deps GFlags::gflags)
endif()
if(ENABLE_EXTERNAL_PLUGINS)
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)
Expand Down

0 comments on commit 4ba55d0

Please sign in to comment.