From 293ea97fa9a55417d78a9dbb3bb166f17808c801 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Mon, 11 Feb 2013 10:36:00 +0100 Subject: [PATCH] Modularize installation target --- CMakeLists.txt | 47 +++-------------------------- cmake/Modules/OpmInstall.cmake | 55 ++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 43 deletions(-) create mode 100644 cmake/Modules/OpmInstall.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ef9236d..1f9b2489 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,49 +247,10 @@ else (PRECOMPILE_HEADERS) message (STATUS "Precompiled headers: disabled") endif (PRECOMPILE_HEADERS) -### installation ### -foreach (_hdr IN LISTS opm-core_HEADERS) - get_filename_component (_dir ${_hdr} PATH) - file (RELATIVE_PATH _rel_dir "${PROJECT_SOURCE_DIR}" "${_dir}") - install ( - FILES ${_hdr} - DESTINATION include/${_rel_dir} - ) -endforeach (_hdr) -install ( - TARGETS ${opm-core_TARGET} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -# only /usr/lib/debug seems to be searched for debug info; if we have -# write access to that directory (package installation), then default -# to use it; otherwise put the debug files together with the library -# (local installation). everything can be overridden by the option. -if (CMAKE_INSTALL_PREFIX STREQUAL "/usr") - set (_sys_dbg_def ON) -else (CMAKE_INSTALL_PREFIX STREQUAL "/usr") - set (_sys_dbg_def OFF) -endif (CMAKE_INSTALL_PREFIX STREQUAL "/usr") -option (SYSTEM_DEBUG "Put .debug files in GDB debug file directory" ${_sys_dbg_def}) -set (DEBUG_FILE_DIRECTORY /usr/lib/debug CACHE LOCATION "GDB debug file directory") -mark_as_advanced (DEBUG_FILE_DIRECTORY) -if (SYSTEM_DEBUG) - set (_dbg_prefix "${DEBUG_FILE_DIRECTORY}/") -else (SYSTEM_DEBUG) - set (_dbg_prefix "") -endif (SYSTEM_DEBUG) -# static libraries don't have their debug info stripped, so there is -# only a separate file when we are building shared objects -if (opm-core_LIBRARY_TYPE STREQUAL "SHARED") - install ( - FILES ${PROJECT_BINARY_DIR}/${opm-core_DEBUG} - DESTINATION ${_dbg_prefix}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} - ) -endif (opm-core_LIBRARY_TYPE STREQUAL "SHARED") -install ( - FILES ${PROJECT_SOURCE_DIR}/dune.module - DESTINATION ${CMAKE_INSTALL_LIBDIR_NOARCH}/dunecontrol/${opm-core_NAME} - ) +# installation target: copy the library together with debug and +# configuration files to system directories +include (OpmInstall) +opm_install (opm-core) message (STATUS "This build defaults to installing in ${CMAKE_INSTALL_PREFIX}") # we need to know the name of the library which is generated diff --git a/cmake/Modules/OpmInstall.cmake b/cmake/Modules/OpmInstall.cmake new file mode 100644 index 00000000..94bb0a98 --- /dev/null +++ b/cmake/Modules/OpmInstall.cmake @@ -0,0 +1,55 @@ +# - Installation macro +# +# Set up installation targets for the binary library. The following +# suffices must be defined for the prefix passed as parameter: +# +# _NAME Name of the library +# _HEADERS List of header files to install +# _TARGET CMake target which builds the library +# _LIBRARY_TYPE Static or shared library +# _DEBUG File containing debug symbols + +macro (opm_install opm) + foreach (_hdr IN LISTS ${opm}_HEADERS) + get_filename_component (_dir ${_hdr} PATH) + file (RELATIVE_PATH _rel_dir "${PROJECT_SOURCE_DIR}" "${_dir}") + install ( + FILES ${_hdr} + DESTINATION include/${_rel_dir} + ) + endforeach (_hdr) + install ( + TARGETS ${${opm}_TARGET} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) + # only /usr/lib/debug seems to be searched for debug info; if we have + # write access to that directory (package installation), then default + # to use it; otherwise put the debug files together with the library + # (local installation). everything can be overridden by the option. + if (CMAKE_INSTALL_PREFIX STREQUAL "/usr") + set (_sys_dbg_def ON) + else (CMAKE_INSTALL_PREFIX STREQUAL "/usr") + set (_sys_dbg_def OFF) + endif (CMAKE_INSTALL_PREFIX STREQUAL "/usr") + option (SYSTEM_DEBUG "Put .debug files in GDB debug file directory" ${_sys_dbg_def}) + set (DEBUG_FILE_DIRECTORY /usr/lib/debug CACHE LOCATION "GDB debug file directory") + mark_as_advanced (DEBUG_FILE_DIRECTORY) + if (SYSTEM_DEBUG) + set (_dbg_prefix "${DEBUG_FILE_DIRECTORY}/") + else (SYSTEM_DEBUG) + set (_dbg_prefix "") + endif (SYSTEM_DEBUG) + # static libraries don't have their debug info stripped, so there is + # only a separate file when we are building shared objects + if (${opm}_LIBRARY_TYPE STREQUAL "SHARED") + install ( + FILES ${PROJECT_BINARY_DIR}/${${opm}_DEBUG} + DESTINATION ${_dbg_prefix}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} + ) + endif (${opm}_LIBRARY_TYPE STREQUAL "SHARED") + install ( + FILES ${PROJECT_SOURCE_DIR}/dune.module + DESTINATION ${CMAKE_INSTALL_LIBDIR_NOARCH}/dunecontrol/${${opm}_NAME} + ) +endmacro (opm_install opm)