Skip to content

cmake: avoid 'target is imported but not globally visible' when consuming libcurl with old cmake - #1587

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:cm-butnot
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:cm-butnot

Conversation

@vszakats

@vszakats vszakats commented Apr 25, 2025 •

Copy link
Copy Markdown
Member

Fixes:

CMake Error at bld-libssh2/_pkg/lib/cmake/libssh2/libssh2-config.cmake:35 (add_library):
  add_library cannot create ALIAS target "libssh2::libssh2" because target
  "libssh2::libssh2_shared" is imported but not globally visible.
Call Stack (most recent call first):
  CMakeLists.txt:27 (find_package)

CMake Error at bld-libssh2/_pkg/lib/cmake/libssh2/libssh2-config.cmake:40 (add_library):
  add_library cannot create ALIAS target "Libssh2::libssh2" because target
  "libssh2::libssh2_shared" is imported but not globally visible.
Call Stack (most recent call first):
  CMakeLists.txt:27 (find_package)

tests/cmake reproducer (requires #1581):

export CMAKE_CONSUMER=/path/to/CMake-3.12.0/bin/cmake
./test.sh find_package

I don't understand what this error says, why it happens in certain CMake
versions, and why a workaround is necessary for what seems like
a standard export/consume configuration. This patch is based on internet
suggestions and other projects ending up with this workaround.

Ref: curl/curl#16973
Ref: curl/curl#17140
Cherry-picked from #1581

…ming libcurl with old cmake

Adapted from curl:

Fixes:
```
CMake Error at bld-curl/_pkg/lib/cmake/CURL/CURLConfig.cmake:62 (add_library):
  add_library cannot create ALIAS target "CURL::libcurl" because target
  "CURL::libcurl_shared" is imported but not globally visible.
Call Stack (most recent call first):
  CMakeLists.txt:39 (find_package)
```

tests/cmake reproducer (requires #16973):
```shell
export CMAKE_CONSUMER=/path/to/CMake-3.12.0/bin/cmake
./test.sh find_package
```

I don't understand what this error says, why it happens in certain CMake
versions, and why a workaround is necessary for what seems like
a standard export/consume configuration. This patch is based on internet
suggestions and other projects ending up with this workaround.

Ref: curl/curl#16973
Ref: curl/curl#17140
@vszakats vszakats closed this in a8dd509 Apr 25, 2025
@vszakats
vszakats deleted the cm-butnot branch April 25, 2025 14:45
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