Relevant to聽several ports which required聽rewriting their buildsystems from scratch in CMake (#603).
Because Vcpkg has聽opinions about how packages should be laid out and linked, we have all the聽information needed to generate general-purpose CMake configure scripts for every library we聽package (even those that don't use CMake!).聽This would greatly simplify聽the job of maintainers who聽need to rewrite聽library buildsystems in CMake to better support聽our configuration聽options (UWP, static linking the CRT,聽etc) because they would be able to rely on find_package() to do the heavy lifting.
Now, it is certainly not our intention to permanently fork libraries, so if a library _did_ decide to start supplying its聽own native聽CMake configure scripts, we would聽have to make (breaking!) changes to switch.
I second that. In my own package manager, that I've been developing for my company as an internal project, I do exactly that. Furthermore, I leverage the CMake versioning system to be able to provide several versions of the same library at the same time. This often requires the port maintainer to patch existing CMake scripts in order to include the required actions for creating config and version files, as more often than not the original CMake scripts fall into old-style CMake coding (based on the assumption that some Find* scripts will be present on the user machine instead of proper config scripts). But that's a one-time effort that greatly pays off downstream, and - as the OP writes - the package manager has a lot of information that can be leveraged to produce or help producing config files automatically (I do that at several levels in my package manager).
Also, I'd stress on the importance of creating INTERFACE targets for header-only libraries (such as glm), so that dependencies can still be checked.
In my package manager, there is no one common include directory for installed packages: they all live in their own directory (otherwise header files from different versions of the same library would clash). This implies that properly-formed CMake files are a strict requirement, and features like config/version files, INTERFACEtargets, include directories specified via target_include_directories() must always be present (either in the original CMake files or in port-specific patches). As I said before, this requires an effort from the port maintainer, but the package user then is presented with an uniform and consistent interface for finding and using libraries, even header-only ones.
we would have to make (breaking!) changes to switch.
What would break and why?
What would / should a Hello World library cmake file look like?
IMO it should be cross-platform and not be tied to vcpkg.
@OlafvdSpek Definitely! We want to integrate with CMake in聽a respectful, native way which聽does _not_聽encourage vcpkg-specific behavior in聽your project (like requiring a include(vcpkg_libraries)).聽The official CMake way to include prebuilt downstream projects is聽via a simple find_package(X), so that's what we want projects to use.
The problem is聽that there are聽several choices that can be聽made when adding find_package() support, such as the聽casing of the package name聽and the聽exact spelling and arrangement of the libraries. Many libraries opt for a聽flat name, so you can do聽target_link_libraries(hello sqlite3), but聽others choose (in line with the official聽CMake guidance) to use namespaces (target_link_libraries(hello Sqlite3::sqlite)).
If the upstream package decides to add聽official, native CMake support, it's very聽possible they will choose a naming scheme that conflicts with our聽generated聽scheme.聽We聽want to聽support cross-platform projects, so we聽should switch聽to the upstream scheme -- but that will cause a break for current Vcpkg users. Providing both _may_ be possible, but we'd really prefer to not to do that in the longer term.
@marcojez聽That's awesome to hear! I'd definitely appreciate your expertise if we go down this path 馃憤. For a few reasons detailed聽in聽many other issues (primarily consistency as the deps graph grows complex), we聽explicitly provide exactly one version of each library, so聽our task may be even easier than what you've already accomplished.
As a side conversation: are聽you聽only targeting聽Windows with that system or is it Linux/osx hosted?聽I'd聽love to have a chat about it over mail to make sure we haven't missed some really important features in Vcpkg([email protected])!
Ideally #include <zlib.h> would be enough and you'd not have to worry about anything else..
IMO find_package(), pkg-config and friends make build scripts more complex and more fragile then they need to be, ultimately making the sum of everything less flexible.
I don't see a problem with generating config files with target names that might become outdated. First of all, everyone can decide on his own if he wants to use them or not. Second, such a break can easily be fixed. Third, even after a library starts providing native cmake support, the vcpkg version could be kept for some time after as an alias - preferably emitting a warning.
At the very least, it should be possible to querey vcpkg on how to use a particular port from cmake: whether to use find_package or find_library/find_path and what package / header name to look for.
I think we already do this for ports where possible, so this decision is "resolved" in favor of "yes, we're doing that".
Most helpful comment
At the very least, it should be possible to querey vcpkg on how to use a particular port from cmake: whether to use
find_packageorfind_library/find_pathand what package / header name to look for.