Skip to content

fix(cmake): avoid duplicate coretrace logger target #72

@SizzleUnrlsd

Description

@SizzleUnrlsd

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:

coretrace_logger

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions