|
10 | 10 | function(add_swift_host_library name)
|
11 | 11 | set(ASHL_SOURCES ${ARGN})
|
12 | 12 |
|
| 13 | + # Create the library target. |
13 | 14 | add_library(${name} ${ASHL_SOURCES})
|
14 | 15 |
|
15 | 16 | # Add this to the list of exported targets.
|
16 | 17 | set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS ${name})
|
17 | 18 |
|
| 19 | + # Determine the module triple based on the target triple. |
| 20 | + # FIXME: We would prefer to have build-script tell us. |
| 21 | + string(REGEX REPLACE "macosx[0-9]+([.][0-9]+)?" "macos" module_triple |
| 22 | + ${CMAKE_Swift_COMPILER_TARGET}) |
| 23 | + |
| 24 | + # Determine where Swift modules will be built and installed. |
| 25 | + set(module_dir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) |
| 26 | + set(module_base "${module_dir}/${name}.swiftmodule") |
| 27 | + set(module_file "${module_base}/${module_triple}.swiftmodule") |
| 28 | + set(module_interface_file "${module_base}/${module_triple}.swiftinterface") |
| 29 | + set(module_sourceinfo_file "${module_base}/${module_triple}.swiftsourceinfo") |
| 30 | + |
| 31 | + # Add a custom target to create the module directory. |
| 32 | + add_custom_command( |
| 33 | + TARGET ${name} |
| 34 | + PRE_BUILD |
| 35 | + COMMAND "${CMAKE_COMMAND}" -E make_directory ${module_base} |
| 36 | + COMMENT "Generating module directory for ${name}") |
| 37 | + |
| 38 | + # Install the Swift module into the appropriate location. |
| 39 | + set_target_properties(${name} |
| 40 | + PROPERTIES Swift_MODULE_DIRECTORY ${module_base} |
| 41 | + ) |
| 42 | + |
| 43 | + # Configure the emission of the Swift module files. |
| 44 | + target_compile_options("${name}" PRIVATE |
| 45 | + $<$<COMPILE_LANGUAGE:Swift>: |
| 46 | + -module-name;${name}; |
| 47 | + -emit-module-path;${module_file}; |
| 48 | + -emit-module-source-info-path;${module_sourceinfo_file} |
| 49 | + >) |
| 50 | + |
18 | 51 | # NOTE: workaround for CMake not setting up include flags yet
|
19 | 52 | set_target_properties(${name} PROPERTIES
|
20 |
| - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) |
| 53 | + INTERFACE_INCLUDE_DIRECTORIES ${module_dir} |
| 54 | + ) |
21 | 55 |
|
22 | 56 | # Install this target
|
23 | 57 | install(TARGETS ${name}
|
|
0 commit comments