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

make boost::filesystem optional #81

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
25 changes: 23 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ option(ENABLE_COVERAGE "Build the project with gcov support (Need ENABLE_TEST=On
set(GCOV_TOOL "gcov" CACHE STRING "Path to gcov tool used by coverage.")
option(ENABLE_DOC "Build doxygen" Off)
option(ENABLE_DATA "Build data" On)
option(ENABLE_TOOLS "Build tools" On)

#########################################
# Dependency
Expand All @@ -34,7 +35,24 @@ pkg_check_modules(ZSTD REQUIRED IMPORTED_TARGET "libzstd")
find_package(Fcitx5Utils REQUIRED)
include("${FCITX_INSTALL_CMAKECONFIG_DIR}/Fcitx5Utils/Fcitx5CompilerSettings.cmake")

find_package(Boost 1.61 REQUIRED COMPONENTS iostreams filesystem)
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("
#include <filesystem>
int main() {
return std::filesystem::is_regular_file(\"/\") ? 0 : 1;
eagleoflqj marked this conversation as resolved.
Show resolved Hide resolved
}
" HAS_STD_FILESYSTEM)

if (HAS_STD_FILESYSTEM)
wengxt marked this conversation as resolved.
Show resolved Hide resolved
set(BOOST_FILESYSTEM)
set(BOOST_FILESYSTEM_LIB)
else()
add_definitions(-DUSE_BOOST_FILESYSTEM)
set(BOOST_FILESYSTEM filesystem)
set(BOOST_FILESYSTEM_LIB Boost::filesystem)
endif()

find_package(Boost 1.61 REQUIRED COMPONENTS iostreams ${BOOST_FILESYSTEM})
set(LIBIME_INSTALL_PKGDATADIR "${CMAKE_INSTALL_FULL_DATADIR}/libime")
set(LIBIME_INSTALL_LIBDATADIR "${CMAKE_INSTALL_FULL_LIBDIR}/libime")

Expand All @@ -56,7 +74,10 @@ if(ENABLE_TEST)
endif()

add_subdirectory(src)
add_subdirectory(tools)

if (ENABLE_TOOLS)
add_subdirectory(tools)
endif()

if (ENABLE_DATA)
add_subdirectory(data)
Expand Down
6 changes: 4 additions & 2 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ target_link_libraries(libime_tabledict LibIME::Table)
install(TARGETS libime_tabledict DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT tools)
add_executable(LibIME::tabledict ALIAS libime_tabledict)

if (NOT APPLE)
eagleoflqj marked this conversation as resolved.
Show resolved Hide resolved
add_executable(libime_migrate_fcitx4_table libime_migrate_fcitx4_table.cpp)
eagleoflqj marked this conversation as resolved.
Show resolved Hide resolved
target_link_libraries(libime_migrate_fcitx4_table LibIME::Table Boost::iostreams Boost::filesystem)
target_link_libraries(libime_migrate_fcitx4_table LibIME::Table Boost::iostreams ${BOOST_FILESYSTEM_LIB})
install(TARGETS libime_migrate_fcitx4_table DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT tools)
add_executable(LibIME::migrate_fcitx4_table ALIAS libime_migrate_fcitx4_table)

add_executable(libime_migrate_fcitx4_pinyin libime_migrate_fcitx4_pinyin.cpp)
target_link_libraries(libime_migrate_fcitx4_pinyin LibIME::Pinyin Boost::iostreams Boost::filesystem)
target_link_libraries(libime_migrate_fcitx4_pinyin LibIME::Pinyin Boost::iostreams ${BOOST_FILESYSTEM_LIB})
install(TARGETS libime_migrate_fcitx4_pinyin DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT tools)
add_executable(LibIME::migrate_fcitx4_pinyin ALIAS libime_migrate_fcitx4_pinyin)
endif()
6 changes: 3 additions & 3 deletions tools/libime_migrate_fcitx4_pinyin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <string_view>
#include <unordered_map>

#if __GNUC__ <= 8
#ifdef USE_BOOST_FILESYSTEM
#include <boost/filesystem.hpp>
#else
#include <filesystem>
Expand Down Expand Up @@ -347,7 +347,7 @@ int main(int argc, char *argv[]) {
if (dictFile[0] == '/') {
outputDictFile = dictFile;
} else {
#if __GNUC__ <= 8
#ifdef USE_BOOST_FILESYSTEM
outputDictFile = boost::filesystem::absolute(dictFile).string();
#else
outputDictFile = std::filesystem::absolute(dictFile);
Expand All @@ -373,7 +373,7 @@ int main(int argc, char *argv[]) {
if (historyFile[0] == '/') {
outputHistoryFile = historyFile;
} else {
#if __GNUC__ <= 8
#ifdef USE_BOOST_FILESYSTEM
outputHistoryFile =
boost::filesystem::absolute(historyFile).string();
#else
Expand Down
4 changes: 2 additions & 2 deletions tools/libime_migrate_fcitx4_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <fcntl.h>
#include <sstream>

#if __GNUC__ <= 8
#ifdef USE_BOOST_FILESYSTEM
#include <boost/filesystem.hpp>
#else
#include <filesystem>
Expand Down Expand Up @@ -82,7 +82,7 @@ struct MigrationCommonOption {
return stringutils::joinPath("table", path);
}

#if __GNUC__ <= 8
#ifdef USE_BOOST_FILESYSTEM
return boost::filesystem::absolute(path).string();
#else
return std::filesystem::absolute(path);
Expand Down
Loading