diff --git a/Runtimes/Supplemental/cmake/modules/FindSwiftCore.cmake b/Runtimes/Supplemental/cmake/modules/FindSwiftCore.cmake index 458dbafea360f..13a7ba9a66944 100644 --- a/Runtimes/Supplemental/cmake/modules/FindSwiftCore.cmake +++ b/Runtimes/Supplemental/cmake/modules/FindSwiftCore.cmake @@ -37,6 +37,8 @@ The module may set the following variables if `SwiftCore_DIR` is not set. #]=======================================================================] +include_guard(GLOBAL) + # If the SwiftCore_DIR_FLAG is specified, look there instead. The cmake-generated # config file is more accurate, but requires that the SDK has one available. if(SwiftCore_DIR) @@ -51,113 +53,112 @@ if(SwiftCore_DIR) endif() include(FindPackageHandleStandardArgs) +include(PlatformInfo) + +# This was loosely modelled after other find modules +# (namely FindGLEW), where the equivalent parameter +# is not stored in cache (possibly because we want +# the project importing it to be able to +# it "immediately") +if(NOT DEFINED SwiftCore_USE_STATIC_LIBS) + set(SwiftCore_USE_STATIC_LIBS OFF) + if(NOT BUILD_SHARED_LIBS AND NOT APPLE) + set(SwiftCore_USE_STATIC_LIBS ON) + endif() +endif() if(APPLE) + list(APPEND SwiftCore_INCLUDE_DIR_HINTS + "${CMAKE_OSX_SYSROOT}/usr/lib/swift") + list(APPEND SwiftCore_LIBRARY_HINTS + "${CMAKE_OSX_SYSROOT}/usr/lib/swift") # When building for Apple platforms, SwiftCore always comes from within the # SDK as a tbd for a shared library in the shared cache. - find_path(SwiftCore_INCLUDE_DIR - "Swift.swiftmodule" - HINTS - "${CMAKE_OSX_SYSROOT}/usr/lib/swift") - find_library(SwiftCore_IMPLIB - NAMES "libswiftCore.tbd" - HINTS - "${CMAKE_OSX_SYSROOT}/usr/lib/swift") - add_library(swiftCore SHARED IMPORTED GLOBAL) - set_target_properties(swiftCore PROPERTIES - IMPORTED_IMPLIB "${SwiftCore_IMPLIB}" - INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}") - find_package_handle_standard_args(SwiftCore DEFAULT_MSG - SwiftCore_IMPLIB SwiftCore_INCLUDE_DIR) + list(APPEND SwiftCore_NAMES libswiftCore.tbd) elseif(LINUX) - if (NOT BUILD_SHARED_LIBS) - find_path(SwiftCore_INCLUDE_DIR - "Swift.swiftmodule" - HINTS - "${Swift_SDKROOT}/usr/lib/swift_static/linux-static") - find_library(SwiftCore_LIBRARY - NAMES "libswiftCore.a" - HINTS "${Swift_SDKROOT}/usr/lib/swift_static/linux-static") - add_library(swiftCore STATIC IMPORTED GLOBAL) + if (SwiftCore_USE_STATIC_LIBS) + list(APPEND SwiftCore_INCLUDE_DIR_HINTS + "${Swift_SDKROOT}/usr/lib/swift_static/linux-static") + list(APPEND SwiftCore_LIBRARY_HINTS + "${Swift_SDKROOT}/usr/lib/swift_static/linux-static") + list(APPEND SwiftCore_NAMES libswiftCore.a) else() - find_path(SwiftCore_INCLUDE_DIR - "Swift.swiftmodule" - HINTS - "${Swift_SDKROOT}/usr/lib/swift/linux") - find_library(SwiftCore_LIBRARY - NAMES "libswiftCore.so" - HINTS "${Swift_SDKROOT}/usr/lib/swift/linux") - add_library(swiftCore SHARED IMPORTED GLOBAL) + list(APPEND SwiftCore_INCLUDE_DIR_HINTS + "${Swift_SDKROOT}/usr/lib/swift/linux") + list(APPEND SwiftCore_LIBRARY_HINTS + "${Swift_SDKROOT}/usr/lib/swift/linux") + list(APPEND SwiftCore_NAMES libswiftCore.so) endif() - set_target_properties(swiftCore PROPERTIES - IMPORTED_LOCATION "${SwiftCore_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}") - find_package_handle_standard_args(SwiftCore DEFAULT_MSG - SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR) elseif(WIN32) - find_path(SwiftCore_INCLUDE_DIR - "Swift.swiftmodule" - HINTS - "${Swift_SDKROOT}/usr/lib/swift/windows" - "$ENV{SDKROOT}/usr/lib/swift/windows") - find_library(SwiftCore_LIBRARY - NAMES "libswiftCore.lib" - HINTS - "${Swift_SDKROOT}/usr/lib/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}" - "${Swift_SDKROOT}/usr/lib/swift" - "$ENV{SDKROOT}/usr/lib/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}" - "$ENV{SDKROOT}/usr/lib/swift") - - add_library(swiftCore SHARED IMPORTED GLOBAL) - set_target_properties(swiftCore PROPERTIES - IMPORTED_IMPLIB "${SwiftCore_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}") - find_package_handle_standard_args(SwiftCore DEFAULT_MSG - SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR) + list(APPEND SwiftCore_INCLUDE_DIR_HINTS + "${Swift_SDKROOT}/usr/lib/swift/windows" + "$ENV{SDKROOT}/usr/lib/swift/windows") + list(APPEND SwiftCore_LIBRARY_HINTS + "${Swift_SDKROOT}/usr/lib/swift/${${PROJECT_NAME}_PLATFORM_SUBDIR}/${${PROJECT_NAME}_ARCH_SUBDIR}" + "${Swift_SDKROOT}/usr/lib/swift" + "$ENV{SDKROOT}/usr/lib/swift/${${PROJECT_NAME}_PLATFORM_SUBDIR}/${${PROJECT_NAME}_ARCH_SUBDIR}" + "$ENV{SDKROOT}/usr/lib/swift") + if (SwiftCore_USE_STATIC_LIBS) + list(APPEND SwiftCore_NAMES libswiftCore.lib) + else() + list(APPEND SwiftCore_NAMES swiftCore.lib) + endif() elseif(ANDROID) - if(BUILD_SHARED_LIBS) - find_path(SwiftCore_INCLUDE_DIR - "Swift.swiftmodule" - NO_CMAKE_FIND_ROOT_PATH - HINTS - "${Swift_SDKROOT}/usr/lib/swift/android" - "$ENV{SDKROOT}/usr/lib/swift/android") - find_library(SwiftCore_LIBRARY - NO_CMAKE_FIND_ROOT_PATH - NAMES "libswiftCore.so" - HINTS - "${Swift_SDKROOT}/usr/lib/swift/android/${SwiftCore_ARCH_SUBDIR}" - "${Swift_SDKROOT}/usr/lib/swift" - "$ENV{SDKROOT}/usr/lib/swift/android/${SwiftCore_ARCH_SUBDIR}" - "$ENV{SDKROOT}/usr/lib/swift") - - add_library(swiftCore SHARED IMPORTED GLOBAL) + if (SwiftCore_USE_STATIC_LIBS) + list(APPEND SwiftCore_INCLUDE_DIR_HINTS + "${Swift_SDKROOT}/usr/lib/swift_static/android" + "$ENV{SDKROOT}/usr/lib/swift_static/android") + list(APPEND SwiftCore_LIBRARY_HINTS + "${Swift_SDKROOT}/usr/lib/swift_static/android/${${PROJECT_NAME}_ARCH_SUBDIR}" + "${Swift_SDKROOT}/usr/lib/swift_static" + "$ENV{SDKROOT}/usr/lib/swift_static/android/${${PROJECT_NAME}_ARCH_SUBDIR}" + "$ENV{SDKROOT}/usr/lib/swift_static") + list(APPEND SwiftCore_NAMES libswiftCore.a) else() - find_path(SwiftCore_INCLUDE_DIR - "Swift.swiftmodule" - NO_CMAKE_FIND_ROOT_PATH - HINTS - "${Swift_SDKROOT}/usr/lib/swift_static/android" - "$ENV{SDKROOT}/usr/lib/swift_static/android") - find_library(SwiftCore_LIBRARY - NO_CMAKE_FIND_ROOT_PATH - NAMES "libswiftCore.a" - HINTS - "${Swift_SDKROOT}/usr/lib/swift_static/android/${SwiftCore_ARCH_SUBDIR}" - "${Swift_SDKROOT}/usr/lib/swift_static" - "$ENV{SDKROOT}/usr/lib/swift_static/android/${SwiftCore_ARCH_SUBDIR}" - "$ENV{SDKROOT}/usr/lib/swift_static") - - add_library(swiftCore STATIC IMPORTED GLOBAL) + list(APPEND SwiftCore_INCLUDE_DIR_HINTS + "${Swift_SDKROOT}/usr/lib/swift/android" + "$ENV{SDKROOT}/usr/lib/swift/android") + list(APPEND SwiftCore_LIBRARY_HINTS + "${Swift_SDKROOT}/usr/lib/swift/android/${${PROJECT_NAME}_ARCH_SUBDIR}" + "${Swift_SDKROOT}/usr/lib/swift" + "$ENV{SDKROOT}/usr/lib/swift/android/${${PROJECT_NAME}_ARCH_SUBDIR}" + "$ENV{SDKROOT}/usr/lib/swift") + list(APPEND SwiftCore_NAMES libswiftCore.so) endif() - - set_target_properties(swiftCore PROPERTIES - IMPORTED_LOCATION "${SwiftCore_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}") - find_package_handle_standard_args(SwiftCore DEFAULT_MSG - SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR) else() message(FATAL_ERROR "FindSwiftCore.cmake module search not implemented for targeted platform\n" " Build Core for your platform and set `SwiftCore_DIR` to" " the directory containing SwiftCoreConfig.cmake\n") endif() + +find_path(SwiftCore_INCLUDE_DIR + "Swift.swiftmodule" + NO_CMAKE_FIND_ROOT_PATH + HINTS + ${SwiftCore_INCLUDE_DIR_HINTS}) +find_library(SwiftCore_LIBRARY + NAMES + ${SwiftCore_NAMES} + NO_CMAKE_FIND_ROOT_PATH + HINTS + ${SwiftCore_LIBRARY_HINTS}) + +if(SwiftCore_USE_STATIC_LIBS) + add_library(swiftCore STATIC IMPORTED GLOBAL) +else() + add_library(swiftCore SHARED IMPORTED GLOBAL) +endif() + +set_target_properties(swiftCore PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SwiftCore_INCLUDE_DIR}") + +if(LINUX OR ANDROID) + set_target_properties(swiftCore PROPERTIES + IMPORTED_LOCATION "${SwiftCore_LIBRARY}") +else() + set_target_properties(swiftCore PROPERTIES + IMPORTED_IMPLIB "${SwiftCore_LIBRARY}") +endif() + +find_package_handle_standard_args(SwiftCore DEFAULT_MSG + SwiftCore_LIBRARY SwiftCore_INCLUDE_DIR) diff --git a/Runtimes/Supplemental/cmake/modules/PlatformInfo.cmake b/Runtimes/Supplemental/cmake/modules/PlatformInfo.cmake index 4dceb92da6629..b62a729bc8ffd 100644 --- a/Runtimes/Supplemental/cmake/modules/PlatformInfo.cmake +++ b/Runtimes/Supplemental/cmake/modules/PlatformInfo.cmake @@ -1,3 +1,5 @@ +include_guard(GLOBAL) + if(NOT ${PROJECT_NAME}_SIZEOF_POINTER) set(${PROJECT_NAME}_SIZEOF_POINTER "${CMAKE_SIZEOF_VOID_P}" CACHE STRING "Size of a pointer in bytes") message(CONFIGURE_LOG "Stdlib Pointer size: ${CMAKE_SIZEOF_VOID_P}")