Skip to content

Commit 0d05234

Browse files
committed
WIP Windows
1 parent dd7096c commit 0d05234

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ endif()
1515
project(SwiftTesting
1616
LANGUAGES CXX Swift)
1717

18+
include(GNUInstallDirs)
19+
1820
list(APPEND CMAKE_MODULE_PATH
1921
${PROJECT_SOURCE_DIR}/cmake/modules
2022
${PROJECT_SOURCE_DIR}/cmake/modules/shared)

Sources/CMakeLists.txt

+15-7
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@
88

99
# Macros must be built for the build machine, not the host.
1010
include(ExternalProject)
11+
1112
if(NOT SwiftTesting_MACRO_MAKE_PROGRAM)
1213
set(SwiftTesting_MACRO_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM})
1314
endif()
1415
if(NOT SwiftTesting_MACRO_Swift_COMPILER)
1516
set(SwiftTesting_MACRO_Swift_COMPILER ${CMAKE_Swift_COMPILER})
1617
endif()
18+
if(NOT SwiftTesting_MACRO_Swift_FLAGS)
19+
set(SwiftTesting_MACRO_Swift_FLAGS ${CMAKE_Swift_FLAGS})
20+
set(SwiftTesting_MACRO_SWIFT_FLAGS_RELEAE ${CMAKE_Swift_FLAGS_RELEAE})
21+
set(SwiftTesting_MACRO_SWIFT_FLAGS_RELWITHDEBINFO ${CMAKE_Swift_FLAGS_RELWITHDEBINFO})
22+
endif()
1723
if(NOT SwiftTesting_MACRO_AR)
1824
set(SwiftTesting_MACRO_AR ${CMAKE_AR})
1925
endif()
@@ -32,10 +38,11 @@ ExternalProject_Add(TestingMacros
3238
PREFIX "tm"
3339
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/TestingMacros"
3440
CMAKE_ARGS
41+
-DCMAKE_MAKE_PROGRAM=${SwiftTesting_MACRO_MAKE_PROGRAM}
3542
-DCMAKE_Swift_COMPILER=${SwiftTesting_MACRO_Swift_COMPILER}
43+
-DCMAKE_Swift_FLAGS=${SwiftTesting_MACRO_Swift_FLAGS}
3644
-DCMAKE_AR=${SwiftTesting_MACRO_AR}
3745
-DCMAKE_RANLIB=${SwiftTesting_MACRO_RANLIB}
38-
-DCMAKE_MAKE_PROGRAM=${SwiftTesting_MACRO_MAKE_PROGRAM}
3946
-DSwiftTesting_BuildMacrosAsExecutables=${SwiftTesting_BuildMacrosAsExecutables}
4047
-DSwiftSyntax_DIR=${SwiftSyntax_DIR}
4148
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>)
@@ -52,14 +59,15 @@ if(NOT SwiftTesting_BuildMacrosAsExecutables)
5259
# TestingMacros uses `ExternalProject` and we cannot directly query the
5360
# properties of its targets here.
5461
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
55-
set(SwiftTesting_TestingMacrosLibraryName "libTestingMacros.dylib")
62+
install(PROGRAMS "${INSTALL_DIR}/lib/swift/host/plugins/testing/libTestingMacros.dylib"
63+
DESTINATION lib/swift/host/plugins/testing)
5664
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
57-
set(SwiftTesting_TestingMacrosLibraryName "libTestingMacros.so")
65+
install(PROGRAMS "${INSTALL_DIR}/lib/swift/host/plugins/libTestingMacros.so"
66+
DESTINATION lib/swift/host/plugins)
67+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
68+
# In Windows toolchain, TestingMacros.dll is installed from seprate CMake
69+
# buikd, just for the macros.
5870
else()
5971
message(FATAL_ERROR "Unable to determine the library name for TestingMacros based on system name: ${CMAKE_SYSTEM_NAME}")
6072
endif()
61-
62-
install(PROGRAMS "${INSTALL_DIR}/lib/${SwiftTesting_TestingMacrosLibraryName}"
63-
# TODO: Finalize the install path
64-
DESTINATION lib/swift/host/plugins)
6573
endif()

Sources/TestingMacros/CMakeLists.txt

+9-8
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,17 @@ else()
6060
add_library(TestingMacros SHARED)
6161

6262
target_link_options(TestingMacros PRIVATE "-no-toolchain-stdlib-rpath")
63-
# Not setting RPATH requires all the dependencies are already loaded in the
64-
# process, because 'plugin' directory wouldn't contain any dependencies.
63+
# Not setting RPATH means it requires all the dependencies are already loaded
64+
# in the process, because 'plugin' directory wouldn't contain any dependencies.
6565
set_property(TARGET TestingMacros PROPERTY INSTALL_RPATH)
6666

67-
# Install the macro plugin to the default location.
68-
#
69-
# This is not the plugin's actual, final install location -- it's only
70-
# relative to this external project's install dir. The final location is
71-
# determined by the "outer" project.
72-
install(TARGETS TestingMacros)
67+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
68+
install(TARGETS TestingMacros
69+
RUNTIME DESTINATION bin)
70+
else()
71+
# Other platforms, TestingMacros is installed by the parent project.
72+
install(TARGETS TestingMacros)
73+
endif()
7374
endif()
7475

7576
target_sources(TestingMacros PRIVATE

cmake/modules/SwiftModuleInstallation.cmake

+21-7
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,19 @@ function(_swift_testing_install_target module)
2828
set(swift swift)
2929
endif()
3030

31+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
32+
set(lib_destination_dir "lib/${swift}/${swift_os}/testing")
33+
set_property(TARGET ${module} PROPERTY
34+
INSTALL_RPATH "@loader_path/..")
35+
else()
36+
set(lib_destination_dir "lib/${swift}/${swift_os}")
37+
set_property(TARGET ${module} PROPERTY
38+
INSTALL_RPATH "$ORIGIN")
39+
endif()
40+
3141
install(TARGETS ${module}
32-
ARCHIVE DESTINATION lib/${swift}/${swift_os}
33-
LIBRARY DESTINATION lib/${swift}/${swift_os}
42+
ARCHIVE DESTINATION "${lib_destination_dir}"
43+
LIBRARY DESTINATION "${lib_destination_dir}"
3444
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
3545
if(type STREQUAL EXECUTABLE)
3646
return()
@@ -52,13 +62,17 @@ function(_swift_testing_install_target module)
5262
mark_as_advanced(SwiftTesting_MODULE_TRIPLE)
5363
endif()
5464

65+
set(module_dir "${lib_destination_dir}/${module_name}.swiftmodule")
5566
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc
56-
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
67+
DESTINATION "${module_dir}"
5768
RENAME ${SwiftTesting_MODULE_TRIPLE}.swiftdoc)
5869
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule
59-
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
70+
DESTINATION "${module_dir}"
6071
RENAME ${SwiftTesting_MODULE_TRIPLE}.swiftmodule)
61-
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftinterface
62-
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
63-
RENAME ${SwiftTesting_MODULE_TRIPLE}.swiftinterface)
72+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
73+
# Only Darwin has stable ABI.
74+
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftinterface
75+
DESTINATION "${module_dir}"
76+
RENAME ${SwiftTesting_MODULE_TRIPLE}.swiftinterface)
77+
endif()
6478
endfunction()

0 commit comments

Comments
 (0)