[CMake] HOWTO: Generate Use*.cmake files for installation
kent williams
nkwmailinglists at gmail.com
Fri Oct 1 16:45:01 EDT 2010
No, I didn't get any clues as to how this is handled. In ITK it is
handled subtly, which is to say I couldn't figure out how it worked
from reading the CMakeLists.txt.
What I ended up doing is to create the Config file twice -- once for
the eventual installation, and once for the in-place usage.
The one that gets installed can be pretty straightforward, if you can
depend on things being installed in readily knowable paths with
respect to the <module>Config.cmake file:
# find out where this file is
get_filename_component(CONFIG_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
#
# assume you're installed in ${CMAKE_INSTALL_PREFIX}/lib/MODULE
# include directory is parallel to lib
set(MODULE_INCLUDE_DIR "${CONFIG_DIR}/../../include/MODULE)
# assume Config file goes into lib/MODULE along with libraries
set(MODULE_LIBRARY_DIR "${CONFIG_DIR}")
# The Use file should be in same directory
set(MODULE_USE_FILE "${CONFIG_DIR}/UseMODULE.cmake")
Then the Use file you can include after find_package(MODULE REQUIRED)
sets things up for the user:
include_directories(BEFORE ${ModuleDescriptionParser_INCLUDE_DIRS})
link_directories(${MODULE_LIBRARY_DIR})
More information about the CMake
mailing list