1

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.
Ed Rowlett-Barbu
  • 1,611
  • 10
  • 27
  • I guess you'd have to modify the `CMakeLists.txt` of OpenSceneGraph. Search for a line which probably should look something like: `set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})`. In other words, it puts OSG's own module search path in front of the CMake's one to precede it. – Alexander Shukaev May 05 '13 at 09:59
  • @Haroogan thanks for the comment Haroogan. I know how OSG is changing the module path. It has its own modules in there too so it needs to set the module path so it can use them. I can't simply delete that line. Modifying it is also no better than simply deleting the FindZLIB module in OSG. I'd prefer a workaround that does not involve changing the OSG sources in any way. – Ed Rowlett-Barbu May 05 '13 at 12:53
  • 1
    Don't delete this line of course, just change the order to: `set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules)`, so that CMake modules take precedence over OSG ones, and ZLib is found according to CMake default rules. Unfortunately, I think you're out of options, it's the OSG developers to blame for such a dumb solution they offer. – Alexander Shukaev May 05 '13 at 14:33

1 Answers1

1

You can simply set the cmake policy that is mentioned. I don't know how to do this through ExternalProject_add, but it does fix the problem. The CMakeLists.txt file that comes with the source distribution has a section where some cmake policies are already set. You can add a line that sets the CMP0017 policy to NEW and it gets rid of this warning.

if (COMMAND cmake_policy)
    ...

    cmake_policy (SET CMP0017 NEW)

    ...
endif ()
Kabbotta
  • 15
  • 5