Skip to content

build: restructure the install location handling #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin AND NOT DISABLE_XCTWAITER)
find_package(Foundation CONFIG REQUIRED)
endif()

include(SwiftSupport)
include(GNUInstallDirs)
include(CheckLinkerFlag)
include(PlatformInfo)

if(CMAKE_SYSTEM_NAME STREQUAL Linux
OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD
OR CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
option(XCTest_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" NO)
set(XCTest_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${XCTest_PLATFORM_SUBDIR}$<$<BOOL:${XCTest_INSTALL_NESTED_SUBDIR}>:/${XCTest_ARCH_SUBDIR}>")
set(XCTest_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${XCTest_PLATFORM_SUBDIR}$<$<BOOL:${XCTest_INSTALL_NESTED_SUBDIR}>:/${XCTest_PLATFORM_SUBDIR}>")

if(UNIX)
enable_language(C)
check_linker_flag(C "LINKER:--build-id=sha1" LINKER_SUPPORTS_BUILD_ID)
endif()
Expand Down Expand Up @@ -142,14 +144,17 @@ endif()


set_property(GLOBAL APPEND PROPERTY XCTest_EXPORTS XCTest)
get_swift_host_arch(swift_arch)


install(TARGETS XCTest
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>
ARCHIVE DESTINATION ${XCTest_INSTALL_LIBDIR}
LIBRARY DESTINATION ${XCTest_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/swift/XCTest.swiftdoc
${CMAKE_CURRENT_BINARY_DIR}/swift/XCTest.swiftmodule
DESTINATION ${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>/${swift_arch})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/swift/XCTest.swiftdoc
DESTINATION ${XCTest_INSTALL_SWIFTMODULEDIR}/XCTest.swiftmodule
RENAME ${XCTest_MODULE_TRIPLE}.swiftdoc)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/swift/XCTest.swiftmodule
DESTINATION ${XCTest_INSTALL_SWIFTMODULEDIR}/XCTest.swiftmodule
RENAME ${XCTest_MODULE_TRIPLE}.swiftmodule)

add_subdirectory(cmake/modules)
41 changes: 41 additions & 0 deletions cmake/modules/PlatformInfo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

set(print_target_info_invocation "${CMAKE_Swift_COMPILER}" -print-target-info)
if(CMAKE_Swift_COMPILER_TARGET)
list(APPEND print_target_info_invocation -target ${CMAKE_Swift_COMPILER_TARGET})
endif()
execute_process(COMMAND ${print_target_info_invocation} OUTPUT_VARIABLE target_info_json)
message(CONFIGURE_LOG "Swift Target Info: ${print_target_info_invocation}\n"
"${target_info_json}")

if(NOT XCTest_MODULE_TRIPLE)
string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
set(XCTest_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used for installed swift{doc,module,interface} files")
mark_as_advanced(XCTest_MODULE_TRIPLE)

message(CONFIGURE_LOG "Swift Module Triple: ${module_triple}")
endif()

if(NOT XCTest_PLATFORM_SUBDIR)
string(JSON platform GET "${target_info_json}" "target" "platform")
if(NOT platform)
if(NOT SWIFT_SYSTEM_NAME)
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(platform macosx)
else()
set(platform $<LOWER_CASE:${CMAKE_SYSTEM_NAME}>)
endif()
endif()
endif()
set(XCTest_PLATFORM_SUBDIR "${platform}" CACHE STRING "Platform name used for installed swift{doc,module,interface} files")
mark_as_advanced(XCTest_PLATFORM_SUBDIR)

message(CONFIGURE_LOG "Swift Platform: ${platform}")
endif()

if(NOT XCTest_ARCH_SUBDIR)
string(JSON arch GET "${target_info_json}" "target" "arch")
set(XCTest_ARCH_SUBDIR "${arch}" CACHE STRING "Architecture used for setting the architecture subdirectory")
mark_as_advanced(XCTest_ARCH_SUBDIR)

message(CONFIGURE_LOG "Swift Architecture: ${arch}")
endif()
44 changes: 0 additions & 44 deletions cmake/modules/SwiftSupport.cmake

This file was deleted.