From 31304c1f956b14f0e85aa045c90157cd9d780399 Mon Sep 17 00:00:00 2001 From: WhiredPlanck Date: Thu, 16 Nov 2023 12:52:38 +0800 Subject: [PATCH] buidl(jni): try to improve boost build --- app/src/main/jni/CMakeLists.txt | 14 +--- app/src/main/jni/cmake/Boost.cmake | 37 +++++++++ app/src/main/jni/cmake/FindBoost.cmake | 100 ++++------------------- app/src/main/jni/cmake/RimePlugins.cmake | 12 +-- 4 files changed, 57 insertions(+), 106 deletions(-) create mode 100644 app/src/main/jni/cmake/Boost.cmake diff --git a/app/src/main/jni/CMakeLists.txt b/app/src/main/jni/CMakeLists.txt index 985e420f04..1843035ff6 100644 --- a/app/src/main/jni/CMakeLists.txt +++ b/app/src/main/jni/CMakeLists.txt @@ -16,19 +16,7 @@ include(Iconv) # workaround for boost install install(TARGETS iconv EXPORT boost_locale-targets) -set(BOOST_VER 1.83.0) -if(NOT EXISTS ${CMAKE_SOURCE_DIR}/boost) - file( - DOWNLOAD "https://github.com/boostorg/boost/releases/download/boost-${BOOST_VER}/boost-${BOOST_VER}.tar.xz" boost-${BOOST_VER}.tar.xz - EXPECTED_HASH SHA256=c5a0688e1f0c05f354bbd0b32244d36085d9ffc9f932e8a18983a9908096f614 - SHOW_PROGRESS - ) - file(ARCHIVE_EXTRACT INPUT boost-${BOOST_VER}.tar.xz - DESTINATION ${CMAKE_SOURCE_DIR} - ) - file(RENAME "boost-${BOOST_VER}" boost) -endif() -add_subdirectory(boost) +include(Boost) option(WITH_GFLAGS "Use gflags" OFF) option(WITH_GTEST "Use googletest" OFF) diff --git a/app/src/main/jni/cmake/Boost.cmake b/app/src/main/jni/cmake/Boost.cmake new file mode 100644 index 0000000000..f8fe507c63 --- /dev/null +++ b/app/src/main/jni/cmake/Boost.cmake @@ -0,0 +1,37 @@ +set(BOOST_VER 1.83.0) + +if(NOT EXISTS "${CMAKE_SOURCE_DIR}/boost") + file( + DOWNLOAD "https://github.com/boostorg/boost/releases/download/boost-${BOOST_VER}/boost-${BOOST_VER}.tar.xz" boost-${BOOST_VER}.tar.xz + EXPECTED_HASH SHA256=c5a0688e1f0c05f354bbd0b32244d36085d9ffc9f932e8a18983a9908096f614 + SHOW_PROGRESS + ) + file(ARCHIVE_EXTRACT INPUT boost-${BOOST_VER}.tar.xz + DESTINATION ${CMAKE_SOURCE_DIR} + ) + file(RENAME + "${CMAKE_SOURCE_DIR}/boost-${BOOST_VER}" + "${CMAKE_SOURCE_DIR}/boost" + ) +endif() + +set(BOOST_INCLUDE_LIBRARIES + algorithm + crc + date_time + dll + interprocess + range + regex + scope_exit + signals2 + utility + uuid + # librime-charcode + locale + asio + # librime-lua + optional +) + +add_subdirectory(${CMAKE_SOURCE_DIR}/boost EXCLUDE_FROM_ALL) diff --git a/app/src/main/jni/cmake/FindBoost.cmake b/app/src/main/jni/cmake/FindBoost.cmake index 31146edb93..8dd416f87e 100644 --- a/app/src/main/jni/cmake/FindBoost.cmake +++ b/app/src/main/jni/cmake/FindBoost.cmake @@ -1,92 +1,22 @@ set(Boost_FOUND TRUE) -# libraries that can't compile -set(BOOST_EXCLUDE_LIBRARIES "context;coroutine;fiber" CACHE STRING "" FORCE) +foreach(_lib ${BOOST_INCLUDE_LIBRARIES}) + list(APPEND libraries Boost::${_lib}) +endforeach() -# we have to specify all libraries and their dependencies manually for Boost_LIBRARIES -# you can dump them from boost/tools/cmake/include/BoostRoot.cmake ${__boost_include_libraries} -set(BOOST_INSTALLED_LIBRARIES - # used by librime directly: - "algorithm" - "any" - "crc" - "date_time" - "dll" - "filesystem" - "format" - "interprocess" - "iostreams" - "lexical_cast" - "optional" - "range" - "regex" - "scope_exit" - "signals2" - "utility" - "uuid" - # for librime-charcode: - "locale" - # dumped from ${__boost_include_libraries}: - "array" - "assert" - "bind" - "concept_check" - "config" - "core" - "coroutine" - "describe" - "exception" - "function" - "iterator" - "mpl" - "static_assert" - "throw_exception" - "tuple" - "type_traits" - "unordered" - "type_index" - "integer" - "io" - "numeric_conversion" - "smart_ptr" - "tokenizer" - "winapi" - "move" - "predef" - "spirit" - "system" - "container_hash" - "detail" - "container" - "intrusive" - "preprocessor" - "random" - "conversion" - "typeof" - "parameter" - "variant" - "serialization" - "tti" - "function_types" - "fusion" - "endian" - "phoenix" - "pool" - "proto" - "thread" - "dynamic_bitset" - "mp11" - "atomic" - "chrono" - "align" - "ratio" - "rational" -) +if(NOT TARGET Boost::boost) + add_library(Boost::boost INTERFACE IMPORTED) + foreach(lib ${libraries}) + get_target_property(_include ${lib} INTERFACE_INCLUDE_DIRECTORIES) + list(APPEND includes ${_include}) + endforeach() + set_target_properties(Boost::boost PROPERTIES + INTERFACE_LINK_LIBRARIES ${libraries} + INTERFACE_INCLUDE_DIRECTORIES ${includes} + ) +endif() -# see boost/tools/boost_install/BoostConfig.cmake -foreach(comp ${BOOST_INSTALLED_LIBRARIES}) - LIST(APPEND Boost_LIBRARIES Boost::${comp}) -endforeach() +set(Boost_LIBRARIES Boost::boost) # for librime-charcode set(Boost_LOCALE_LIBRARIES Boost::locale) diff --git a/app/src/main/jni/cmake/RimePlugins.cmake b/app/src/main/jni/cmake/RimePlugins.cmake index e2235ae2ab..89ac15915a 100644 --- a/app/src/main/jni/cmake/RimePlugins.cmake +++ b/app/src/main/jni/cmake/RimePlugins.cmake @@ -7,13 +7,11 @@ set(RIME_PLUGINS ) # plugins didn't use target_link_libraries, the usage-requirements won't work, include manually -set(PLUGIN_INCLUDES "") find_package(Boost) -foreach(boost_lib ${Boost_LIBRARIES}) - unset(includes) - get_target_property(includes ${boost_lib} INTERFACE_INCLUDE_DIRECTORIES) - list(APPEND PLUGIN_INCLUDES ${includes}) -endforeach() +get_target_property(PLUGIN_INCLUDES + ${Boost_LIBRARIES} + INTERFACE_INCLUDE_DIRECTORIES +) include_directories(${PLUGIN_INCLUDES}) # move plugins @@ -39,5 +37,3 @@ execute_process(COMMAND ln -s # librime-charcode option(BUILD_WITH_ICU "" OFF) -# TODO: replace with TOUCH after cmake >= 3.12 -file(WRITE "${CMAKE_BINARY_DIR}/include/boost/asio.hpp" "")