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

Re-export CMAKE_MODULE_PATH #532

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

threeal
Copy link
Contributor

@threeal threeal commented Jan 14, 2024

This pull request re-export the CMAKE_MODULE_PATH variable to the parent scope from the add_subdirectory function. This function is useful because some packages, like Catch2, export the CMAKE_MODULE_PATH of their script files to the parent scope, as could be seen here:

image

While this implementation may be somewhat unconventional and a bit hacky, I don't know of any better ways to solve this issue. It allows script files to be directly used instead of having to delve deep into the project source files. Previously, if we wanted to use the catch_discover_tests function with Catch2, we had to do the following:

CPMAddPackage("gh:catchorg/[email protected]")
include("${Catch2_SOURCE_DIR}/extras/Catch.cmake")

Copy link
Member

@TheLartians TheLartians left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey thanks for the PR, I wasn't aware of this mechanism in packages! I don't see how this can break anything, so in general the implementation seems fine. Some ideas for improvement:

  • Can you add a comment in cpm_add_subdirectory explaining why the modules are exported to the parent scope there?
  • Would it be possible to move the parent scope export of the module path to the cpm_export_variables macro? That way we don't need to remember to call it after each cpm_add_subdirectory
  • To avoid regressions, do you think there's an easy way we could add a simple integration test for this?

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.

2 participants