Skip to content

Commit 85ff8ff

Browse files
committed
CMake: work around an issue with CMake Xcode generator and the Swift driver
The Swift driver does not update the mtime of the output files if the existing output files on disk are identical to the ones that are about to be written. This behavior confuses the makefiles used in CMake Xcode projects: the makefiles will not consider everything up to date after invoking the compiler. As a result, the standard library gets rebuilt multiple times during a single build. To work around this issue we touch the output files so that their mtime always gets updated.
1 parent fb6fb95 commit 85ff8ff

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

cmake/modules/SwiftSource.cmake

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,27 @@ function(_compile_swift_files dependency_target_out_var_name)
370370
set(swift_compiler_tool "${SWIFT_SOURCE_DIR}/utils/check-incremental" "${swift_compiler_tool}")
371371
endif()
372372

373+
set(outputs
374+
${SWIFTFILE_OUTPUT} "${module_file}" "${module_doc_file}"
375+
${apinote_files})
376+
377+
if(XCODE)
378+
# HACK: work around an issue with CMake Xcode generator and the Swift
379+
# driver.
380+
#
381+
# The Swift driver does not update the mtime of the output files if the
382+
# existing output files on disk are identical to the ones that are about
383+
# to be written. This behavior confuses the makefiles used in CMake Xcode
384+
# projects: the makefiles will not consider everything up to date after
385+
# invoking the compiler. As a result, the standard library gets rebuilt
386+
# multiple times during a single build.
387+
#
388+
# To work around this issue we touch the output files so that their mtime
389+
# always gets updated.
390+
set(command_touch_outputs
391+
COMMAND "${CMAKE_COMMAND}" -E touch ${outputs})
392+
endif()
393+
373394
add_custom_command_target(
374395
dependency_target
375396
${command_create_dirs}
@@ -380,9 +401,8 @@ function(_compile_swift_files dependency_target_out_var_name)
380401
"${line_directive_tool}" "${source_files}" --
381402
"${swift_compiler_tool}" "${main_command}" ${swift_flags}
382403
${output_option} "${source_files}"
383-
OUTPUT
384-
${SWIFTFILE_OUTPUT} "${module_file}" "${module_doc_file}"
385-
${apinote_files}
404+
${command_touch_outputs}
405+
OUTPUT ${outputs}
386406
DEPENDS
387407
${swift_compiler_tool_dep}
388408
${source_files} ${SWIFTFILE_DEPENDS}

0 commit comments

Comments
 (0)