opm-simulators/cmake/Modules/OpmInit.cmake
Roland Kaufmann 8c71f4d75b Support installation in a versioned directory
If the option USE_VERSIONED_DIR is set to ON (default is OFF), then
most files are installed in a ${suite}-${label}/ subdirectory
(e.g. header files go in "/usr/include/opm-2013.03/"). This enables
us to easily install backports of newer versions on systems which
have a system package for an older one, without getting conflicts.
2013-08-27 09:24:35 +02:00

74 lines
2.7 KiB
CMake

# - Initialize project-specific variables
#
# This will read the dune.module file for project information and
# set the following variables:
#
# project From the Module: field
# ${project}_NAME Same as above
# ${project}_DESCRIPTION From the Description: field
# ${project}_VERSION_MAJOR From the Version: field
# ${project}_VERSION_MINOR From the Version: field also
#
# This module should be the first to be included in the project,
# because most of the others (OpmXxx.cmake) use these variables.
# helper macro to retrieve a single field of a dune.module file
macro(OpmGetDuneModuleDirective field variable contents)
string (REGEX MATCH ".*${field}:[ ]*([^\n]+).*" ${variable} "${contents}")
string (REGEX REPLACE ".*${field}:[ ]*([^\n]+).*" "\\1" "${variable}" "${${variable}}")
string (STRIP "${${variable}}" ${variable})
endmacro()
function (OpmInitProjVars)
# locate the "dune.module" file
set (DUNE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/dune.module")
# read this file into a variable
file (READ "${DUNE_MODULE_PATH}" DUNE_MODULE)
# read fields from the file
OpmGetDuneModuleDirective ("Module" project "${DUNE_MODULE}")
OpmGetDuneModuleDirective ("Description" description "${DUNE_MODULE}")
OpmGetDuneModuleDirective ("Version" version "${DUNE_MODULE}")
OpmGetDuneModuleDirective ("Label" label "${DUNE_MODULE}")
# parse the version number
set (verno_regex "^([0-9]*)\\.([0-9]*).*\$")
string (REGEX REPLACE "${verno_regex}" "\\1" major "${version}")
string (REGEX REPLACE "${verno_regex}" "\\2" minor "${version}")
# return these variables
set (project "${project}" PARENT_SCOPE)
set (${project}_NAME "${project}" PARENT_SCOPE)
set (${project}_DESCRIPTION "${description}" PARENT_SCOPE)
set (${project}_VERSION_MAJOR "${major}" PARENT_SCOPE)
set (${project}_VERSION_MINOR "${minor}" PARENT_SCOPE)
set (${project}_LABEL "${label}" PARENT_SCOPE)
endfunction ()
macro (OpmInitDirVars)
# these are the most common (and desired locations)
set (${project}_DIR "opm")
set (doxy_dir "doc/doxygen")
# but for backward compatibility we can override it
if (COMMAND dir_hook)
dir_hook ()
endif (COMMAND dir_hook)
endmacro ()
OpmInitProjVars ()
OpmInitDirVars ()
# if we are backporting this release to a system which already have an
# earlier version, set this flag to have everything scoped into a directory
# which incorporates the label of the release. this is done by interjecting
# the ${project}_VER_DIR into the installation path.
option (USE_VERSIONED_DIR "Put files in release-specific directories" OFF)
set (${project}_SUITE "opm")
if (USE_VERSIONED_DIR)
set (${project}_VER_DIR "/${${project}_SUITE}-${${project}_LABEL}")
else ()
set (${project}_VER_DIR "")
endif ()