cmake: allow users to define CMAKE_FIND_ROOT_PATH_MODE_XXX #7819
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
I'm opening this PR to solve an issue I have with my setup, here is a short summary:
I'm using Conan at work to manage C++ dependencies, and we are trying to cross-build to WebAssembly with Emscripten. To do so, I created a "Toolchain package" which sets correct flags automatically for consumers of this package.
For CMake builds, I simply exposed the
CMAKE_TOOLCHAIN_FILE
to point toEmscripten.cmake
.The thing is
find_package
now fails to find any dependency, due to theCMAKE_FIND_ROOT_PATH_MODE_PACKAGE
set toONLY
.While this is a valid behavior for regular CMake use-case, it is quite inconvenient for us, since Conan packages are all located in different folders, but are still found easily with
CMAKE_PREFIX_PATH
being set with all the package folders' paths. However,ONLY
prevents it from working, and I'd like to set everyMODE_XXX
setting toBOTH
.So I simply mimicked what's done in the Android NDK's toolchain file and added some if/endif guards around each
set()
. It allows users to specify a different value if they need. This works great for us when cross-building to Android with Conan.Note:
I first tried to simply include Emscripten's Toolchain from a custom toolchain file, and reset those variables. However, the
CMakeSystemSpecificInformation.cmake
includesEmscripten.cmake
right before processing the customerCMakeLists.txt
and thus the variables are overriden with the default values.