Reputation: 446
I'm working on Flutter plugin that depends on ICU package. Currently I'm stuck with linking ICU libraries to my project using cmake
. Though I've tried to pass an actual path to icu4c
dir in different ways, cmake
is persistently referring to those parts of ICU package that are bundled with my current Android NDK.
My CMakeLists.txt is the following:
cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0074 NEW)
project(uuid_library VERSION 0.0.1 LANGUAGES C)
add_library(uuid SHARED
"uuid.c"
)
set_target_properties(uuid PROPERTIES
OUTPUT_NAME "uuid"
)
set(CMAKE_PREFIX_PATH "/usr/local/opt/icu4c")
set(ICU_ROOT "/usr/local/opt/icu4c")
set(ICU_DEBUG ON)
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
message(STATUS "ICU_ROOT: ${ICU_ROOT}")
find_package(ICU COMPONENTS i18n uc)
message(STATUS "ICU_FOUND: ${ICU_FOUND}")
message(STATUS "ICU_INCLUDE_DIRS: ${ICU_INCLUDE_DIRS}")
message(STATUS "ICU_LIBRARIES: ${ICU_LIBRARIES}")
if (ICU_FOUND)
include_directories(${ICU_INCLUDE_DIRS})
target_link_libraries(uuid PRIVATE ICU::i18n ICU::uc)
else()
message(FATAL_ERROR "ICU libraries not found")
endif()
target_compile_definitions(uuid PUBLIC DART_SHARED_LIB)
if (ANDROID)
# Support Android 15 16k page size.
target_link_options(uuid PRIVATE "-Wl,-z,max-page-size=16384")
endif()
Now I get the following error while trying to build example project depending on my plugin:
Launching lib/main.dart on sdk gphone x86 64 in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':uuid:configureCMakeDebug[arm64-v8a]'.
> [CXX1429] error when building with cmake using /<path-to-my-project>/src/CMakeLists.txt: -- The C compiler identification is Clang 14.0.6
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Users/<user-name>/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- CMAKE_PREFIX_PATH: /usr/local/opt/icu4c
-- ICU_ROOT: /usr/local/opt/icu4c
-- Found the following ICU libraries:
-- i18n (required)
-- uc (required)
-- --------FindICU.cmake search debug--------
-- ICU binary path search order: /usr/local/opt/icu4c
-- ICU include path search order: /usr/local/opt/icu4c
-- ICU library path search order: /usr/local/opt/icu4c
-- ----------------
-- Failed to find all ICU components (missing: ICU_LIBRARY) (found version "71.1")
-- --------FindICU.cmake results debug--------
-- ICU found: FALSE
-- ICU_VERSION number: 71.1
-- ICU_ROOT directory: /usr/local/opt/icu4c
-- ICU_INCLUDE_DIR directory: /Users/<user-name>/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include
-- ICU_LIBRARIES:
-- gencnval program: ICU_GENCNVAL_EXECUTABLE=/usr/local/opt/icu4c/bin/gencnval
-- icuinfo program: ICU_ICUINFO_EXECUTABLE=/usr/local/opt/icu4c/bin/icuinfo
-- genbrk program: ICU_GENBRK_EXECUTABLE=/usr/local/opt/icu4c/bin/genbrk
-- icu-config program: ICU_ICU-CONFIG_EXECUTABLE=/usr/local/opt/icu4c/bin/icu-config
-- genrb program: ICU_GENRB_EXECUTABLE=/usr/local/opt/icu4c/bin/genrb
-- gendict program: ICU_GENDICT_EXECUTABLE=/usr/local/opt/icu4c/bin/gendict
-- derb program: ICU_DERB_EXECUTABLE=/usr/local/opt/icu4c/bin/derb
-- pkgdata program: ICU_PKGDATA_EXECUTABLE=/usr/local/opt/icu4c/bin/pkgdata
-- uconv program: ICU_UCONV_EXECUTABLE=/usr/local/opt/icu4c/bin/uconv
-- gencfu program: ICU_GENCFU_EXECUTABLE=/usr/local/opt/icu4c/bin/gencfu
-- makeconv program: ICU_MAKECONV_EXECUTABLE=/usr/local/opt/icu4c/bin/makeconv
-- gennorm2 program: ICU_GENNORM2_EXECUTABLE=/usr/local/opt/icu4c/sbin/gennorm2
-- genccode program: ICU_GENCCODE_EXECUTABLE=/usr/local/opt/icu4c/sbin/genccode
-- gensprep program: ICU_GENSPREP_EXECUTABLE=/usr/local/opt/icu4c/sbin/gensprep
-- icupkg program: ICU_ICUPKG_EXECUTABLE=/usr/local/opt/icu4c/sbin/icupkg
-- gencmn program: ICU_GENCMN_EXECUTABLE=/usr/local/opt/icu4c/sbin/gencmn
-- Makefile.inc data: ICU_MAKEFILE_INC=ICU_MAKEFILE_INC-NOTFOUND
-- pkgdata.inc data: ICU_PKGDATA_INC=ICU_PKGDATA_INC-NOTFOUND
-- i18n library found: ICU_I18N_FOUND=
-- i18n library found (compat name): I18N_FOUND=
-- i18n library: ICU_I18N_LIBRARIES=
-- uc library found: ICU_UC_FOUND=
-- uc library found (compat name): UC_FOUND=
-- uc library: ICU_UC_LIBRARIES=
-- ----------------
-- ICU_FOUND: FALSE
-- ICU_INCLUDE_DIRS:
-- ICU_LIBRARIES:
-- Configuring incomplete, errors occurred!
See also "/<path-to-my-project>/android/.cxx/Debug/2k402641/arm64-v8a/CMakeFiles/CMakeOutput.log".
C++ build system [configure] failed while executing:
/Users/<user-name>/Library/Android/sdk/cmake/3.22.1/bin/cmake \
-H/<path-to-my-project>/src \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_SYSTEM_VERSION=21 \
-DANDROID_PLATFORM=android-21 \
-DANDROID_ABI=arm64-v8a \
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
-DANDROID_NDK=/Users/<user-name>/Library/Android/sdk/ndk/25.1.8937393 \
-DCMAKE_ANDROID_NDK=/Users/<user-name>/Library/Android/sdk/ndk/25.1.8937393 \
-DCMAKE_TOOLCHAIN_FILE=/Users/<user-name>/Library/Android/sdk/ndk/25.1.8937393/build/cmake/android.toolchain.cmake \
-DCMAKE_MAKE_PROGRAM=/Users/<user-name>/Library/Android/sdk/cmake/3.22.1/bin/ninja \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/<path-to-my-project>/example/build/uuid/intermediates/cxx/Debug/2k402641/obj/arm64-v8a \
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=/<path-to-my-project>/example/build/uuid/intermediates/cxx/Debug/2k402641/obj/arm64-v8a \
-DCMAKE_BUILD_TYPE=Debug \
-B/<path-to-my-project>/android/.cxx/Debug/2k402641/arm64-v8a \
-GNinja
from /<path-to-my-project>/android
CMake Error at CMakeLists.txt:38 (message):
ICU libraries not found
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
Error: Gradle task assembleDebug failed with exit code 1
As you can see from the FindICU's debug output, though both CMAKE_PREFIX_PATH
and ICU_ROOT
are actually set to a proper value /usr/local/opt/icu4c, ICU_INCLUDE_DIR
still refers to the include dir inside the NDK toolchain. How can I force find_package()
or find_library()
functions to link the right ICU package?
Upvotes: 1
Views: 26