|
6 | 6 | # See http://swift.org/LICENSE.txt for license information
|
7 | 7 | # See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
8 | 8 |
|
9 |
| -# Macros must be built for the build machine, not the host. |
10 |
| -include(ExternalProject) |
11 |
| -if(NOT SwiftTesting_MACRO_MAKE_PROGRAM) |
12 |
| - set(SwiftTesting_MACRO_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM}) |
13 |
| -endif() |
| 9 | +set(SwiftTesting_MACRO "<auto>" CACHE STRING |
| 10 | + "Path to SwiftTesting macro plugin, or '<auto>' for automatically building it") |
| 11 | + |
| 12 | +if(SwiftTesting_MACRO STREQUAL "<auto>") |
| 13 | + # Macros must be built for the build machine, not the host. |
| 14 | + include(ExternalProject) |
| 15 | + if(NOT SwiftTesting_MACRO_MAKE_PROGRAM) |
| 16 | + set(SwiftTesting_MACRO_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM}) |
| 17 | + endif() |
| 18 | + if(NOT SwiftTesting_MACRO_Swift_COMPILER) |
| 19 | + set(SwiftTesting_MACRO_Swift_COMPILER ${CMAKE_Swift_COMPILER}) |
| 20 | + endif() |
| 21 | + if(NOT SwiftTesting_MACRO_Swift_FLAGS) |
| 22 | + set(SwiftTesting_MACRO_Swift_FLAGS ${CMAKE_Swift_FLAGS}) |
| 23 | + set(SwiftTesting_MACRO_SWIFT_FLAGS_RELEASE ${CMAKE_Swift_FLAGS_RELEASE}) |
| 24 | + set(SwiftTesting_MACRO_SWIFT_FLAGS_RELWITHDEBINFO ${CMAKE_Swift_FLAGS_RELWITHDEBINFO}) |
| 25 | + endif() |
| 26 | + if(NOT SwiftTesting_MACRO_AR) |
| 27 | + set(SwiftTesting_MACRO_AR ${CMAKE_AR}) |
| 28 | + endif() |
| 29 | + if(NOT SwiftTesting_MACRO_RANLIB) |
| 30 | + set(SwiftTesting_MACRO_RANLIB ${CMAKE_RANLIB}) |
| 31 | + endif() |
| 32 | + if(NOT SwiftTesting_MACRO_BUILD_TYPE) |
| 33 | + set(SwiftTesting_MACRO_BUILD_TYPE ${CMAKE_BUILD_TYPE}) |
| 34 | + endif() |
| 35 | + |
| 36 | + find_package(SwiftSyntax CONFIG GLOBAL) |
| 37 | + if(SwiftSyntax_FOUND) |
| 38 | + set(SwiftTesting_BuildMacrosAsExecutables NO) |
| 39 | + else() |
| 40 | + set(SwiftTesting_BuildMacrosAsExecutables YES) |
| 41 | + endif() |
14 | 42 |
|
15 |
| -find_package(SwiftSyntax CONFIG GLOBAL) |
16 |
| -if(SwiftSyntax_FOUND) |
17 |
| - set(SwiftTesting_BuildMacrosAsExecutables NO) |
| 43 | + # Build and install the plugin into the current build directry. |
| 44 | + set(SwiftTesting_MACRO_INSTALL_PREFIX "${CMAKE_BINARY_DIR}") |
| 45 | + |
| 46 | + ExternalProject_Add(TestingMacros |
| 47 | + PREFIX "tm" |
| 48 | + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/TestingMacros" |
| 49 | + BUILD_ALWAYS ON |
| 50 | + CMAKE_ARGS |
| 51 | + -DCMAKE_MAKE_PROGRAM=${SwiftTesting_MACRO_MAKE_PROGRAM} |
| 52 | + -DCMAKE_Swift_COMPILER=${SwiftTesting_MACRO_Swift_COMPILER} |
| 53 | + -DCMAKE_Swift_FLAGS=${SwiftTesting_MACRO_Swift_FLAGS} |
| 54 | + -DCMAKE_Swift_FLAGS_RELEASE=${SwiftTesting_MACRO_Swift_FLAGS_RELEASE} |
| 55 | + -DCMAKE_Swift_FLAGS_RELWITHDEBINFO=${SwiftTesting_MACRO_Swift_FLAGS_RELWITHDEBINFO} |
| 56 | + -DCMAKE_AR=${SwiftTesting_MACRO_AR} |
| 57 | + -DCMAKE_RANLIB=${SwiftTesting_MACRO_RANLIB} |
| 58 | + -DCMAKE_BUILD_TYPE=${CSwiftTesting_MACRO_BUILD_TYPE} |
| 59 | + -DSwiftTesting_BuildMacrosAsExecutables=${SwiftTesting_BuildMacrosAsExecutables} |
| 60 | + -DSwiftSyntax_DIR=${SwiftSyntax_DIR} |
| 61 | + -DCMAKE_INSTALL_PREFIX=${SwiftTesting_MACRO_INSTALL_PREFIX}) |
| 62 | + |
| 63 | + # Hardcode the known file names based on system name as a workaround since |
| 64 | + # TestingMacros uses `ExternalProject` and we cannot directly query the |
| 65 | + # properties of its targets here. |
| 66 | + if(NOT SwiftTesting_BuildMacrosAsExecutables) |
| 67 | + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") |
| 68 | + set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/lib/swift/host/plugins/testing/libTestingMacros.dylib") |
| 69 | + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") |
| 70 | + set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/lib/swift/host/plugins/libTestingMacros.so") |
| 71 | + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") |
| 72 | + set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/bin/TestingMacros.dll") |
| 73 | + else() |
| 74 | + message(FATAL_ERROR "Unable to determine the library name for TestingMacros based on system name: ${CMAKE_HOST_SYSTEM_NAME}") |
| 75 | + endif() |
| 76 | + else() |
| 77 | + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") |
| 78 | + set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/bin/TestingMacros.exe") |
| 79 | + else() |
| 80 | + set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/bin/TestingMacros") |
| 81 | + endif() |
| 82 | + endif() |
| 83 | +elseif(SwiftTesting_MACRO) |
| 84 | + # Use the passed-in plugin path. |
| 85 | + set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO}") |
| 86 | + add_custom_target(TestingMacros DEPENDS "${SwiftTesting_MACRO_PATH}") |
18 | 87 | else()
|
19 |
| - set(SwiftTesting_BuildMacrosAsExecutables YES) |
| 88 | + # If it's explicitly "NO", do not compile the library with macros. |
| 89 | + add_custom_target(TestingMacros) |
20 | 90 | endif()
|
21 | 91 |
|
22 |
| -ExternalProject_Add(TestingMacros |
23 |
| - PREFIX "tm" |
24 |
| - SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/TestingMacros" |
25 |
| - CMAKE_ARGS |
26 |
| - -DCMAKE_MAKE_PROGRAM=${SwiftTesting_MACRO_MAKE_PROGRAM} |
27 |
| - -DSwiftTesting_BuildMacrosAsExecutables=${SwiftTesting_BuildMacrosAsExecutables} |
28 |
| - -DSwiftSyntax_DIR=${SwiftSyntax_DIR} |
29 |
| - INSTALL_COMMAND "") |
30 |
| -ExternalProject_Get_Property(TestingMacros BINARY_DIR) |
| 92 | +if(NOT SwiftTesting_MACRO_PATH) |
| 93 | + message(STATUS "TestingMacros: (none)") |
| 94 | +elseif(SwiftTesting_MACRO_PATH) |
| 95 | + if(SwiftTesting_MACRO_PATH MATCHES [[\.(dylib|so|dll)$]]) |
| 96 | + message(STATUS "TestingMacros: ${SwiftTesting_MACRO_PATH} (shared library)") |
| 97 | + add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-load-plugin-library ${SwiftTesting_MACRO_PATH}>") |
| 98 | + else() |
| 99 | + message(STATUS "TestingMacros: ${SwiftTesting_MACRO_PATH} (executable)") |
| 100 | + add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-load-plugin-exectuable ${SwiftTesting_MACRO_PATH}#TestingMacros>") |
| 101 | + endif() |
| 102 | +endif() |
31 | 103 |
|
32 | 104 | include(AvailabilityDefinitions)
|
33 | 105 | include(CompilerSettings)
|
|
0 commit comments