-
Notifications
You must be signed in to change notification settings - Fork 197
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 our terms of service and privacy 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?
Conversation
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 (NOT TARGET "${_lib}::{_lib}")
add_library("${_lib}::${_lib}" INTERFACE IMPORTED)
target_link_libraries("${_lib}::${_lib}" INTERFACE "${_lib}")
endif()
... |
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 |
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}" INTERFACE IMPORTED)
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 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.
Guard add_library calls in Findtest-drive.cmake
Co-authored-by: Federico Perini <[email protected]>
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?