-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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 #76587
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
include(macCatalystUtils) | ||
|
||
# Workaround a cmake bug, see the corresponding function in swift-syntax | ||
function(force_add_dependencies TARGET) | ||
foreach(DEPENDENCY ${ARGN}) | ||
string(REGEX REPLACE [<>:\"/\\|?*] _ sanitized ${DEPENDENCY}) | ||
|
@@ -16,12 +15,18 @@ endfunction() | |
function(force_target_link_libraries TARGET) | ||
target_link_libraries(${TARGET} ${ARGN}) | ||
|
||
cmake_parse_arguments(ARGS "PUBLIC;PRIVATE;INTERFACE" "" "" ${ARGN}) | ||
force_add_dependencies(${TARGET} ${ARGS_UNPARSED_ARGUMENTS}) | ||
if(NOT CMP0157_IS_NEW) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't this get fixed in 3.26 or something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really sure, tbh I didn't tried just removing this without enabling Is just checking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed the missing dependency edge on the swiftmodule here: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/8084. |
||
# Workaround a cmake bug, see the corresponding function in swift-syntax | ||
cmake_parse_arguments(ARGS "PUBLIC;PRIVATE;INTERFACE" "" "" ${ARGN}) | ||
force_add_dependencies(${TARGET} ${ARGS_UNPARSED_ARGUMENTS}) | ||
endif() | ||
endfunction() | ||
|
||
# Add compile options shared between libraries and executables. | ||
function(_add_host_swift_compile_options name) | ||
set_property(TARGET ${name} PROPERTY | ||
Swift_COMPILATION_MODE "$<IF:$<CONFIG:Release,RelWithDebInfo>,wholemodule,incremental>") | ||
|
||
# Avoid introducing an implicit dependency on the string-processing library. | ||
if(SWIFT_SUPPORTS_DISABLE_IMPLICIT_STRING_PROCESSING_MODULE_IMPORT) | ||
target_compile_options(${name} PRIVATE | ||
|
@@ -296,14 +301,16 @@ function(add_pure_swift_host_library name) | |
# NOTE: workaround for CMake not setting up include flags. | ||
INTERFACE_INCLUDE_DIRECTORIES ${module_dir}) | ||
|
||
# Workaround to touch the library and its objects so that we don't | ||
# continually rebuild (again, see corresponding change in swift-syntax). | ||
add_custom_command( | ||
TARGET ${name} | ||
POST_BUILD | ||
COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $<TARGET_FILE:${name}> $<TARGET_OBJECTS:${name}> "${module_file}" | ||
COMMAND_EXPAND_LISTS | ||
COMMENT "Update mtime of library outputs workaround") | ||
if(NOT CMP0157_IS_NEW) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
# Workaround to touch the library and its objects so that we don't | ||
# continually rebuild (again, see corresponding change in swift-syntax). | ||
add_custom_command( | ||
TARGET ${name} | ||
POST_BUILD | ||
COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $<TARGET_FILE:${name}> $<TARGET_OBJECTS:${name}> "${module_file}" | ||
COMMAND_EXPAND_LISTS | ||
COMMENT "Update mtime of library outputs workaround") | ||
endif() | ||
|
||
# Downstream linking should include the swiftmodule in debug builds to allow lldb to | ||
# work correctly. Only do this on Darwin since neither gold (currently used by default | ||
|
@@ -439,24 +446,26 @@ function(add_pure_swift_host_tool name) | |
"SHELL:-Xlinker --build-id=sha1") | ||
endif() | ||
|
||
# Workaround to touch the library and its objects so that we don't | ||
# continually rebuild (again, see corresponding change in swift-syntax). | ||
add_custom_command( | ||
TARGET ${name} | ||
POST_BUILD | ||
COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $<TARGET_FILE:${name}> $<TARGET_OBJECTS:${name}> | ||
COMMAND_EXPAND_LISTS | ||
COMMENT "Update mtime of executable outputs workaround") | ||
|
||
# Even worse hack - ${name}.swiftmodule is added as an output, even though | ||
# this is an executable target. Just touch it all the time to avoid having | ||
# to rebuild it every time. | ||
add_custom_command( | ||
TARGET ${name} | ||
POST_BUILD | ||
COMMAND "${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/${name}.swiftmodule" | ||
COMMAND_EXPAND_LISTS | ||
COMMENT "Update mtime of executable outputs workaround") | ||
if(NOT CMP0157_IS_NEW) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
# Workaround to touch the library and its objects so that we don't | ||
# continually rebuild (again, see corresponding change in swift-syntax). | ||
add_custom_command( | ||
TARGET ${name} | ||
POST_BUILD | ||
COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $<TARGET_FILE:${name}> $<TARGET_OBJECTS:${name}> | ||
COMMAND_EXPAND_LISTS | ||
COMMENT "Update mtime of executable outputs workaround") | ||
|
||
# Even worse hack - ${name}.swiftmodule is added as an output, even though | ||
# this is an executable target. Just touch it all the time to avoid having | ||
# to rebuild it every time. | ||
add_custom_command( | ||
TARGET ${name} | ||
POST_BUILD | ||
COMMAND "${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/${name}.swiftmodule" | ||
COMMAND_EXPAND_LISTS | ||
COMMENT "Update mtime of executable outputs workaround") | ||
endif() | ||
|
||
if(NOT APSHT_SWIFT_COMPONENT STREQUAL no_component) | ||
add_dependencies(${APSHT_SWIFT_COMPONENT} ${name}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of setting this variable, we should probably use
cmake_policy(GET...)
at the locations where we are querying for it so that it can't get out of sync and there's only one source of truth.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't use
cmake_policy(GET...)
because it would require a temporary variable.Is there a way to check the value in
if(...)
condition?