Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Draft
jvdp1 wants to merge4 commits intofortran-lang:master
base:master
Choose a base branch
Loading
fromjvdp1:fix_cmake

Conversation

@jvdp1
Copy link
Member

Following the changes in#1033, the following Cmake directives are broken:

...  if("${method}"STREQUAL"fetch")    message(STATUS"Retrieving${_lib} from${_url}")    include(FetchContent)    FetchContent_Declare("${_lib}"      GIT_REPOSITORY"${_url}"      GIT_TAG"HEAD"      )    FetchContent_MakeAvailable("${_lib}")    add_library("${_lib}::${_lib}"INTERFACEIMPORTED)    target_link_libraries("${_lib}::${_lib}"INTERFACE"${_lib}")# We need the module directory in the subproject before we finish the configure stage    FetchContent_GetProperties("${_lib}" SOURCE_DIR"${_pkg}_SOURCE_DIR")    FetchContent_GetProperties("${_lib}" BINARY_DIR"${_pkg}_BINARY_DIR")    if(NOTEXISTS"${${_pkg}_BINARY_DIR}/mod_files")      make_directory("${${_pkg}_BINARY_DIR}/mod_files")    endif()    break()  endif()...

Commenting out the directiveadd_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?

@jvdp1jvdp1 requested a review fromperazzOctober 5, 2025 13:48
@jvdp1
Copy link
MemberAuthor

@perazz@eduardz1

@eduardz1
Copy link
Contributor

Following the changes in#1033, the following Cmake directives are broken:

...  if("${method}"STREQUAL"fetch")    message(STATUS"Retrieving${_lib} from${_url}")    include(FetchContent)    FetchContent_Declare("${_lib}"      GIT_REPOSITORY"${_url}"      GIT_TAG"HEAD"      )    FetchContent_MakeAvailable("${_lib}")    add_library("${_lib}::${_lib}"INTERFACEIMPORTED)    target_link_libraries("${_lib}::${_lib}"INTERFACE"${_lib}")# We need the module directory in the subproject before we finish the configure stage    FetchContent_GetProperties("${_lib}" SOURCE_DIR"${_pkg}_SOURCE_DIR")    FetchContent_GetProperties("${_lib}" BINARY_DIR"${_pkg}_BINARY_DIR")    if(NOTEXISTS"${${_pkg}_BINARY_DIR}/mod_files")      make_directory("${${_pkg}_BINARY_DIR}/mod_files")    endif()    break()  endif()...

Commenting out the directiveadd_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?

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
Copy link
MemberAuthor

I won't be able to test it in the next two weeks

Thank you for your quick answer. It is not urgent on my side

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.

Only the secondadd_library was added in#1033, as far as I can see. So, I wonder why it was added there (there might be a reason that I am not aware of).

I see that the code you wrote is probably part of some function or some automated installation.

Indeed, it is based on thestdlibFindtest-drive.cmake

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()...

It is also a possibility. But I will have to adapt many projects :( Of course, it is possible. But in that case, should thestdlibREADME be adapted?

perazz reacted with thumbs up emoji

@eduardz1
Copy link
Contributor

I won't be able to test it in the next two weeks

Thank you for your quick answer. It is not urgent on my side

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.

Only the secondadd_library was added in#1033, as far as I can see. So, I wonder why it was added there (there might be a reason that I am not aware of).

I see that the code you wrote is probably part of some function or some automated installation.

Indeed, it is based on thestdlibFindtest-drive.cmake

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()...

It is also a possibility. But I will have to adapt many projects :( Of course, it is possible. But in that case, should thestdlibREADME be adapted?

I didn't notice how it was done in inFindtest-drive.cmake, sorry! I added the alias because it makes it more seamless to integrate with FetchContent, removing the need to create the target manually, but you're right that theFindtest-drive.cmake should have been updated as well. Can somebody do that? Otherwise I can open a PR to fix it in about 2/3 weeks.

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 yourGIT_TAG so you don't risk accidentally breaking the build

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
Co-authored-by: Federico Perini <federico.perini@gmail.com>
@jvdp1jvdp1 marked this pull request as draftNovember 8, 2025 13:47
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@perazzperazzperazz approved these changes

Assignees

@eduardz1eduardz1

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@jvdp1@eduardz1@perazz

[8]ページ先頭

©2009-2025 Movatter.jp