fix(cmake): require project() before find_package(XRT) in example templates#3051
Merged
Conversation
…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>
andrej
approved these changes
May 7, 2026
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 |
Collaborator
There was a problem hiding this comment.
Do you know what that hard-wired XRT path is and why it is required?
Collaborator
Author
There was a problem hiding this comment.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
common.cmake'sfind_package(XRT)was being called beforeproject()in example templates, causingadd_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.mlir_aie_init_example()macro — 53 templates each drop ~25 lines.FATAL_ERRORguard at the top ofcommon.cmakeso the bug class can't regress silently. Alignedcmake_minimum_requiredat 3.30 across templates.Fixes #3048