Rephrased Question
How can I control the order in which CMake uses FindXXX.cmake modules?
My exact issue
For example, OpenSceneGraph comes with its own FindZLIB which is not as good as the FindZLIB Cmake comes with.The FindZLIB module that comes with OSG is not able to find my ZLIB installation. I have ZLIB installed in the CMAKE_INSTALL_PREFIX path.
During build, cmake warns me about this.
OSG sets the module path to its own dir, and thus FindPNG (from CMake) improperly uses the FindZLIB OpenSceneGraph comes with. And so, it fails to find ZLIB.
How can I prevent this from happening? I'm building OpenSceneGraph through a call to ExternalProject_Add. I've read setting a cmake policy (CMP0017 to be precise) might fix it? I do not know how to do that through ExternalProject_Add.
More details
This is the related warning when cmake (called from the generated visual studio solution) tries to configure and build OSG: 4> CMake Warning (dev) at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPNG.cmake:34 (find_package):
4> File C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPNG.cmake
4> includes E:/project/third-party/OpenSceneGraph/CMakeModules/FindZLIB.cmake
4> (found via CMAKE_MODULE_PATH) which shadows C:/Program Files (x86)/CMake
4> 2.8/share/cmake-2.8/Modules/FindZLIB.cmake. This may cause errors later on
4> .
4>
4> Policy CMP0017 is not set: Prefer files from the CMake module directory
4> when including from there. Run "cmake --help-policy CMP0017" for policy
4> details. Use the cmake_policy command to set the policy and suppress this
4> warning.