Skip to content

Commit 4b9a1b5

Browse files
committed
[cmake] Clean up FindICU.cmake
- Get rid of the singular (*_INCLUDE_DIR and *_LIBRARY) variables and standardize on the plural ones, since that's also what's used by CMake's FindICU module (which was added in 3.7). - Use PKG_CONFIG_FOUND instead of PKGCONFIG_FOUND, since that's what's documented in CMake's FindPkgConfig module. (The latter will be set by the find_package call, so it's not incorrect, but it's clearer to use the documented variable.) - Search for the headers and libraries even if pkg-config can't find the module, since e.g. we might have ICU somewhere in our CMake search path but might not have the pkg-config module for it. We're only using the pkg-config results as search hints anyway. (This might result in an empty HINTS argument to find_path and find_library, but CMake seems to handle that fine.) *This should be the only functional change.* - Remove ICU_${MODULE}_DEFINITIONS, since it's never used anywhere. - Don't add the *_INCLUDEDIR and *_LIBDIR variables to the hints, since they should be the same as the corresponding *_INCLUDE_DIRS and *_LIBRARY_DIRS variables (since we're only searching for a single module). The only intended functional change, as mentioned above, is that we can now successfully find ICU if its include and library directories are in the CMake search path but its pkg-config module isn't, which might be the case in certain cross-compilation or hermetic build scenarios. (It's compounded by CMake only looking for pkg-config modules in CMAKE_PREFIX_PATH and not CMAKE_SYSTEM_PREFIX_PATH, which I asked about in https://cmake.org/pipermail/cmake/2018-August/068109.html).
1 parent 42785be commit 4b9a1b5

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

cmake/modules/FindICU.cmake

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,19 @@ foreach(MODULE ${ICU_FIND_COMPONENTS})
99
string(TOUPPER "${MODULE}" MODULE)
1010
string(TOLOWER "${MODULE}" module)
1111
list(APPEND ICU_REQUIRED
12-
ICU_${MODULE}_INCLUDE_DIR ICU_${MODULE}_LIBRARIES)
12+
ICU_${MODULE}_INCLUDE_DIRS ICU_${MODULE}_LIBRARIES)
1313

1414
pkg_check_modules(PC_ICU_${MODULE} QUIET icu-${module})
15-
if(NOT ${PKGCONFIG_FOUND})
15+
if(NOT PKG_CONFIG_FOUND)
1616
# PkgConfig doesn't exist on this system, so we manually provide hints via CMake.
1717
set(PC_ICU_${MODULE}_INCLUDE_DIRS "${ICU_${MODULE}_INCLUDE_DIRS}")
1818
set(PC_ICU_${MODULE}_LIBRARY_DIRS "${ICU_${MODULE}_LIBRARY_DIRS}")
1919
endif()
2020

21-
if((${PC_ICU_${MODULE}_FOUND}) OR (NOT ${PKGCONFIG_FOUND}))
22-
set(ICU_${MODULE}_DEFINITIONS ${PC_ICU_${MODULE}_CFLAGS_OTHER})
23-
24-
find_path(ICU_${MODULE}_INCLUDE_DIR unicode
25-
HINTS ${PC_ICU_${MODULE}_INCLUDEDIR} ${PC_ICU_${MODULE}_INCLUDE_DIRS})
26-
set(ICU_${MODULE}_INCLUDE_DIRS ${ICU_${MODULE}_INCLUDE_DIR})
27-
28-
find_library(ICU_${MODULE}_LIBRARY NAMES icu${module} ${ICU_${MODULE}_LIB_NAME}
29-
HINTS ${PC_ICU_${MODULE}_LIBDIR} ${PC_ICU_${MODULE}_LIBRARY_DIRS})
30-
set(ICU_${MODULE}_LIBRARIES ${ICU_${MODULE}_LIBRARY})
31-
endif()
21+
find_path(ICU_${MODULE}_INCLUDE_DIRS unicode
22+
HINTS ${PC_ICU_${MODULE}_INCLUDE_DIRS})
23+
find_library(ICU_${MODULE}_LIBRARIES NAMES icu${module} ${ICU_${MODULE}_LIB_NAME}
24+
HINTS ${PC_ICU_${MODULE}_LIBRARY_DIRS})
3225
endforeach()
3326

3427
foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS;HAIKU)
@@ -38,7 +31,7 @@ foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS;HAIKU)
3831
set(SWIFT_${sdk}_${SWIFT_HOST_VARIANT_ARCH}_ICU_${MODULE}_INCLUDE ${ICU_${MODULE}_INCLUDE_DIRS} CACHE STRING "" FORCE)
3932
endif()
4033
if("${SWIFT_${sdk}_${SWIFT_HOST_VARIANT_ARCH}_ICU_${MODULE}}" STREQUAL "")
41-
set(SWIFT_${sdk}_${SWIFT_HOST_VARIANT_ARCH}_ICU_${MODULE} ${ICU_${MODULE}_LIBRARY} CACHE STRING "" FORCE)
34+
set(SWIFT_${sdk}_${SWIFT_HOST_VARIANT_ARCH}_ICU_${MODULE} ${ICU_${MODULE}_LIBRARIES} CACHE STRING "" FORCE)
4235
endif()
4336
endforeach()
4437
endforeach()

lib/Driver/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ if(SWIFT_BUILD_STATIC_STDLIB)
3333
else()
3434
set(ICU_STATICLIB "FALSE")
3535
find_package(ICU REQUIRED COMPONENTS uc i18n)
36-
get_filename_component(ICU_UC_LIBDIR "${ICU_UC_LIBRARY}" DIRECTORY)
37-
get_filename_component(ICU_I18N_LIBDIR "${ICU_I18N_LIBRARY}" DIRECTORY)
36+
get_filename_component(ICU_UC_LIBDIR "${ICU_UC_LIBRARIES}" DIRECTORY)
37+
get_filename_component(ICU_I18N_LIBDIR "${ICU_I18N_LIBRARIES}" DIRECTORY)
3838
endif()
3939
set(linkfile "${lowercase_sdk}/static-stdlib-args.lnk")
4040
add_custom_command_target(swift_static_stdlib_${sdk}_args

0 commit comments

Comments
 (0)