-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add CMake package config #36
base: master
Are you sure you want to change the base?
Conversation
c61aaba
to
d86e492
Compare
Ping @jpihl @mortenvp @techbech @loglund |
Hi @globberwops, Sorry for the radio silence and thanks for your extensive perseverance 👍 Non of us are very familiar with vcpkg not do we understand the need for your changes in the cmake file. Would you care to elaborate on the motivation for the changes? All the best Jeppe |
Hi @jpihl, no worries! Thanks for your reply. These changes are only loosely related to vcpkg. Once installed, CMake will be able to find the file vcpkg is just one of the package managers that rely on CMake to provide package config files. I hope that helps. Cheers, |
Thanks, that cleared up a few things. |
CMakeLists.txt
Outdated
|
||
# Define library | ||
add_library(recycle INTERFACE) | ||
target_compile_features(recycle INTERFACE cxx_std_14) | ||
target_include_directories(recycle INTERFACE src/) | ||
target_include_directories(recycle INTERFACE $<BUILD_INTERFACE:src> $<INSTALL_INTERFACE:include>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between this and the original?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The include path in the BUILD_INTERFACE
is used during the build of this project, and the include path in the INSTALL_INTERFACE
will be used by downstream projects that use an installed version of this project.
During the build of this project, the headers are located in src
, but they will be installed in <INSTALL_PREFIX>/include
(according to GNU convention).
This is why we have to differentiate and tell CMake, where to find the headers in both cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so if the library is being used as a CMake Package, INSTALL_INTERFACE
will be used, but if it's being used with, e.g.,
add_subdirectory
or FetchContent_Declare
, BUILD_INTERFACE
will be used?
Is this correctly understood?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our internal projects, we use add_subdirectory
for dependencies. I just tried using these changes, and I got this error:
[cmake] CMake Error in resolve_symlinks/slide/CMakeLists.txt:
[cmake] Target "recycle" contains relative path in its
[cmake] INTERFACE_INCLUDE_DIRECTORIES:
[cmake]
[cmake] "src"
[cmake]
[cmake]
[cmake] -- Generating done
[cmake] CMake Generate step failed. Build files cannot be regenerated correctly.
I search a little and found this, so it seems the BUILD_INTERFACE
needs to have ${CMAKE_CURRENT_SOURCE_DIR}
prepended. At least that fixed the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @globberwops; if you make this change, we should be able to merge this one finally ;-)
Cheers!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jpihl Done! Thanks for the reminder :)
install( | ||
EXPORT recycle-targets | ||
DESTINATION ${RECYCLE_CONFIG_DIR} | ||
NAMESPACE steinwurf::) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need help understanding the purpose of lines 24-29.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call will create the file recycle-targets.cmake
in the dir ${RECYCLE_CONFIG_DIR}
.
The targets defined in this file will be prefixed with steinwurf::
.
Downstream projects can then link these targets e.g.
find_package(recycle)
target_link_libraries(<TARGET> PUBLIC steinwurf::recycle)
cmake/recycle-config.cmake.in | ||
"${CMAKE_CURRENT_BINARY_DIR}/recycle-config.cmake" | ||
INSTALL_DESTINATION ${RECYCLE_CONFIG_DIR} | ||
NO_CHECK_REQUIRED_COMPONENTS_MACRO) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the NO_CHECK_REQUIRED_COMPONENTS_MACRO
option set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, configure_package_config_file
will put a macro into the package config file that can be used to check, if all components of the package can be found, e.g.
find_package(Boost COMPONENTS regex log)
Since this project does not have any components, we disable the macro.
d86e492
to
edd76bc
Compare
edd76bc
to
27ab859
Compare
Fixes #35