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

Improve CMake Scripts Composing #749

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 2 additions & 5 deletions .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
82 changes: 17 additions & 65 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Empty file removed bin/.placeholder
Empty file.
2 changes: 1 addition & 1 deletion build-clang.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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^
Expand Down
2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%^
Expand Down
17 changes: 17 additions & 0 deletions cmake/FindGFlags.cmake
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions cmake/FindGLog.cmake
Original file line number Diff line number Diff line change
@@ -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)
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.

43 changes: 0 additions & 43 deletions cmake/FindIconv.cmake

This file was deleted.

17 changes: 17 additions & 0 deletions cmake/FindLevelDB.cmake
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 0 additions & 26 deletions cmake/FindLevelDb.cmake

This file was deleted.

Loading