mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
- 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).
41 lines
1.5 KiB
CMake
41 lines
1.5 KiB
CMake
# Find libicu's libraries
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
find_package(PkgConfig)
|
|
|
|
set(ICU_REQUIRED)
|
|
foreach(MODULE ${ICU_FIND_COMPONENTS})
|
|
string(TOUPPER "${MODULE}" MODULE)
|
|
string(TOLOWER "${MODULE}" module)
|
|
list(APPEND ICU_REQUIRED
|
|
ICU_${MODULE}_INCLUDE_DIRS ICU_${MODULE}_LIBRARIES)
|
|
|
|
pkg_check_modules(PC_ICU_${MODULE} QUIET icu-${module})
|
|
if(NOT PKG_CONFIG_FOUND)
|
|
# PkgConfig doesn't exist on this system, so we manually provide hints via CMake.
|
|
set(PC_ICU_${MODULE}_INCLUDE_DIRS "${ICU_${MODULE}_INCLUDE_DIRS}")
|
|
set(PC_ICU_${MODULE}_LIBRARY_DIRS "${ICU_${MODULE}_LIBRARY_DIRS}")
|
|
endif()
|
|
|
|
find_path(ICU_${MODULE}_INCLUDE_DIRS unicode
|
|
HINTS ${PC_ICU_${MODULE}_INCLUDE_DIRS})
|
|
find_library(ICU_${MODULE}_LIBRARIES NAMES icu${module} ${ICU_${MODULE}_LIB_NAME}
|
|
HINTS ${PC_ICU_${MODULE}_LIBRARY_DIRS})
|
|
endforeach()
|
|
|
|
foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS;HAIKU)
|
|
foreach(MODULE ${ICU_FIND_COMPONENTS})
|
|
string(TOUPPER "${MODULE}" MODULE)
|
|
if("${SWIFT_${sdk}_${SWIFT_HOST_VARIANT_ARCH}_ICU_${MODULE}_INCLUDE}" STREQUAL "")
|
|
set(SWIFT_${sdk}_${SWIFT_HOST_VARIANT_ARCH}_ICU_${MODULE}_INCLUDE ${ICU_${MODULE}_INCLUDE_DIRS} CACHE STRING "" FORCE)
|
|
endif()
|
|
if("${SWIFT_${sdk}_${SWIFT_HOST_VARIANT_ARCH}_ICU_${MODULE}}" STREQUAL "")
|
|
set(SWIFT_${sdk}_${SWIFT_HOST_VARIANT_ARCH}_ICU_${MODULE} ${ICU_${MODULE}_LIBRARIES} CACHE STRING "" FORCE)
|
|
endif()
|
|
endforeach()
|
|
endforeach()
|
|
|
|
find_package_handle_standard_args(ICU DEFAULT_MSG ${ICU_REQUIRED})
|
|
mark_as_advanced(${ICU_REQUIRED})
|