Skip to content
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

Provide CMake imported targets instead of variables #6

Closed
Orphis opened this issue Sep 19, 2016 · 7 comments
Closed

Provide CMake imported targets instead of variables #6

Orphis opened this issue Sep 19, 2016 · 7 comments

Comments

@Orphis
Copy link

Orphis commented Sep 19, 2016

In modern CMake, you are not supposed to give the user a list of variables but an imported target you use directly with "target_link_libraries".
It's a bit sad to see the example requiring CMake 3.0 but using patterns from CMake 2.6 dating from the CMake stone age.

https://cmake.org/cmake/help/v3.6/command/add_library.html#imported-libraries

@ras0219-msft
Copy link
Contributor

Could you be more specific about what list of variables we're providing?

@Orphis
Copy link
Author

Orphis commented Sep 19, 2016

find_library(CPPREST_LIBRARY cpprest_2_8)
find_path(CPPREST_INCLUDE_DIR cpprest/version.h)

include_directories(${CPPREST_INCLUDE_DIR})
link_libraries(${CPPREST_LIBRARY})

You should be providing instead something like "find_package(vcpkg::cpprest_2_8 REQUIRED)" and then have people link against the target "vcpkg::cpprest_2_8".
You can generate files for find_package directly that create the imported targets for you.
The pkg-config CMake support upstream has been doing that.

@ras0219-msft
Copy link
Contributor

I've filed an issue against cpprestsdk. Thanks for bringing this up!

@Orphis
Copy link
Author

Orphis commented Sep 20, 2016

Well, that's not specific to cpprestsdk, it's first your example that isn't great, and then you don't provide a good mechanism to link the libs provided by vcpkg to the targets in our projects.

@ras0219-msft
Copy link
Contributor

ras0219-msft commented Sep 20, 2016

We do support all the normal CMake integration (find_package and so forth) for packages that provide it. For example, find_package(ZLIB) should work correctly.

Is there a package that externally supports cmake but is not being packaged correctly?

@Orphis
Copy link
Author

Orphis commented Sep 20, 2016

Well, you should then really use find_package() instead in your example and have the cpprestsdk either provide the imported targets or patch it in your ports file to add support for them.

For Zlib that would be:

find_package(ZLIB REQUIRED)
target_link_libraries(MyExecutable PRIVATE ZLIB::ZLIB)

Don't forget the PUBLIC / PRIVATE after target_link_libraries either in examples.
Don't use link_libraries, usage is not recommended as per CMake's documentation. You don't want everything to link against it, just your executable or library, and that should be explicit.

@stoperro
Copy link
Contributor

stoperro commented Apr 20, 2017

It took me a while to learn why find_package(cpprestsdk REQUIRED) doesn't work. Could somehow vcpkg provide warning if someone does it like that that this less standard way of using libraries is needed? I thought my installation was broken. I see now in Readme.md there is:

If you're using a library that does not provide CMake integration, you will need to explicitly search for the files and add them yourself using find_path() and find_library().

but I only understand it now when I found this issue... others may have a hard time to find it too.

ras0219-msft pushed a commit that referenced this issue Oct 28, 2017
Update from Microsoft master
Be-ing added a commit to Be-ing/vcpkg that referenced this issue Jan 16, 2021
GH Actions: use Azure Artifacts binary cache
strega-nil pushed a commit to strega-nil/vcpkg that referenced this issue May 5, 2021
…cheme dependencies (microsoft#6)

* [vcpkg] Fix failure to install features for non-string, non-relaxed scheme dependencies

* [vcpkg] Fix warnings
dan-shaw pushed a commit that referenced this issue Mar 31, 2022
* [wxwidgets] Fix linux build

* clean up baseline

* version

* Fix --libs output

* version

* Use system pkg-config on linux (#6)

* Use system pkg-config for linux

* Update versions

* Revert baseline changes

* Add double quotes to paths

* version

* Fix incorrect double quotes place

* version

Co-authored-by: Kai Pastor <[email protected]>
dempo93 pushed a commit to dempo93/vcpkg that referenced this issue Aug 23, 2022
Updating README.md (installation instructions)
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

No branches or pull requests

3 participants