|
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) |
| 9 | +set(SwiftTesting_MACRO "<auto>" CACHE STRING |
| 10 | + "Path to SwiftTesting macro plugin, or '<auto>' for automatically building it") |
11 | 11 |
|
12 |
| -if(NOT SwiftTesting_MACRO_MAKE_PROGRAM) |
13 |
| - set(SwiftTesting_MACRO_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM}) |
14 |
| -endif() |
15 |
| -if(NOT SwiftTesting_MACRO_Swift_COMPILER) |
16 |
| - set(SwiftTesting_MACRO_Swift_COMPILER ${CMAKE_Swift_COMPILER}) |
17 |
| -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() |
23 |
| -if(NOT SwiftTesting_MACRO_AR) |
24 |
| - set(SwiftTesting_MACRO_AR ${CMAKE_AR}) |
25 |
| -endif() |
26 |
| -if(NOT SwiftTesting_MACRO_RANLIB) |
27 |
| - set(SwiftTesting_MACRO_RANLIB ${CMAKE_RANLIB}) |
28 |
| -endif() |
| 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() |
29 | 42 |
|
30 |
| -find_package(SwiftSyntax CONFIG GLOBAL) |
31 |
| -if(SwiftSyntax_FOUND) |
32 |
| - set(SwiftTesting_BuildMacrosAsExecutables NO) |
| 43 | + set(SwiftTesting_MACRO_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/plugin") |
| 44 | + |
| 45 | + ExternalProject_Add(TestingMacros |
| 46 | + PREFIX "tm" |
| 47 | + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/TestingMacros" |
| 48 | + BUILD_ALWAYS ON |
| 49 | + CMAKE_ARGS |
| 50 | + -DCMAKE_MAKE_PROGRAM=${SwiftTesting_MACRO_MAKE_PROGRAM} |
| 51 | + -DCMAKE_Swift_COMPILER=${SwiftTesting_MACRO_Swift_COMPILER} |
| 52 | + -DCMAKE_Swift_FLAGS=${SwiftTesting_MACRO_Swift_FLAGS} |
| 53 | + -DCMAKE_Swift_FLAGS_RELEASE=${SwiftTesting_MACRO_Swift_FLAGS_RELEASE} |
| 54 | + -DCMAKE_Swift_FLAGS_RELWITHDEBINFO=${SwiftTesting_MACRO_Swift_FLAGS_RELWITHDEBINFO} |
| 55 | + -DCMAKE_AR=${SwiftTesting_MACRO_AR} |
| 56 | + -DCMAKE_RANLIB=${SwiftTesting_MACRO_RANLIB} |
| 57 | + -DCMAKE_BUILD_TYPE=${CSwiftTesting_MACRO_BUILD_TYPE} |
| 58 | + -DSwiftTesting_BuildMacrosAsExecutables=${SwiftTesting_BuildMacrosAsExecutables} |
| 59 | + -DSwiftSyntax_DIR=${SwiftSyntax_DIR} |
| 60 | + -DCMAKE_INSTALL_PREFIX=${SwiftTesting_MACRO_INSTALL_PREFIX}) |
| 61 | + |
| 62 | + # Hardcode the known file names based on system name as a workaround since |
| 63 | + # TestingMacros uses `ExternalProject` and we cannot directly query the |
| 64 | + # properties of its targets here. |
| 65 | + if(NOT SwiftTesting_BuildMacrosAsExecutables) |
| 66 | + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 67 | + set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/lib/libTestingMacros.dylib") |
| 68 | + install(PROGRAMS "${SwiftTesting_MACRO_PATH}" |
| 69 | + DESTINATION lib/swift/host/plugins/testing) |
| 70 | + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 71 | + set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/lib/libTestingMacros.so") |
| 72 | + install(PROGRAMS "${SwiftTesting_MACRO_PATH}" |
| 73 | + DESTINATION lib/swift/host/plugins) |
| 74 | + elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 75 | + set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/bin/TestingMacros.dll") |
| 76 | + install(PROGRAMS "${SwiftTesting_MACRO_PATH}" |
| 77 | + DESTINATION bin) |
| 78 | + else() |
| 79 | + message(FATAL_ERROR "Unable to determine the library name for TestingMacros based on system name: ${CMAKE_SYSTEM_NAME}") |
| 80 | + endif() |
| 81 | + else() |
| 82 | + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 83 | + set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/bin/TestingMacros.exe") |
| 84 | + else() |
| 85 | + set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/bin/TestingMacros") |
| 86 | + endif() |
| 87 | + endif() |
| 88 | +elseif(SwiftTesting_MACRO) |
| 89 | + set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO}") |
| 90 | + add_custom_target(TestingMacros DEPENDS "${SwiftTesting_MACRO_PATH}") |
33 | 91 | else()
|
34 |
| - set(SwiftTesting_BuildMacrosAsExecutables YES) |
| 92 | + # If it's excplicitly "false", do not compile the libray with macros. |
| 93 | + add_custom_target(TestingMacros) |
35 | 94 | endif()
|
36 | 95 |
|
37 |
| -ExternalProject_Add(TestingMacros |
38 |
| - PREFIX "tm" |
39 |
| - SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/TestingMacros" |
40 |
| - CMAKE_ARGS |
41 |
| - -DCMAKE_MAKE_PROGRAM=${SwiftTesting_MACRO_MAKE_PROGRAM} |
42 |
| - -DCMAKE_Swift_COMPILER=${SwiftTesting_MACRO_Swift_COMPILER} |
43 |
| - -DCMAKE_Swift_FLAGS=${SwiftTesting_MACRO_Swift_FLAGS} |
44 |
| - -DCMAKE_AR=${SwiftTesting_MACRO_AR} |
45 |
| - -DCMAKE_RANLIB=${SwiftTesting_MACRO_RANLIB} |
46 |
| - -DSwiftTesting_BuildMacrosAsExecutables=${SwiftTesting_BuildMacrosAsExecutables} |
47 |
| - -DSwiftSyntax_DIR=${SwiftSyntax_DIR} |
48 |
| - -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>) |
49 |
| -ExternalProject_Get_Property(TestingMacros BINARY_DIR) |
50 |
| -ExternalProject_Get_Property(TestingMacros INSTALL_DIR) |
| 96 | +if(NOT SwiftTesting_MACRO_PATH) |
| 97 | + message(STATUS "TestingMacros: (none)") |
| 98 | +elseif(SwiftTesting_MACRO_PATH) |
| 99 | + get_filename_component(macro_ext "${SwiftTesting_MACRO_PATH}" LAST_EXT) |
| 100 | + if(macro_ext STREQUAL ${CMAKE_SHARED_LIBRARY_SUFFIX}) |
| 101 | + message(STATUS "TestingMacros: ${SwiftTesting_MACRO_PATH} (shared library)") |
| 102 | + add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-load-plugin-library ${SwiftTesting_MACRO_PATH}>") |
| 103 | + else() |
| 104 | + message(STATUS "TestingMacros: ${SwiftTesting_MACRO_PATH} (executable)") |
| 105 | + add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-load-plugin-exectuable ${SwiftTesting_MACRO_PATH}#TestingMacros>") |
| 106 | + endif() |
| 107 | +endif() |
51 | 108 |
|
52 | 109 | include(AvailabilityDefinitions)
|
53 | 110 | include(CompilerSettings)
|
54 | 111 | add_subdirectory(_TestingInternals)
|
55 | 112 | add_subdirectory(Testing)
|
56 | 113 |
|
57 |
| -if(NOT SwiftTesting_BuildMacrosAsExecutables) |
58 |
| - # Hardcode the known library names based on system name as a workaround since |
59 |
| - # TestingMacros uses `ExternalProject` and we cannot directly query the |
60 |
| - # properties of its targets here. |
61 |
| - if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") |
62 |
| - install(PROGRAMS "${INSTALL_DIR}/lib/libTestingMacros.dylib" |
63 |
| - DESTINATION lib/swift/host/plugins/testing) |
64 |
| - elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") |
65 |
| - install(PROGRAMS "${INSTALL_DIR}/lib/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. |
70 |
| - else() |
71 |
| - message(FATAL_ERROR "Unable to determine the library name for TestingMacros based on system name: ${CMAKE_SYSTEM_NAME}") |
72 |
| - endif() |
73 |
| -endif() |
|
0 commit comments