Skip to content

Conversation

perazz
Copy link

@perazz perazz commented Oct 6, 2025

Summary

Add if(NOT TARGET) guards around add_library calls to prevent conflicts when the target already exists.

Context

After PR fortran-lang#1033, stdlib automatically creates namespaced ALIAS targets (e.g., fortran_stdlib::stdlib). The example code in Findtest-drive.cmake that users copy for integrating stdlib via FetchContent was trying to create these same targets, causing CMake errors.

Changes

  • Added guards in three locations (pkgconf, subproject, fetch methods)
  • Prevents duplicate target creation while maintaining backward compatibility

Testing

This allows the FetchContent pattern to work correctly with stdlib after fortran-lang#1033 without requiring users to manually remove the add_library lines.

Fixes the issue described in fortran-lang#1036

Add if(NOT TARGET) guards around add_library calls to prevent conflicts
when the target already exists (e.g., when using stdlib with FetchContent
after PR fortran-lang#1033 which adds ALIAS targets automatically).

This allows users to use the Find module pattern with libraries that
already provide namespaced ALIAS targets.
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.

1 participant