You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
include(FetchContent) need to be call inside each subdirectory (cmake < 3.17) else it's not working.
So before the return() in CPM.cmake line 44 we can add include(FetchContent) which fix the issue.
Also, CPM_INDENT is locally defined that why there is no CPM: in front of adding package [email protected] (6.2.1) in the given example.
An (ugly ?) way to keep the prefix is to also add the following line:
if(NOT CPM_INDENT)
set(CPM_INDENT "CPM:")
endif()
Unless I missed something or something seems wrong to you, if the fix sound nice to you I can create a pull request.
Best regards,
Xavier
The text was updated successfully, but these errors were encountered:
Hey, thanks for the report! Yeah, I've assumed CPM.cmake would be included in the outermost CMakeLists, but in case like this, the outer variables go out of scope before the second subdirectory is included.
About the indent, a simpler fix might be to cache the variable at the declaration in line 133: set(CPM_INDENT "CPM:" CACHE INTERNAL ""), that way it would always be set to CPM: in the global scope.
About outer includes, how would you feel about lazily including the modules each time a functions using it? That way we couldn't pollute the outer scope and in the cached case we would have a better performance. Otherwise your solution of moving them to the top sounds like a good idea. Also I'm not sure about the performance overhead of the include so it might be negligible anyways.
I'm always be happy to receive a PR, where we could discuss the exact implementation details anyways!
To reproduce the bug with at least CPM >= 0.27.5:
Minimal structure:
CMakeLists.txt:
libA/CMakeLists.txt:
libB/CMakeLists.txt:
ERROR:
Solution
include(FetchContent)
need to be call inside each subdirectory (cmake < 3.17) else it's not working.So before the
return()
in CPM.cmake line 44 we can addinclude(FetchContent)
which fix the issue.Also,
CPM_INDENT
is locally defined that why there is noCPM:
in front ofadding package [email protected] (6.2.1)
in the given example.An (ugly ?) way to keep the prefix is to also add the following line:
Unless I missed something or something seems wrong to you, if the fix sound nice to you I can create a pull request.
Best regards,
Xavier
The text was updated successfully, but these errors were encountered: