Problem
The CMake configuration fails with LLVM 20 when coretrace-stack-analyzer loads coretrace-compiler, then also loads coretrace-log directly.
Observed error:
add_library cannot create target "coretrace_logger" because another target
with the same name already exists.
Reproduction
From build/:
cmake .. \
-DLLVM_DIR=/opt/homebrew/opt/llvm@20/lib/cmake/llvm/ \
-DClang_DIR=/opt/homebrew/opt/llvm@20/lib/cmake/clang \
-DUSE_SHARED_LIB=OFF \
-DENABLE_DEBUG_ASAN=OFF \
-DCMAKE_OSX_DEPLOYMENT_TARGET=15.0 \
-DBUILD_ANALYZER_UNIT_TESTS=OFF \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
Cause
coretrace-compiler already imports coretrace-log with:
FetchContent_Declare(coretrace_logger ...)
The stack analyzer then imports the same repository again in cmake/logger/coretraceLog.cmake, but under the name coretrace-logger.
Even though the FetchContent names differ, the subproject creates the same logical CMake target:
This violates CMake policy CMP0002, which requires logical target names to be globally unique.
Expected Behavior
CMake should reuse an existing logger target if it has already been created by a transitive dependency.
Proposed Fix
Make cmake/logger/coretraceLog.cmake idempotent:
- if
coretrace::logger already exists, do nothing;
- if
coretrace_logger already exists, create the coretrace::logger alias if needed;
- otherwise import
coretrace-log with the canonical FetchContent name coretrace_logger.
Architecture Rationale
This keeps a single logger instance in the CMake dependency graph, avoids hardcoded _deps paths, and does not patch external dependencies.
The fix belongs in the CMake integration layer because the failure is caused by duplicate dependency registration, not by LLVM 20 or by source-level C++ behavior.
Acceptance Criteria
- The reproduction CMake command passes with LLVM 20.
cmake --build . completes successfully.
- No test files are modified.
- The build no longer creates or requires duplicate
coretrace-log FetchContent directories.
Suggested Commit
fix(cmake): reuse existing coretrace logger target
Problem
The CMake configuration fails with LLVM 20 when
coretrace-stack-analyzerloadscoretrace-compiler, then also loadscoretrace-logdirectly.Observed error:
Reproduction
From
build/:Cause
coretrace-compileralready importscoretrace-logwith:FetchContent_Declare(coretrace_logger ...)The stack analyzer then imports the same repository again in
cmake/logger/coretraceLog.cmake, but under the namecoretrace-logger.Even though the FetchContent names differ, the subproject creates the same logical CMake target:
coretrace_loggerThis violates CMake policy CMP0002, which requires logical target names to be globally unique.
Expected Behavior
CMake should reuse an existing logger target if it has already been created by a transitive dependency.
Proposed Fix
Make
cmake/logger/coretraceLog.cmakeidempotent:coretrace::loggeralready exists, do nothing;coretrace_loggeralready exists, create thecoretrace::loggeralias if needed;coretrace-logwith the canonical FetchContent namecoretrace_logger.Architecture Rationale
This keeps a single logger instance in the CMake dependency graph, avoids hardcoded
_depspaths, and does not patch external dependencies.The fix belongs in the CMake integration layer because the failure is caused by duplicate dependency registration, not by LLVM 20 or by source-level C++ behavior.
Acceptance Criteria
cmake --build .completes successfully.coretrace-logFetchContent directories.Suggested Commit