[CMake] Externally hooking a FindXYZ module
Fernando Cacciola
fernando.cacciola at gmail.com
Mon Aug 25 15:07:28 EDT 2008
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??
TIA
Fernando Cacciola
More information about the CMake
mailing list