-
Notifications
You must be signed in to change notification settings - Fork 192
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
base: master
Are you sure you want to change the base?
Conversation
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.
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 eachcpm_add_subdirectory
- To avoid regressions, do you think there's an easy way we could add a simple integration test for this?
Hi @TheLartians and @threeal I too have some issues with my package, in regards to appending a module path to include(FetchContent)
FetchContent_Declare(
"rsp-cmake-scripts"
GIT_REPOSITORY "https://github.com/rsps/cmake-scripts"
GIT_TAG "43febe92df4a06a31338e380eb2dc64683f8a273" # Commit hash for now, version not yet released.
)
FetchContent_MakeAvailable("rsp-cmake-scripts")
include("rsp/debug") # Works
dump(CMAKE_MODULE_PATH) # Works But, when trying to fetch my package using CPM, any changes to CPMAddPackage(
NAME "rsp-cmake-scripts"
GIT_TAG "43febe92df4a06a31338e380eb2dc64683f8a273" # Commit hash for now, version not yet released.
# VERSION "${RSP_CMAKE_SCRIPTS_VERSION}"
GITHUB_REPOSITORY "rsps/cmake-scripts"
OPTIONS "RSP_ENABLE_ANSI true"
)
include("rsp/debug") # CMake Error: include could not find requested file: rsp/debug
dump(CMAKE_MODULE_PATH) # ...not reached Experiment A (failed)I have locally attempted to set the macro(cpm_export_variables name)
# ... previous not shown ...
# Attempt to propagate eventual appended CMAKE_MODULE_PATH paths to parent
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
endmacro() Sadly, the above change had no effect. My package's module path isn't available. Experiment BSame as "Experiment A", but with an additional modification to function(cpm_fetch_package PACKAGE DOWNLOAD_ONLY populated)
# ... previous not shown ...
set(${PACKAGE}_SOURCE_DIR
${${lower_case_name}_SOURCE_DIR}
PARENT_SCOPE
)
set(${PACKAGE}_BINARY_DIR
${${lower_case_name}_BINARY_DIR}
PARENT_SCOPE
)
# Attempt to propagate eventual appended CMAKE_MODULE_PATH paths to parent - allows
# cpm_export_variables() to propagate change upwards...
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
endfunction() This seems to work in my case, yet I'm not sure if other CPM functions need to be modified? For now, I do not see any viable work-around on how to make this work as desired. It is not uncommon for packages, libraries, ...etc, to append paths to In any case, I really hope that CPM can make this work. |
In addition to the previous comment, the problem is actually not just for appended paths to I'm not sure what a correct solution would be (I'm not a CMake expert... I'm still struggling to understand the basics). |
This pull request re-export the
CMAKE_MODULE_PATH
variable to the parent scope from theadd_subdirectory
function. This function is useful because some packages, like Catch2, export theCMAKE_MODULE_PATH
of their script files to the parent scope, as could be seen here: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: