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
cmake: fix multiple include of CURL package #11913
Conversation
Out of curiosity: how did you hit this problem? |
Failed update attempt in vcpkg:
|
vcpkg update with this change added: microsoft/vcpkg#33924 |
I see - thanks for explanation. |
@jzakrzewski should we count that as a 👍 from you? |
Frankly, I don't know if this is enough. |
OK, I checked it. Since CURLTargets.cmake is already protected against multiple calls, this fix looks OK. |
Co-authored-by: Viktor Szakats <vszakats@users.noreply.github.com>
FTR this |
FTR there is another problem, with older version of CMake:
(Found by a vcpkg CI test which CMake 3.7.2.) Choose what you want:
This can be done in another PR. |
Speaking of
Ref: #11646 |
https://cmake.org/cmake/help/latest/command/add_library.html#alias-libraries: The downside of the the INTERFACE target is that it doesn't let you read properties like an ALIAS does. |
Ping. |
Could you create a minimal build case example that reproduces this issue? We could include that in a future integration test. Tried reproducing this for libssh2 (where I added such tests earlier this year) but without success: https://github.com/libssh2/libssh2/tree/master/tests/cmake |
cmake_minimum_required(3.1)
project(test)
find_package(CURL CONFIG)
find_package(CURL CONFIG) (And even the |
FTR in the vcpkg port I already replaced the ALIAS with IMPORTED, to satisfy older versions of CMake. |
@dg0yt: Thanks for the example. My next trouble is that this is what I tried with libssh2 to reproduce this. I tried it now with curl, and strangely it runs without issues. This is with CMake 3.27.6. What might cause the difference? (Not questioning the validy of the issue, I'd just like to learn what's happening.) CMakeLists.txt: cmake_minimum_required(VERSION 3.1) # it fails with "(3.1)"
project(test)
find_package(CURL CONFIG)
find_package(CURL CONFIG)
.../curl/bld-cmake/pkg/usr/local/lib/cmake/CURL/CURLConfig.cmake: [...]
# Alias for either shared or static library
add_library(CURL::libcurl ALIAS CURL::libcurl_static) |
Sorry, the example was too short and failed for the first line. I will extend it. |
FTR after fixing the first line, the example is still exposes the error for older versions of CMake ( |
Got it, so this is only hit by older CMake versions (e.g. 3.16). Do we know which CMake version changed this behaviour? |
I currently fail to reproduce the message from the initial post, but I verified that it is in the linked vpckg CI log from the initial curl update attempt, and this was using CMake 3.27.1. I need to verify that no other package did something fishy. There is nothing more telling than a producing minimal reproducable example ;-) |
FWIW this is the canonical way to "alias" targets imported in Find Modules or CMake Packages. The drawback is loosing easy access to custom properties, but their existence should not even be known to consumers of the library (i.e., all properties required for building/linking should be exposed with But I also agree that this should be tackled in a separate PR, because the version incompatibility exists already (and is not introduced by the PR) and the PR fixes a breaking issue with any CMake project that transitively depends on cURL more than once. |
There are discussions of two issues in this thread. The fix proposed in this MR fixes issue 1, which is very easy to reproduce.
You now have an installed version of CURL in
cmake_minimum_required(VERSION 3.27)
project(curl)
set(CURL_DIR "BLAH/build/install/lib/cmake/CURL")
find_package(CURL CONFIG REQUIRED)
find_package(CURL CONFIG REQUIRED) The second
Issue 2 is totally separate as mentioned a few times in this thread |
AHA https://cmake.org/cmake/help/v3.28/policy/CMP0107.html
|
@hjmallon Thanks for your example in #12300. I re-tested, and oddly enough this issue is dependent on
Release notes of 3.18 doesn't say anything obvious to indicate this breaking change: https://cmake.org/cmake/help/latest/release/3.18.html |
https://cmake.org/cmake/help/v3.28/policy/CMP0107.html @vszakats : Look at my link above, it documents the change in behaviour EDIT: Also in release notes
|
Oh, nice find! So it is listed in the 3.18 changelog after all, in "Other Changes". |
Also extend our integration test double inclusion. It will still not catch this case, because that requires `cmake_minimum_required(VERSION 3.18)` or higher. Fixes: ``` CMake Error at .../lib/cmake/libssh2/libssh2-config.cmake:8 (add_library): add_library cannot create ALIAS target "libssh2::libssh2" because another target with the same name already exists. Call Stack (most recent call first): CMakeLists.txt:24 (find_package) CMake Error at .../lib/cmake/libssh2/libssh2-config.cmake:13 (add_library): add_library cannot create ALIAS target "Libssh2::libssh2" because another target with the same name already exists. Call Stack (most recent call first): CMakeLists.txt:24 (find_package) ``` Test to reproduce: ```cmake cmake_minimum_required(VERSION 3.27) # must be 3.18 or higher project(test) find_package(libssh2 CONFIG) find_package(libssh2 CONFIG) # fails add_executable(test main.c) target_link_libraries(test libssh2::libssh2) ``` Ref: https://cmake.org/cmake/help/latest/release/3.18.html#other-changes Ref: https://cmake.org/cmake/help/v3.18/policy/CMP0107.html Assisted-by: Kai Pastor Assisted-by: Harry Mallon Ref: curl/curl#11913 Closes #xxxx
Also extend our integration test double inclusion. It will still not catch this case, because that requires `cmake_minimum_required(VERSION 3.18)` or higher. Fixes: ``` CMake Error at .../lib/cmake/libssh2/libssh2-config.cmake:8 (add_library): add_library cannot create ALIAS target "libssh2::libssh2" because another target with the same name already exists. Call Stack (most recent call first): CMakeLists.txt:24 (find_package) CMake Error at .../lib/cmake/libssh2/libssh2-config.cmake:13 (add_library): add_library cannot create ALIAS target "Libssh2::libssh2" because another target with the same name already exists. Call Stack (most recent call first): CMakeLists.txt:24 (find_package) ``` Test to reproduce: ```cmake cmake_minimum_required(VERSION 3.18) # must be 3.18 or higher project(test) find_package(libssh2 CONFIG) find_package(libssh2 CONFIG) # fails add_executable(test main.c) target_link_libraries(test libssh2::libssh2) ``` Ref: https://cmake.org/cmake/help/latest/release/3.18.html#other-changes Ref: https://cmake.org/cmake/help/v3.18/policy/CMP0107.html Assisted-by: Kai Pastor Assisted-by: Harry Mallon Ref: curl/curl#11913 Closes #xxxx
Also extend our integration test double inclusion. It will still not catch this case, because that requires `cmake_minimum_required(VERSION 3.18)` or higher. Fixes: ``` CMake Error at .../lib/cmake/libssh2/libssh2-config.cmake:8 (add_library): add_library cannot create ALIAS target "libssh2::libssh2" because another target with the same name already exists. Call Stack (most recent call first): CMakeLists.txt:24 (find_package) CMake Error at .../lib/cmake/libssh2/libssh2-config.cmake:13 (add_library): add_library cannot create ALIAS target "Libssh2::libssh2" because another target with the same name already exists. Call Stack (most recent call first): CMakeLists.txt:24 (find_package) ``` Test to reproduce: ```cmake cmake_minimum_required(VERSION 3.18) # must be 3.18 or higher project(test) find_package(libssh2 CONFIG) find_package(libssh2 CONFIG) # fails add_executable(test main.c) target_link_libraries(test libssh2::libssh2) ``` Ref: https://cmake.org/cmake/help/latest/release/3.18.html#other-changes Ref: https://cmake.org/cmake/help/v3.18/policy/CMP0107.html Assisted-by: Kai Pastor Assisted-by: Harry Mallon Ref: curl/curl#11913 Closes #1216
Thank you all, merged now. |
Fixes errors on second `find_package(CURL)`. This is a frequent case with transitive dependencies: ``` CMake Error at ...: add_library cannot create ALIAS target "CURL::libcurl" because another target with the same name already exists. ``` Test to reproduce: ```cmake cmake_minimum_required(VERSION 3.27) # must be 3.18 or higher project(curl) set(CURL_DIR "example/lib/cmake/CURL/") find_package(CURL CONFIG REQUIRED) find_package(CURL CONFIG REQUIRED) # fails add_executable(main main.c) target_link_libraries(main CURL::libcurl) ``` Ref: https://cmake.org/cmake/help/latest/release/3.18.html#other-changes Ref: https://cmake.org/cmake/help/v3.18/policy/CMP0107.html Ref: curl#12300 Assisted-by: Harry Mallon Closes curl#11913
Fixes errors on second
find_package(CURL)
. This is a frequent case with transitive dependencies.Test to reproduce:
Ref: https://cmake.org/cmake/help/latest/release/3.18.html#other-changes
Ref: https://cmake.org/cmake/help/v3.18/policy/CMP0107.html
Ref: #12300
Assisted-by: Harry Mallon
Closes #11913