diff --git a/src/cmake/AieCodegenIncludes.cmake b/src/cmake/AieCodegenIncludes.cmake index 2be2c9d4..e86e12e2 100644 --- a/src/cmake/AieCodegenIncludes.cmake +++ b/src/cmake/AieCodegenIncludes.cmake @@ -3,28 +3,25 @@ # SPDX-License-Identifier: MIT ############################################################################### -include(${CMAKE_CURRENT_LIST_DIR}/AieCodegenHeaders.cmake) - -function(_aie_codegen_materialize_header source dest) - file(CREATE_LINK "${source}" "${dest}" SYMBOLIC RESULT _link_result) - if(NOT _link_result EQUAL 0) - configure_file("${source}" "${dest}" COPYONLY) - endif() -endfunction() - function(aie_codegen_setup_build_include_layout) set(_inc_root "${CMAKE_CURRENT_BINARY_DIR}/include") file(MAKE_DIRECTORY "${_inc_root}/aie_codegen_inc") - aie_codegen_collect_headers(_headers) - foreach(_hdr IN LISTS _headers) - get_filename_component(_name "${_hdr}" NAME) - _aie_codegen_materialize_header("${_hdr}" "${_inc_root}/aie_codegen_inc/${_name}") - endforeach() - - _aie_codegen_materialize_header( - "${CMAKE_CURRENT_SOURCE_DIR}/aie_codegen.h" - "${_inc_root}/aie_codegen.h") + # Headers are copied at build time via a cmake -P script so that GLOB runs + # fresh on each build. Configure-time copies bake resolved paths into the + # generated build rules; stale rules cause MSB8066 failures in CI when a + # prior build directory is reused after a source-tree relocation. + add_custom_target(copy_headers ALL + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${CMAKE_CURRENT_SOURCE_DIR}/aie_codegen.h" + "${_inc_root}/aie_codegen.h" + COMMAND ${CMAKE_COMMAND} + "-DSRC_DIR=${CMAKE_CURRENT_SOURCE_DIR}" + "-DREGDB_DIR=${CMAKE_CURRENT_SOURCE_DIR}/../aie-regdb/globalparams" + "-DDST_DIR=${_inc_root}/aie_codegen_inc" + -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyHeaders.cmake" + COMMENT "Syncing headers to build include directory" + ) endfunction() function(aie_codegen_apply_include_directories target) @@ -35,4 +32,5 @@ function(aie_codegen_apply_include_directories target) $ $ ) + add_dependencies(${target} copy_headers) endfunction() diff --git a/src/cmake/CopyHeaders.cmake b/src/cmake/CopyHeaders.cmake new file mode 100644 index 00000000..cc778863 --- /dev/null +++ b/src/cmake/CopyHeaders.cmake @@ -0,0 +1,29 @@ +############################################################################### +# Copyright (C) 2022-2026 Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: MIT +############################################################################### +# Build-time script: invoked via cmake -P by the copy_headers custom target. +# Runs GLOB at build time so that paths are resolved fresh on each build rather +# than being baked into generated build rules at configure time. +# +# Expected variables (passed via -D on the cmake -P command line): +# SRC_DIR - aie-codegen/src source directory +# REGDB_DIR - aie-regdb/globalparams source directory +# DST_DIR - destination include/aie_codegen_inc directory + +foreach(_var SRC_DIR REGDB_DIR DST_DIR) + if(NOT DEFINED ${_var}) + message(FATAL_ERROR "CopyHeaders.cmake: required variable ${_var} is not defined") + endif() +endforeach() + +file(GLOB_RECURSE _hdrs + "${SRC_DIR}/*/*.h" + "${SRC_DIR}/*/*/*.h" + "${REGDB_DIR}/*.h" +) + +foreach(_hdr IN LISTS _hdrs) + get_filename_component(_name "${_hdr}" NAME) + file(COPY_FILE "${_hdr}" "${DST_DIR}/${_name}" ONLY_IF_DIFFERENT) +endforeach()