[CMake] Module path contamination when including Magic Leap SDK

Hi,

I was having difficulties locating some third-party libraries with CMake. It took me some time to find that the problem arose since I’ve included Magic Leap SDK in my project.

Long story short: Magic Leap SDK’s root find package module file ENV{MLSDK}/cmake/FindMagicLeap.cmakeincorrectly overwrites the CMAKE_MODULE_PATH variable. Indeed, line 105 (for Magic Leap SDK v1.12.0) reads as follows:

set(CMAKE_MODULE_PATH "${FOUND_MLSDK}/cmake/")

The CMAKE_MODULE_PATH variable is a list of paths, not a single path. It’s set by the consumer project. Unconditionally setting it as actually done in the Magic Leap SDK will clear what has been set by the consumer project, which is a problem IMHO, but opinions may vary :grin:

The fix is easy: Add the path of the Magic Leap SDK to the CMAKE_MODULE_PATH variable rather than setting it. Line 105 thus becomes:

list(APPEND CMAKE_MODULE_PATH "${FOUND_MLSDK}/cmake/")

If you think of an other way to fix this, please let me know. At the moment, in my consumer project, I’m saving the value of CMAKE_MODULE_PATH variable before calling find_package(MagicLeap) and then restore the saved value.