Skip to content
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
34 changes: 16 additions & 18 deletions src/cmake/AieCodegenIncludes.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -35,4 +32,5 @@ function(aie_codegen_apply_include_directories target)
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/aie_codegen_inc>
)
add_dependencies(${target} copy_headers)
endfunction()
29 changes: 29 additions & 0 deletions src/cmake/CopyHeaders.cmake
Original file line number Diff line number Diff line change
@@ -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()
Loading