How to use FindICU, tell it where to search?

I’m trying to link my C++ project with ICU. I found this documentation: FindICU.

I used brew to install icu4c on my macOS system. It put it in /usr/local/opt/icu4c.

In my CMakeLists.txt, I try:

set(ICU_DEBUG ON)
# set(ICU_ROOT /usr/local/opt/icu4c)
include(FindICU)

And it can’t find it. How do I tell it where to look? I thought maybe setting that ICU_ROOT variable would help, but it didn’t.

To load a module, use the find_package command:

set(ICU_DEBUG ON)
find_package(ICU)

Okay, I tried:

set(ICU_DEBUG ON)
set(ICU_ROOT /usr/local/opt/icu4c) # also tried without this
find_package(ICU)

And it still seems confused. How do I point it at the include and lib dirs under /usr/local/opt/icu4c, that brew installed? It prints:

-- --------FindICU.cmake results debug--------
-- ICU found: FALSE
-- ICU_VERSION number: 70.1
-- ICU_ROOT directory: /usr/local/opt/icu4c
-- ICU_INCLUDE_DIR directory: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include
-- ICU_LIBRARIES: 
-- gencnval program: ICU_GENCNVAL_EXECUTABLE=/usr/local/opt/icu4c/bin/gencnval
...

From your log, I think you re-launch the configuration step without cleaning up the environment which explain why you have artifacts from different installations (i.e. native one + brew). At least remove CMakeCache.txt file or, if you have version 3.24, you can use the --fresh option.

Now, on macOS, it seems not all components are installed (i.e. component lx seems missing), so the ICU is not fully founded. Try a query with an explicit list of components:

set(ICU_DEBUG ON)
set(ICU_ROOT /usr/local/opt/icu4c)
find_package(ICU COMPONENTS data)

Thanks! Naming the specific components makes the difference. - find_package(ICU COMPONENTS data ...)