[CMake] Externally hooking a FindXYZ module
Yuri V. Timenkov
ytimenkov at parallels.com
Tue Aug 26 00:54:00 EDT 2008
On Monday 25 August 2008 23:07:28 Fernando Cacciola wrote:
> Hi people,
>
> It turns out that Mac's Leopard OS needs a fix for OpenGL. The fix
> itself has been discussed in this list a while back:
>
> http://www.mail-archive.com/cmake@cmake.org/msg09358.html
>
>
> I need to incorporate that fix into production code, and I don't want to
> distribute my own hacked up version FindOpenGL.cmake, not a real one at
> least, so I wonder, is there a way to hook into the find_package behaviour?
>
>
> The only hack I could come up was stubbing a Find module
> in this way:
>
> (1)
> At the most top level CMakeLists.txt:
>
> # Save aside the default modules path.
> set(ORIGINAL_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} )
>
> # Prepend a project specific path so my modules take precedence
> set(CMAKE_MODULE_PATH "cmake_modules" ${CMAKE_MODULE_PATH} )
>
>
>
> (2)
> Then at the local cmake_modules folder, add a "FindOpenGL.cmake" stub
> with this:
>
>
> # Avoid recursion
> if ( NOT FIND_OPENGL_WRAPPER )
>
> set ( FIND_OPENGL_WRAPPER 1 )
>
> set(SAVED_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} )
>
> set(CMAKE_MODULE_PATH ${ORIGINAL_CMAKE_MODULE_PATH} )
>
> # This calls the real module.
> find_package(OpenGL)
>
> # Here is the post-processing to "fix" OpenGL for leopard
>
> if ( OPENGL_FOUND AND APPLE_LEOPARD )
>
> set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-dylib_file,/System/
> Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/
> System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib
>")
>
> endif()
>
> # reset the modules path.
> set(CMAKE_MODULE_PATH ${SAVED_CMAKE_MODULE_PATH} )
>
> endif()
>
>
> Is there a better way??
First, you can move linking flags logic outside of FindGL.cmake file, therefore
you don't need customization.
Alternatively you can copy this file to your custom modules directory and do
not call original one.
>
> TIA
>
> Fernando Cacciola
>
>
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
More information about the CMake
mailing list