find_package() behaviour and WSL
To be directly clear, this is not a bug. CMake behaves exactly as documented, but in combination with WSL on Windows, this lead to a surprising behaviour and I wanted to report it because maybe there is something that I miss or maybe there is something CMake can change to make this less surprising.
Connected issue on Github: https://github.com/eclipse-ecal/ecal/issues/1195
What I did:
- I installed a software on Windows 11. The software comes with some CMake files if you want to develop against it
- The software adds itself to the PATH in Windows 11. That path ends in bin
- The CMake files reside in a folder parallel to bin named cmake
- WSL adds the Windows PATH at the end of the WSL PATH variable, mapping e.g. C:/Folder/bin to /mnt/c/Folder/bin
- I wanted to build the software myself in WSL Ubuntu 22.04, so I cloned the repo there and ran cmake inside WSL
- CMake failed because it picked up the *-config CMake files from /mnt/c/Folder/cmake
Now find_package() clearly states that it checks the PATH and behaves that way if a PATH entry ends in bin. But the combination of stuff here lead to a big surprise for me.
The obvious current solution is to either remove the offending Windows PATH entries from the WSL PATH, or add them to CMAKE_IGNORE_PATH within WSL. Also, the real offender here is probably Microsoft because it automagically extends the WSL PATH with all Windows entries. The chain of events just lead to me being really surprised.
Still, I wanted to ask whether there is any possibility to warn about this from CMake side ("WARNING: Found CMake files from outside the WSL environment") or have a flag to skip files found on the host machine if running inside WSL? There are probably better ideas.
I have the feeling every way of handling this situation would lead to me being surprised depending on my current use case ("Why didn't it pick up that file? It's in my PATH!").
Still, I wanted to mention it because maybe experts have an idea how to handle this nicely.