Skip to content
Merged
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()
43 changes: 43 additions & 0 deletions src/cmake/CopyHeaders.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
###############################################################################
# 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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this also check the dirs exist, not just that the vars are defined? aie-regdb is often an uninitialized submodule; when it's missing the GLOB silently returns nothing and you get a
confusing missing-header error later. A message(WARNING) on NOT IS_DIRECTORY would do.

if(NOT DEFINED ${_var})
message(FATAL_ERROR "CopyHeaders.cmake: required variable ${_var} is not defined")
endif()
endforeach()

foreach(_dir SRC_DIR REGDB_DIR)
if(NOT IS_DIRECTORY "${${_dir}}")
message(WARNING "CopyHeaders.cmake: ${_dir}=\"${${_dir}}\" is not a directory; "
"headers from this location will be missing. "
"Is the submodule initialized?")
endif()
endforeach()

# Reuse the canonical header-dir list from AieCodegenHeaders.cmake so that
# build-time copies and install-time copies always cover exactly the same set.
include("${CMAKE_CURRENT_LIST_DIR}/AieCodegenHeaders.cmake")

set(_hdrs "")
foreach(_dir IN LISTS _AIE_CODEGEN_HEADER_DIRS)
file(GLOB _dir_hdrs "${SRC_DIR}/${_dir}/*.h")
list(APPEND _hdrs ${_dir_hdrs})
endforeach()
file(GLOB _regdb_hdrs "${REGDB_DIR}/*.h")
list(APPEND _hdrs ${_regdb_hdrs})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now a second definition of "which headers are public" — AieCodegenHeaders.cmake still owns _AIE_CODEGEN_HEADER_DIRS and still drives the install path. They match today (I
checked: 68 headers each), but a future src/newdir/foo.h would land in the build include dir and not in the installed package — builds in-tree, breaks against the installed SDK.

Can we reuse the existing list?

include("${CMAKE_CURRENT_LIST_DIR}/AieCodegenHeaders.cmake")
set(_hdrs "")
foreach(_dir IN LISTS _AIE_CODEGEN_HEADER_DIRS)
file(GLOB _d "${SRC_DIR}/${_dir}/.h")
list(APPEND _hdrs ${_d})
endforeach()
file(GLOB _r "${REGDB_DIR}/
.h")
list(APPEND _hdrs ${_r})

Use the variable, not aie_codegen_collect_headers() — that reads CMAKE_CURRENT_SOURCE_DIR, which is wrong under cmake -P. Keeping the recursive glob is fine too, as long as the install
path switches to it as well.

foreach(_hdr IN LISTS _hdrs)
get_filename_component(_name "${_hdr}" NAME)
file(COPY_FILE "${_hdr}" "${DST_DIR}/${_name}" ONLY_IF_DIFFERENT)
endforeach()
Loading