|
1 |
| -# Generate and install swift interface files |
| 1 | +i# Generate and install swift interface files |
2 | 2 |
|
3 | 3 | # TODO: CMake should learn how to model library evolution and generate this
|
4 | 4 | # stuff automatically.
|
5 |
| - |
| 5 | +if(POLICY CMP0195) |
| 6 | + message(AUTHOR_WARNING [=[ |
| 7 | + This version of CMake supports the Swift module directory structure |
| 8 | + Please consider checking the implementation of `emit_swift_interface`` |
| 9 | + to ensure it behaves as expected |
| 10 | + ]=]) |
| 11 | +endif() |
6 | 12 |
|
7 | 13 | # Generate a swift interface file for the target if library evolution is enabled
|
8 | 14 | function(emit_swift_interface target)
|
9 | 15 | # Generate the target-variant binary swift module when performing zippered
|
10 | 16 | # build
|
11 |
| - if(SwiftOverlay_VARIANT_MODULE_TRIPLE) |
12 |
| - set(variant_module_tmp_dir "${CMAKE_CURRENT_BINARY_DIR}/${target}-${SwiftOverlay_VARIANT_MODULE_TRIPLE}") |
13 |
| - file(MAKE_DIRECTORY "${variant_module_tmp_dir}") |
| 17 | + # Clean this up once CMake has nested swiftmodules in the build directory: |
| 18 | + # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/10664 |
| 19 | + # https://cmake.org/cmake/help/git-stage/policy/CMP0195.html |
| 20 | + |
| 21 | + # We can't expand the Swift_MODULE_NAME target property in a generator |
| 22 | + # expression or it will fail saying that the target doesn't exist. |
| 23 | + get_target_property(module_name ${target} Swift_MODULE_NAME) |
| 24 | + if(NOT module_name) |
| 25 | + set(module_name ${target}) |
| 26 | + endif() |
| 27 | + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") |
| 28 | + target_compile_options(${target} PRIVATE |
| 29 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-module-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_MODULE_TRIPLE}.swiftmodule>") |
| 30 | + if(SwiftCore_VARIANT_MODULE_TRIPLE) |
14 | 31 | target_compile_options(${target} PRIVATE
|
15 |
| - "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-variant-module-path ${variant_module_tmp_dir}/${target}.swiftmodule>") |
| 32 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-variant-module-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_VARIANT_MODULE_TRIPLE}.swiftmodule>") |
16 | 33 | endif()
|
| 34 | + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_MODULE_TRIPLE}.swiftmodule" |
| 35 | + DEPENDS ${target}) |
| 36 | + target_sources(${target} |
| 37 | + INTERFACE |
| 38 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_MODULE_TRIPLE}.swiftmodule>) |
17 | 39 |
|
18 | 40 | # Generate textual swift interfaces is library-evolution is enabled
|
19 |
| - if(SwiftOverlay_ENABLE_LIBRARY_EVOLUTION) |
| 41 | + if(SwiftCore_ENABLE_LIBRARY_EVOLUTION) |
| 42 | + target_compile_options(${target} PRIVATE |
| 43 | + $<$<COMPILE_LANGUAGE:Swift>:-emit-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_MODULE_TRIPLE}.swiftinterface> |
| 44 | + $<$<COMPILE_LANGUAGE:Swift>:-emit-private-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_MODULE_TRIPLE}.private.swiftinterface>) |
| 45 | + if(SwiftCore_VARIANT_MODULE_TRIPLE) |
| 46 | + target_compile_options(${target} PRIVATE |
| 47 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-variant-module-interface-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_VARIANT_MODULE_TRIPLE}.swiftinterface>" |
| 48 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-variant-private-module-interface-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_VARIANT_MODULE_TRIPLE}.private.swiftinterface>") |
| 49 | + endif() |
20 | 50 | target_compile_options(${target} PRIVATE
|
21 |
| - $<$<COMPILE_LANGUAGE:Swift>:-emit-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftinterface> |
22 |
| - $<$<COMPILE_LANGUAGE:Swift>:-emit-private-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.private.swiftinterface> |
23 | 51 | $<$<COMPILE_LANGUAGE:Swift>:-library-level$<SEMICOLON>api>
|
24 | 52 | $<$<COMPILE_LANGUAGE:Swift>:-Xfrontend$<SEMICOLON>-require-explicit-availability=ignore>)
|
25 |
| - |
26 |
| - # Emit catalyst swiftmodules and interfaces |
27 |
| - if(SwiftOverlay_VARIANT_MODULE_TRIPLE) |
28 |
| - target_compile_options(${target} PRIVATE |
29 |
| - "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-variant-module-interface-path ${variant_module_tmp_dir}/${target}.swiftinterface>" |
30 |
| - "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-variant-private-module-interface-path ${variant_module_tmp_dir}/${target}.private.swiftinterface>") |
31 |
| - endif() |
32 | 53 | endif()
|
33 | 54 | endfunction()
|
0 commit comments