From 7328855cedd645c7705f4c6aea8eee17b7533296 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 5 Jan 2020 22:09:57 -0800 Subject: [PATCH] build: cleanup some of the link rules Many of the options were in place due to the legacy build. Linking against the imported libraries will both link and include the paths. Furthermore, now with proper Swift support, it is possible to have the library linking be computed transitively. Avoid the double dependency checking. Although libdispatch is also used by Foundation, allow the autolinking to take care of that for the Foundation library as we do not explicitly link against dispatch anywhere. --- CMakeLists.txt | 9 - CoreFoundation/CMakeLists.txt | 24 +- CoreFoundation/cmake/modules/FindICU.cmake | 251 --------------------- Foundation/CMakeLists.txt | 7 - 4 files changed, 14 insertions(+), 277 deletions(-) delete mode 100644 CoreFoundation/cmake/modules/FindICU.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d5d68f9833..7bfda92134 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,15 +26,6 @@ endif() option(BUILD_SHARED_LIBS "build shared libraries" ON) -find_package(CURL CONFIG) -if(CURL_FOUND) - include(CMakeExpandImportedTargets) - cmake_expand_imported_targets(CURL_LIBRARIES LIBRARIES CURL::libcurl) -else() - find_package(CURL REQUIRED) -endif() -find_package(ICU COMPONENTS uc i18n REQUIRED) -find_package(LibXml2 REQUIRED) find_package(dispatch CONFIG REQUIRED) include(SwiftSupport) diff --git a/CoreFoundation/CMakeLists.txt b/CoreFoundation/CMakeLists.txt index 90a777234e..ef022c1296 100644 --- a/CoreFoundation/CMakeLists.txt +++ b/CoreFoundation/CMakeLists.txt @@ -379,8 +379,7 @@ target_compile_definitions(CoreFoundation $<$:CF_CHARACTERSET_UNICODE_DATA_L="CharacterSets/CFUnicodeData-L.mapping">) target_include_directories(CoreFoundation PRIVATE - ${PROJECT_SOURCE_DIR} - ${ICU_INCLUDE_DIR}) + ${PROJECT_SOURCE_DIR}) target_link_libraries(CoreFoundation PRIVATE Threads::Threads ${CMAKE_DL_LIBS} @@ -390,6 +389,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL Android) target_link_libraries(CoreFoundation PRIVATE log) endif() +if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) + target_link_libraries(CoreFoundation PRIVATE + ICU::uc + ICU::i18n) +endif() add_framework(CFURLSessionInterface ${FRAMEWORK_LIBRARY_TYPE} @@ -409,10 +413,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows) PRIVATE CURL_STATICLIB) endif() -target_include_directories(CFURLSessionInterface PRIVATE - ${CURL_INCLUDE_DIRS}) -target_link_libraries(CFURLSessionInterface PRIVATE - ${CURL_LIBRARIES}) +if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) + target_link_libraries(CFURLSessionInterface PRIVATE + CURL::libcurl) +endif() add_framework(CFXMLInterface ${FRAMEWORK_LIBRARY_TYPE} @@ -427,10 +431,10 @@ add_framework(CFXMLInterface SOURCES Parsing.subproj/CFXMLInterface.c) add_dependencies(CFXMLInterface CoreFoundation) -target_include_directories(CFXMLInterface PRIVATE - ${LIBXML2_INCLUDE_DIR}) -target_link_libraries(CFXMLInterface PRIVATE - ${LIBXML2_LIBRARIES}) +if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) + target_link_libraries(CFXMLInterface PRIVATE + LibXml2::LibXml2) +endif() if(CMAKE_SYSTEM_NAME STREQUAL Windows) add_library(CoreFoundationResources OBJECT diff --git a/CoreFoundation/cmake/modules/FindICU.cmake b/CoreFoundation/cmake/modules/FindICU.cmake deleted file mode 100644 index 448414febf..0000000000 --- a/CoreFoundation/cmake/modules/FindICU.cmake +++ /dev/null @@ -1,251 +0,0 @@ -# Find libicu's libraries - -function(_icu_find) - set(icu_programs - gencnval icuinfo genbrk icu-config genrb gendict derb pkgdata uconv gencfu - makeconf gennorm2 genccode gensprep icupkg gencmn) - set(icu_data - Makefile.inc pkgdata.inc) - - # Set up search paths, taking compiler into account. Search ICU_ROOT, with - # ICU_ROOT in the environment as a fallback if unset. - if(ICU_ROOT) - list(APPEND icu_roots ${ICU_ROOT}) - else() - if(NOT "$ENV{ICU_ROOT}" STREQUAL "") - file(TO_CMAKE_PATH "$ENV{ICU_ROOT}" NATIVE_PATH) - set(ICU_ROOT "${NATIVE_PATH}" CACHE PATH - "Location of the ICU installation" FORCE) - list(APPEND icu_roots ${NATIVE_PATH}) - endif() - endif() - - # Find the include directory. - list(APPEND icu_include_suffixes "include") - find_path(ICU_INCLUDE_DIR - NAMES "unicode/utypes.h" - HINTS ${icu_roots} - PATh_SUFFIXES ${icu_include_suffixes} - DOC "ICU include directory") - set(ICU_INCLUDE_DIR "${ICU_INCLUDE_DIR}" PARENT_SCOPE) - - # Get the version. - if(ICU_INCLUDE_DIR AND EXISTS "${ICU_INCLUDE_DIR}/unicode/uvernum.h") - file(STRINGS "${ICU_INCLUDE_DIR}/unicode/uvernum.h" icu_header_str - REGEX "^#define[\t ]+U_ICU_VERSION[\t ]+\".*\".*") - - string(REGEX REPLACE "^#define[\t ]+U_ICU_VERSION[\t ]+\"([^ \\n]*)\".*" - "\\1" icu_version_string "${icu_header_str}") - set(ICU_VERSION "${icu_version_string}" PARENT_SCOPE) - - unset(icu_header_str) - unset(icu_version_string) - endif() - - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(_bin64 "bin64") - set(_lib64 "lib64") - endif() - - # Find all ICU programs. - list(APPEND icu_binary_suffixes "${_bin64}" "bin" "sbin") - foreach(program ${icu_programs}) - string(TOUPPER ${program} program_upcase) - set(cache_var "ICU_${program_upcase}_EXECUTABLE") - find_program(${cache_var} ${program} - HINTS ${icu_roots} - PATH_SUFFIXES ${icu_binary_suffixes} - DOC "ICU ${program} executable") - mark_as_advanced(cache_var) - set(${cache_var} "${${cache_var}}" PARENT_SCOPE) - endforeach() - - set(static_prefix ) - if(MSVC) - set(static_prefix "s") - endif() - - # Find all ICU libraries. - list(APPEND icu_library_suffixes "${_lib64}" "lib") - set(ICU_REQUIRED_LIBS_FOUND YES) - foreach(component ${ICU_FIND_COMPONENTS}) - string(TOUPPER ${component} component_upcase) - - set(component_cache "ICU_${component_upcase}_LIBRARY") - set(component_cache_release "${component_cache}_RELEASE") - set(component_cache_debug "${component_cache}_DEBUG") - set(component_found "${component_cache}_FOUND") - - list(APPEND component_libnames "icu${component}") - list(APPEND component_debug_libnames "icu${component}d") - if(component STREQUAL data) - list(APPEND component_libnames icudt) - list(APPEND component_debug_libnames icudtd) - elseif(component STREQUAL dt) - list(APPEND component_libnames icudata) - list(APPEND component_debug_libnames icudatad) - elseif(component STREQUAL i18n) - list(APPEND component_libnames icuin) - list(APPEND component_debug_libnames icuind) - elseif(component STREQUAL in) - list(APPEND component_libnames icui18n) - list(APPEND component_debug_libnames icui18nd) - endif() - - if(static_prefix) - unset(static_component_libnames) - foreach(component_libname ${component_libnames}) - list(APPEND static_component_libnames - ${static_prefix}${component_libname}) - endforeach() - list(APPEND component_libnames ${static_component_libnames}) - - unset(static_component_debug_libnames) - foreach(component_libname ${component_debug_libnames}) - list(APPEND static_component_debug_libnames - ${static_prefix}${component_libname}) - endforeach() - list(APPEND component_debug_libnames ${static_component_debug_libnames}) - endif() - - find_library(${component_cache_release} ${component_libnames} - HINTS ${icu_roots} - PATH_SUFFIXES ${icu_library_suffixes} - DOC "ICU ${component} library (release)") - find_library(${component_cache_debug} ${component_debug_libnames} - HINTS ${icu_roots} - PATH_SUFFIXES ${icu_library_suffixes} - DOC "ICU ${component} library (debug)") - - include(SelectLibraryConfigurations) - select_library_configurations(ICU_${component_upcase}) - mark_as_advanced(${component_cache_release} ${component_cache_debug}) - - if(${component_cache}) - set(${component_found} YES) - list(APPEND ICU_LIBRARY ${${component_cache}}) - endif() - mark_as_advanced(${component_found}) - - set(${component_cache} "${${component_cache}}" PARENT_SCOPE) - set(${component_found} "${${component_found}}" PARENT_SCOPE) - if(${component_found}) - if(ICU_FIND_REQUIRED_${component}) - list(APPEND ICU_LIBS_FOUND "${component} (required)") - else() - list(APPEND ICU_LIBS_FOUND "${component} (optional)") - endif() - else() - if(ICU_FIND_REQUIRED_${component}) - list(APPEND ICU_LIBS_NOTFOUND "${component} (required)") - else() - list(APPEND ICU_LIBS_NOTFOUND "${component} (optional)") - endif() - endif() - - set(_ICU_REQUIRED_LIBS_FOUND "${ICU_REQUIRED_LIBS_FOUND}" PARENT_SCOPE) - set(ICU_LIBRARY "${ICU_LIBRARY}" PARENT_SCOPE) - endforeach() - - if(CMAKE_LIBRARY_ARCHITECTURE) - list(APPEND icu_data_suffixes - "${_lib64}/${CMAKE_LIBRARY_ARCHITECTURE}/icu/${ICU_VERSION}" - "lib/${CMAKE_LIBRARY_ARCHITECTURE}/icu/${ICU_VERSION}" - "${_lib64}/${CMAKE_LIBRARY_ARCHITECTURE}/icu" - "lib/${CMAKE_LIBRARY_ARCHITECTURE}/icu") - endif() - list(APPEND icu_data_suffixes - "${_lib64}/icu/${ICU_VERSION}" - "lib/icu/${ICU_VERSION}" - "${_lib64}/icu" - "lib/icu") - foreach(data ${icu_data}) - string(TOUPPER ${data} data_upcase) - STRING(REPLACE "." "_" data_upcase ${data_upcase}) - - set(cache_var ICU_${data_upcase}) - find_file(${cache_Var} ${data} - HINTS ${icu_roots} - PATH_SUFFIXES ${icu_data_suffixes} - DOC "ICU ${data} data file") - mark_as_advanced(cache_var) - set(${cache_var} "${${cache_var}}" PARENT_SCOPE) - endforeach() -endfunction() - -_icu_find() -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(ICU - FOUND_VAR - ICU_FOUND - REQUIRED_VARS - ICU_INCLUDE_DIR - ICU_LIBRARY - _ICU_REQUIRED_LIBS_FOUND - VERSION_VAR - ICU_VERSION - FAIL_MESSAGE - "Failed to find all ICU components") -unset(_ICU_REQUIRED_LIBS_FOUND) - -if(ICU_FOUND) - set(ICU_INCLUDE_DIRS "${ICU_INCLUDE_DIR}") - set(ICU_LIBRARIES "${ICU_LIBRARY}") - foreach(_ICU_component ${ICU_FIND_COMPONENTS}) - string(TOUPPER ${_ICU_component} _ICU_component_upcase) - - set(_ICU_component_cache "ICU_${_ICU_component_upcase}_LIBRARY") - set(_ICU_component_cache_release "ICU_${_ICU_component_upcase}_LIBRARY_RELEASE") - set(_ICU_component_cache_debug "ICU_${_ICU_component_upcase}_LIBRARY_DEBUG") - set(_ICU_component_lib "ICU_${_ICU_component_upcase}_LIBRARIES") - set(_ICU_component_found "${_ICU_component_upcase}_FOUND") - set(_ICU_imported_target "ICU::${_ICU_component}") - - if(${_ICU_component_found}) - set(${_ICU_component_lib} "${${_ICU_component_cache}}") - if(NOT TARGET ${_ICU_imported_target}) - add_library(${_ICU_imported_target} UNKNOWN IMPORTED) - if(ICU_INCLUDE_DIR) - set_target_properties(${_ICU_imported_target} PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES - ${ICU_INCLUDE_DIR}) - endif() - if(EXISTS ${${_ICU_component_cache}}) - set_target_properties(${_ICU_imported_target} PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES - CXX - IMPORTED_LOCATION - ${${_ICU_component_cache}}) - endif() - if(EXISTS ${${_ICU_component_cache_release}}) - set_property(TARGET ${_ICU_imported_target} APPEND PROPERTY - IMPORTED_CONFIGURATIONS - RELEASE) - set_target_properties(${_ICU_imported_target} PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE - CXX - IMPORTED_LOCATION_RELEASE - ${${_ICU_component_cache_release}}) - endif() - if(EXISTS ${${_ICU_component_cache_debug}}) - set_property(TARGET ${_ICU_imported_target} APPEND PROPERTY - IMPORTED_CONFIGURATIONS - DEBUG) - set_target_properties(${_ICU_imported_target} PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG - CXX - IMPORTED_LOCATION_DEBUG - ${${_ICU_component_cache_debug}}) - endif() - endif() - endif() - - unset(_ICU_imported_target) - unset(_ICU_component_found) - unset(_ICU_component_lib) - unset(_ICU_component_cache_debug) - unset(_ICU_component_cache_release) - unset(_ICU_component_cache) - endforeach() -endif() - diff --git a/Foundation/CMakeLists.txt b/Foundation/CMakeLists.txt index cf80e7dde9..82208bb925 100644 --- a/Foundation/CMakeLists.txt +++ b/Foundation/CMakeLists.txt @@ -140,8 +140,6 @@ target_compile_definitions(Foundation PRIVATE DEPLOYMENT_RUNTIME_SWIFT) target_compile_options(Foundation PUBLIC "SHELL:-Xcc -F${CMAKE_BINARY_DIR}") -target_compile_options(Foundation PRIVATE - "SHELL:-Xcc -I${ICU_INCLUDE_DIR}") if(CMAKE_SYSTEM_NAME STREQUAL Windows AND CMAKE_VERSION VERSION_LESS 3.16) # Work around for CMake 15 which doesn't link in the resource file # target properly @@ -153,8 +151,6 @@ if(ENABLE_TESTING) -enable-testing) endif() target_link_libraries(Foundation PRIVATE - ${ICU_UC_LIBRARY} - ${ICU_I18N_LIBRARY} CoreFoundation uuid) target_link_libraries(Foundation PUBLIC @@ -219,8 +215,6 @@ if(ENABLE_TESTING) -enable-testing) endif() target_link_libraries(FoundationNetworking PRIVATE - ${CURL_LIBRARIES} - ${ZLIB_LIBRARIES} Foundation CFURLSessionInterface) set_target_properties(FoundationNetworking PROPERTIES @@ -245,7 +239,6 @@ if(ENABLE_TESTING) -enable-testing) endif() target_link_libraries(FoundationXML PRIVATE - ${LIBXML2_LIBRARIES} Foundation CFXMLInterface) set_target_properties(FoundationXML PROPERTIES