Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CMake] Enable CMP0157 NEW if available #2856

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
59 changes: 33 additions & 26 deletions cmake/modules/AddSwiftHostLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 "$<IF:$<CONFIG:Release,RelWithDebInfo>,wholemodule,incremental>")

if(SWIFTSYNTAX_EMIT_MODULE)
# Determine where Swift modules will be built and installed.
set(module_dir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
Expand Down Expand Up @@ -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 $<TARGET_FILE:${target}> "${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 $<TARGET_OBJECTS:${target}>
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 $<TARGET_FILE:${target}> "${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 $<TARGET_OBJECTS:${target}>
COMMAND_EXPAND_LISTS
COMMENT "Update mtime of objcect files workaround")
endif()

set_target_properties(${target} PROPERTIES
Swift_MODULE_NAME ${name}
Expand Down