From 5bd4b60492ddbf4cb785c62b8ba9f1a245d39d3c 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 | 9 +++------ app/src/main/jni/cmake/FindGlog.cmake | 2 ++ app/src/main/jni/cmake/FindYamlCpp.cmake | 2 +- app/src/main/jni/cmake/OpenccWorkarounds.cmake | 13 +++++-------- 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..ba2e4f08ab 100644 --- a/app/src/main/jni/CMakeLists.txt +++ b/app/src/main/jni/CMakeLists.txt @@ -57,13 +57,10 @@ 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" -) +set(X11Keysym "${CMAKE +_SOURCE_DIR}/librime/include") +option(BUILD_TEST "" OFF) 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..5a62e27d12 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) 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..8580064f09 100644 --- a/app/src/main/jni/cmake/OpenccWorkarounds.cmake +++ b/app/src/main/jni/cmake/OpenccWorkarounds.cmake @@ -1,10 +1,7 @@ -# 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(