From f87d15e9e6213dc3e85dc488a95244291101b9f6 Mon Sep 17 00:00:00 2001 From: WhiredPlanck Date: Mon, 13 Nov 2023 23:50:20 +0800 Subject: [PATCH] build(jni): more neat way to find headers --- app/src/main/jni/CMakeLists.txt | 8 ++------ app/src/main/jni/cmake/FindGlog.cmake | 2 ++ app/src/main/jni/cmake/FindYamlCpp.cmake | 2 +- app/src/main/jni/cmake/OpenccWorkarounds.cmake | 14 ++++++-------- app/src/main/jni/librime_jni/CMakeLists.txt | 4 ++-- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/app/src/main/jni/CMakeLists.txt b/app/src/main/jni/CMakeLists.txt index b84a05d99e..e0c7086a2c 100644 --- a/app/src/main/jni/CMakeLists.txt +++ b/app/src/main/jni/CMakeLists.txt @@ -7,6 +7,8 @@ set(CMAKE_CXX_STANDARD 14) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) +set(CMAKE_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/librime/include") + # general options option(BUILD_SHARED_LIBS "" OFF) option(BUILD_TESTING "" OFF) @@ -58,12 +60,6 @@ include(OpenccWorkarounds) include(RimePlugins) option(BUILD_TEST "" OFF) -include_directories( - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/librime/include" - PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/librime/deps/glog" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/librime/deps/glog/src" -) - add_subdirectory(librime) add_subdirectory(librime_jni) diff --git a/app/src/main/jni/cmake/FindGlog.cmake b/app/src/main/jni/cmake/FindGlog.cmake index f3a16b2796..03730793b2 100644 --- a/app/src/main/jni/cmake/FindGlog.cmake +++ b/app/src/main/jni/cmake/FindGlog.cmake @@ -1,2 +1,4 @@ set(Glog_FOUND TRUE) set(Glog_LIBRARY glog) +get_target_property(Glog_INCLUDE_PATH glog::glog + INTERFACE_INCLUDE_DIRECTORIES) \ No newline at end of file diff --git a/app/src/main/jni/cmake/FindYamlCpp.cmake b/app/src/main/jni/cmake/FindYamlCpp.cmake index 13cea6eead..2a4dbb40f5 100644 --- a/app/src/main/jni/cmake/FindYamlCpp.cmake +++ b/app/src/main/jni/cmake/FindYamlCpp.cmake @@ -1,2 +1,2 @@ -set(YamlCpp_FOUNT TRUE) +set(YamlCpp_FOUND TRUE) set(YamlCpp_LIBRARY yaml-cpp) diff --git a/app/src/main/jni/cmake/OpenccWorkarounds.cmake b/app/src/main/jni/cmake/OpenccWorkarounds.cmake index 6a4e3ead36..4f65337e3a 100644 --- a/app/src/main/jni/cmake/OpenccWorkarounds.cmake +++ b/app/src/main/jni/cmake/OpenccWorkarounds.cmake @@ -1,10 +1,8 @@ -# install opencc headers manually +# Since OpenCC doesn't include its headers in the binary dir, +# we need to install them manually. file(GLOB LIBOPENCC_HEADERS - OpenCC/src/*.hpp - OpenCC/src/*.h - "${CMAKE_BINARY_DIR}/OpenCC/src/opencc_config.h" + OpenCC/src/*.hpp + "${CMAKE_BINARY_DIR}/OpenCC/src/opencc_config.h" ) -make_directory("${CMAKE_BINARY_DIR}/include/opencc") -foreach(header ${LIBOPENCC_HEADERS}) - configure_file(${header} "${CMAKE_BINARY_DIR}/include/opencc" COPYONLY) -endforeach() +file(COPY ${LIBOPENCC_HEADERS} DESTINATION "${CMAKE_BINARY_DIR}/include/opencc") + diff --git a/app/src/main/jni/librime_jni/CMakeLists.txt b/app/src/main/jni/librime_jni/CMakeLists.txt index 709a3f4fe2..8ae9a91306 100644 --- a/app/src/main/jni/librime_jni/CMakeLists.txt +++ b/app/src/main/jni/librime_jni/CMakeLists.txt @@ -1,17 +1,17 @@ find_package(Opencc REQUIRED) -file(GLOB RIME_JNI_SOURCES +set(RIME_JNI_SOURCES key_table.cc levers.cc opencc.cc rime_jni.cc ) add_library(rime_jni SHARED ${RIME_JNI_SOURCES}) +target_link_libraries(rime_jni log rime-static ${Opencc_LIBRARY}) target_include_directories(rime_jni PRIVATE "${CMAKE_SOURCE_DIR}/librime/src" "${Opencc_INCLUDE_PATH}" ) -target_link_libraries(rime_jni rime-static log ${Opencc_LIBRARY}) string(TIMESTAMP TODAY "%Y%m%d") execute_process(