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