- Notifications
You must be signed in to change notification settings - Fork205
CMake: isssue with an "add_library" added in #1033#1036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
jvdp1 commentedOct 5, 2025
eduardz1 commentedOct 5, 2025
I won't be able to test it in the next two weeks but you should be able to remove the two lines "add_library" and "target_link_libraries", the error is due to the target existing already. I see that the code you wrote is probably part of some function or some automated installation. In case you still want to keep these two lines for some repositories then change it to something like ...if (NOTTARGET"${_lib}::{_lib}") add_library("${_lib}::${_lib}"INTERFACEIMPORTED) target_link_libraries("${_lib}::${_lib}"INTERFACE"${_lib}")endif()... |
jvdp1 commentedOct 5, 2025
Thank you for your quick answer. It is not urgent on my side
Only the second
Indeed, it is based on the
It is also a possibility. But I will have to adapt many projects :( Of course, it is possible. But in that case, should the |
eduardz1 commentedOct 5, 2025
I didn't notice how it was done in in Maybe I wasn't clear enough before but if you use this code only for the stdlib you can simply remove these lines from your code add_library("${_lib}::${_lib}"INTERFACEIMPORTED)target_link_libraries("${_lib}::${_lib}"INTERFACE"${_lib}") Also it's not strictly related but I suggest using a commit hash for your |
Add if(NOT TARGET) guards around add_library calls to prevent conflictswhen the target already exists (e.g., when using stdlib with FetchContentafter PRfortran-lang#1033 which adds ALIAS targets automatically).This allows users to use the Find module pattern with libraries thatalready provide namespaced ALIAS targets.
Guard add_library calls in Findtest-drive.cmake
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Federico Perini <federico.perini@gmail.com>
Following the changes in#1033, the following Cmake directives are broken:
Commenting out the directive
add_library(${PROJECT_NAME}::${target_name} ALIAS ${target_name})introduced in#1033 solved my issue. However, I am not an experxt in CMake. So, is this required?