Skip to content

fix(cmake): require project() before find_package(XRT) in example templates#3051

Merged
hunhoffe merged 4 commits into
Xilinx:mainfrom
hunhoffe:add-library-bug
May 8, 2026
Merged

fix(cmake): require project() before find_package(XRT) in example templates#3051
hunhoffe merged 4 commits into
Xilinx:mainfrom
hunhoffe:add-library-bug

Conversation

@hunhoffe
Copy link
Copy Markdown
Collaborator

@hunhoffe hunhoffe commented May 6, 2026

Summary

  • common.cmake's find_package(XRT) was being called before project() in example templates, causing add_library(... SHARED IMPORTED) to fail on cmake 4.3.2 / Ubuntu 26.04 ("does not support dynamic linking") and silently downgrade SHARED→STATIC on older cmake/XRT.
  • Hoisted the pre-project boilerplate (WSL detect, gcc-13 fallback, ProjectName/currentTarget setup) into a shared mlir_aie_init_example() macro — 53 templates each drop ~25 lines.
  • Added a FATAL_ERROR guard at the top of common.cmake so the bug class can't regress silently. Aligned cmake_minimum_required at 3.30 across templates.

Fixes #3048

hunhoffe and others added 2 commits May 6, 2026 13:39
…plates

common.cmake's find_package(XRT) loaded xrt-targets.cmake, which runs
add_library(... SHARED IMPORTED) before any project() had been called.
On cmake 4.3.2 / Ubuntu 26.04 this fails with "does not support dynamic
linking"; on older cmake/XRT it silently downgrades SHARED to STATIC.

Hoist the per-example pre-project boilerplate (WSL detect, gcc-13
fallback, ProjectName/currentTarget setup) into a shared
mlir_aie_init_example() macro so 53 templates can drop ~25 lines each
and the ordering rule lives in one place. Add a FATAL_ERROR guard at
the top of common.cmake that fires if PROJECT_NAME isn't set, so the
bug class can't return silently. Also align cmake_minimum_required at
3.30 across all example templates (three outliers were on 3.1 or 3.20).

Fixes Xilinx#3048

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
@hunhoffe hunhoffe added this to the IRON 1.3.2 milestone May 6, 2026
@hunhoffe hunhoffe marked this pull request as ready for review May 6, 2026 23:30
Copy link
Copy Markdown
Collaborator

@andrej andrej left a comment

Choose a reason for hiding this comment

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

Looks great to me!

Comment on lines +16 to +17
# event_trace uses an example-specific TARGET_NAME and a hard-wired XRT
# install path. Setting these BEFORE mlir_aie_init_example() / common.cmake
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.

Do you know what that hard-wired XRT path is and why it is required?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good question! It's something that should be handled by makefile common, and not duplicated here. I'm adding another commit to address this.

common.cmake's XRT auto-detection already falls back to the same
/opt/xilinx/xrt and C:/Technical/... paths, so re-setting them in
event_trace's own CMakeLists.txt was duplication, not an
example-specific requirement. Only the custom TARGET_NAME genuinely
needs to be set before mlir_aie_init_example().

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
@hunhoffe hunhoffe added this pull request to the merge queue May 7, 2026
Merged via the queue into Xilinx:main with commit 47f1009 May 8, 2026
71 checks passed
@hunhoffe hunhoffe deleted the add-library-bug branch May 8, 2026 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ADD_LIBRARY called with SHARED option but the target platform does not support dynamic linking.

2 participants