diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ddf76cdff2..9e2421304fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,13 @@ cmake_minimum_required(VERSION 3.19.6) +# Enable Swift_COMPILATION_MODE property. +set(CMP0157_IS_NEW FALSE) +if(POLICY CMP0157) + cmake_policy(SET CMP0157 NEW) + set(CMP0157_IS_NEW TRUE) +endif() + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) project(SwiftSyntax LANGUAGES C Swift) diff --git a/cmake/modules/AddSwiftHostLibrary.cmake b/cmake/modules/AddSwiftHostLibrary.cmake index 25d6c49799f..5f8385f8dd6 100644 --- a/cmake/modules/AddSwiftHostLibrary.cmake +++ b/cmake/modules/AddSwiftHostLibrary.cmake @@ -32,16 +32,18 @@ function(target_link_swift_syntax_libraries TARGET) # seem to be being tracked. # # Remove once rdar://102202478 is fixed. - foreach(DEPENDENCY ${dependencies}) - string(REGEX REPLACE [<>:\"/\\|?*] _ sanitized ${DEPENDENCY}) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift - COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift - DEPENDS ${DEPENDENCY} - ) - target_sources(${TARGET} PRIVATE - ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift - ) - endforeach() + if(NOT CMP0157_IS_NEW) + foreach(DEPENDENCY ${dependencies}) + string(REGEX REPLACE [<>:\"/\\|?*] _ sanitized ${DEPENDENCY}) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift + COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift + DEPENDS ${DEPENDENCY} + ) + target_sources(${TARGET} PRIVATE + ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift + ) + endforeach() + endif() endfunction() # Add a new host library with the given name. @@ -53,6 +55,9 @@ function(add_swift_syntax_library name) # Create the library target. add_library(${target} ${ASHL_SOURCES}) + set_property(TARGET ${target} PROPERTY + Swift_COMPILATION_MODE "$,wholemodule,incremental>") + if(SWIFTSYNTAX_EMIT_MODULE) # Determine where Swift modules will be built and installed. set(module_dir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) @@ -104,22 +109,24 @@ function(add_swift_syntax_library name) set(module_file "${module_file}") endif() - # Touch the library and objects to workaround their mtime not being updated - # when there are no real changes (eg. a file was updated with a comment). - # Ideally this should be done in the driver, which could only update the - # files that have changed. - add_custom_command( - TARGET ${target} - POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $ "${module_base}" - COMMAND_EXPAND_LISTS - COMMENT "Update mtime of library outputs workaround") - add_custom_command( - TARGET ${target} - POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $ - COMMAND_EXPAND_LISTS - COMMENT "Update mtime of objcect files workaround") + if(NOT CMP0157_IS_NEW) + # Touch the library and objects to workaround their mtime not being updated + # when there are no real changes (eg. a file was updated with a comment). + # Ideally this should be done in the driver, which could only update the + # files that have changed. + add_custom_command( + TARGET ${target} + POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $ "${module_base}" + COMMAND_EXPAND_LISTS + COMMENT "Update mtime of library outputs workaround") + add_custom_command( + TARGET ${target} + POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $ + COMMAND_EXPAND_LISTS + COMMENT "Update mtime of objcect files workaround") + endif() set_target_properties(${target} PROPERTIES Swift_MODULE_NAME ${name}