From e321b9dbcda33a4240442ebe3bfc25887b4678d0 Mon Sep 17 00:00:00 2001 From: Weng Xuetian Date: Sat, 7 Dec 2024 14:36:22 -0800 Subject: [PATCH] Add support for static library build --- CMakeLists.txt | 3 ++- src/libime/core/CMakeLists.txt | 4 ++-- src/libime/pinyin/CMakeLists.txt | 2 +- src/libime/table/CMakeLists.txt | 2 +- tools/CMakeLists.txt | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f7316ee1..444b6708 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.12) project(libime VERSION 1.1.9) set(LibIME_VERSION ${PROJECT_VERSION}) @@ -8,6 +8,7 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${C ######################################### # Options ######################################### +option(BUILD_SHARED_LIBS "Build library as shared libs" On) option(ENABLE_TEST "Build Test" On) option(ENABLE_COVERAGE "Build the project with gcov support (Need ENABLE_TEST=On)" Off) set(GCOV_TOOL "gcov" CACHE STRING "Path to gcov tool used by coverage.") diff --git a/src/libime/core/CMakeLists.txt b/src/libime/core/CMakeLists.txt index 35ee9546..d51e732d 100644 --- a/src/libime/core/CMakeLists.txt +++ b/src/libime/core/CMakeLists.txt @@ -9,7 +9,7 @@ foreach(f ${__KENLM_SRCS}) endif() endforeach() -add_library(kenlm STATIC ${KENLM_SRCS}) +add_library(kenlm OBJECT ${KENLM_SRCS}) target_include_directories(kenlm PUBLIC $) target_compile_definitions(kenlm PUBLIC -DKENLM_MAX_ORDER=3 PRIVATE -DNDEBUG) target_link_libraries(kenlm PUBLIC Boost::boost PkgConfig::ZSTD) @@ -69,7 +69,7 @@ ecm_setup_version(PROJECT # the cmake if will set(IMECore_SOVERSION 0) -add_library(IMECore SHARED ${LIBIME_SRCS}) +add_library(IMECore ${LIBIME_SRCS}) set_target_properties(IMECore PROPERTIES VERSION ${IMECore_VERSION} SOVERSION ${IMECore_SOVERSION} diff --git a/src/libime/pinyin/CMakeLists.txt b/src/libime/pinyin/CMakeLists.txt index a5e6d351..96fcbbbb 100644 --- a/src/libime/pinyin/CMakeLists.txt +++ b/src/libime/pinyin/CMakeLists.txt @@ -32,7 +32,7 @@ ecm_setup_version(PROJECT PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/LibIMEPinyinConfigVersion.cmake") set(IMEPinyin_SOVERSION 0) -add_library(IMEPinyin SHARED ${LIBIME_PINYIN_SRCS}) +add_library(IMEPinyin ${LIBIME_PINYIN_SRCS}) set_target_properties(IMEPinyin PROPERTIES VERSION ${IMEPinyin_VERSION} SOVERSION ${IMEPinyin_SOVERSION} diff --git a/src/libime/table/CMakeLists.txt b/src/libime/table/CMakeLists.txt index 62317bd6..620a6ee6 100644 --- a/src/libime/table/CMakeLists.txt +++ b/src/libime/table/CMakeLists.txt @@ -23,7 +23,7 @@ ecm_setup_version(PROJECT PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/LibIMETableConfigVersion.cmake") set(IMETable_SOVERSION 0) -add_library(IMETable SHARED ${LIBIME_TABLE_SRCS}) +add_library(IMETable ${LIBIME_TABLE_SRCS}) set_target_properties(IMETable PROPERTIES VERSION ${IMETable_VERSION} SOVERSION ${IMETable_SOVERSION} diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index e5ecf4b0..b8b94455 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -24,7 +24,7 @@ target_link_libraries(libime_tabledict LibIME::Table) install(TARGETS libime_tabledict DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT tools) add_executable(LibIME::tabledict ALIAS libime_tabledict) -add_library(filesystem_helper filesystem_helper.cpp) +add_library(filesystem_helper STATIC filesystem_helper.cpp) if (HAS_STD_FILESYSTEM) target_compile_definitions(filesystem_helper PRIVATE -DHAS_STD_FILESYSTEM) else()