Install config mode CMake module at installation

find_package only searches for FindXxx-modules in the path specified by
CMAKE_MODULE_PATH; other paths are supposed to contain config-mode
modules (much like pkgconfig).

Generate the config-mode module in the installation directory using the
same template as is used for the one in the build directory, only
selectively swapping some directories in the relevant variables.
This commit is contained in:
Roland Kaufmann
2012-12-07 12:18:49 +01:00
parent e7d9abcd8e
commit 9942dcc8d9
3 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
# - Helper routines for opm-core like projects
# installation of CMake modules to help user programs locate the library
function (opm_cmake_config name)
# replace the build directory with the target directory in the
# variables that contains build paths
string (REPLACE
"${PROJECT_SOURCE_DIR}"
"${CMAKE_INSTALL_PREFIX}/include"
${name}_INCLUDE_DIRS
"${${name}_INCLUDE_DIRS}"
)
string (REPLACE
"${PROJECT_BINARY_DIR}/lib"
"${CMAKE_INSTALL_PREFIX}/lib"
${name}_LIBRARY
"${${name}_LIBRARY}"
)
string (REPLACE
"${PROJECT_BINARY_DIR}/lib"
"${CMAKE_INSTALL_PREFIX}/lib"
CMAKE_LIBRARY_OUTPUT_DIRECTORY
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
)
# create a config mode file which targets the install directory instead
# of the build directory (using the same input template)
configure_file (
${PROJECT_SOURCE_DIR}/${name}-config.cmake.in
${PROJECT_BINARY_DIR}/${name}-install.cmake
@ONLY
)
configure_vars (
FILE CMAKE "${PROJECT_BINARY_DIR}/${name}-install.cmake"
APPEND "${${name}_CONFIG_VARS}"
)
# this file gets copied to the final installation directory
install (
FILES ${PROJECT_BINARY_DIR}/${name}-install.cmake
DESTINATION share/cmake/${name}
RENAME ${name}-config.cmake
)
endfunction (opm_cmake_config name)