Merge pull request #298 from rolk/298_dunever

Make version numbers for DUNE prerequisites available
This commit is contained in:
Bård Skaflestad
2013-08-08 04:10:25 -07:00
9 changed files with 144 additions and 3 deletions

View File

@@ -38,6 +38,10 @@ include (${project}-prereqs)
# it should set various lists with the names of the files to include
include (CMakeLists_files.cmake)
macro (config_hook)
# opm_need_version_of ("dune-common")
endmacro (config_hook)
macro (prereqs_hook)
endmacro (prereqs_hook)

View File

@@ -56,3 +56,7 @@ int main (void) {
HAVE_TUPLE
")
#debug_find_vars ("dune-common")
# make version number available in config.h
include (UseDuneVer)
find_dune_version ("dune" "common")

View File

@@ -45,3 +45,7 @@ int main (void) {
")
#debug_find_vars ("dune-geometry")
# make version number available in config.h
include (UseDuneVer)
find_dune_version ("dune" "geometry")

View File

@@ -53,3 +53,7 @@ int main (void) {
")
#debug_find_vars ("dune-grid")
# make version number available in config.h
include (UseDuneVer)
find_dune_version ("dune" "grid")

View File

@@ -60,3 +60,7 @@ int main (void) {
SUPERLU_POST_2005_VERSION
")
#debug_find_vars ("dune-istl")
# make version number available in config.h
include (UseDuneVer)
find_dune_version ("dune" "istl")

View File

@@ -42,6 +42,7 @@ set (_opm_proj_vars
INCLUDE_DIRS
LIBRARY_DIRS
CONFIG_VARS
CONFIG_IMPL_VARS
)
# ensure that they are at least the empty list after we're done

View File

@@ -121,6 +121,20 @@ if (COMMAND sources_hook)
sources_hook ()
endif (COMMAND sources_hook)
# convenience macro to add version of another suite, e.g. dune-common
macro (opm_need_version_of what)
string (TOUPPER "${what}" _WHAT)
string (REPLACE "-" "_" _WHAT "${_WHAT}")
list (APPEND ${project}_CONFIG_IMPL_VARS
${_WHAT}_VERSION_MAJOR ${_WHAT}_VERSION_MINOR ${_WHAT}_VERSION_REVISION
)
endmacro (opm_need_version_of suite module)
# use this hook to add version macros before we write to config.h
if (COMMAND config_hook)
config_hook ()
endif (COMMAND config_hook)
# create configuration header which describes available features
# necessary to compile this library. singular version is the names that
# is required by this project alone, plural version transitively
@@ -129,11 +143,13 @@ include (ConfigVars)
list (APPEND ${project}_CONFIG_VARS ${${project}_CONFIG_VAR})
# write configuration variables to this file. note that it is a temporary.
# _CONFIG_IMPL_VARS are defines that are only written to config.h internal
# to this project; they are not exported to any installed files.
message (STATUS "Writing config file \"${PROJECT_BINARY_DIR}/config.h\"...")
set (CONFIG_H "${PROJECT_BINARY_DIR}/config.h.tmp")
configure_vars (
FILE CXX ${CONFIG_H}
WRITE ${${project}_CONFIG_VARS}
WRITE ${${project}_CONFIG_VARS} ${${project}_CONFIG_IMPL_VARS}
)
# call this hook to let it setup necessary conditions for Fortran support

View File

@@ -262,7 +262,7 @@ macro (find_opm_package module deps header lib defs prog conf)
endif ("${lib}" STREQUAL "")
# if the search is going to fail, then write these variables to
# the console as well as a diagnostics
if (NOT (${module}_INCLUDE_DIR ${_and_lib_var} AND HAVE_${MODULE})
if ((NOT (${module}_INCLUDE_DIR ${_and_lib_var} AND HAVE_${MODULE}))
AND (${module}_FIND_REQUIRED OR NOT ${module}_FIND_QUIETLY))
if (DEFINED ${module}_DIR)
message ("${module}_DIR = ${${module}_DIR}")
@@ -271,7 +271,7 @@ macro (find_opm_package module deps header lib defs prog conf)
elseif (DEFINED ${MODULE}_ROOT)
message ("${MODULE}_ROOT = ${${MODULE}_ROOT}")
endif (DEFINED ${module}_DIR)
endif (NOT (${module}_INCLUDE_DIR ${_and_lib_var} AND HAVE_${MODULE})
endif ((NOT (${module}_INCLUDE_DIR ${_and_lib_var} AND HAVE_${MODULE}))
AND (${module}_FIND_REQUIRED OR NOT ${module}_FIND_QUIETLY))
find_package_handle_standard_args (
${module}

View File

@@ -0,0 +1,104 @@
# - Find version of a DUNE package
#
# Synopsis:
#
# find_dune_version (suite module)
#
# where:
# suite Name of the suite; this should always be "dune"
# module Name of the module, e.g. "common"
#
# Finds the content of DUNE_${MODULE}_VERSION_{MAJOR,MINOR,REVISION}
# from the installation.
#
# Add these variables to ${project}_CONFIG_IMPL_VARS in CMakeLists.txt
# if you need these in the code.
include (UseMultiArch)
function (find_dune_version suite module)
# the _ROOT variable may or may not be set, but the include
# variable should always be; get the prefix from the header path
# if we have a multilib installation where the package maintainer
# have installed it in e.g. /usr/include/dune-2.2/dune/istl, then
# stash this extra indirection and add it back later in lib/
set (_inc_path "${${suite}-${module}_INCLUDE_DIR}")
file (TO_CMAKE_PATH _inc_path "${_inc_path}")
set (_multilib_regexp "(.*)/include(/${suite}[^/]+)?")
if (_inc_path MATCHES "${_multilib_regexp}")
set (_orig_inc "${_inc_path}")
string (REGEX REPLACE "${_multilib_regexp}" "\\1" _inc_path "${_orig_inc}")
# only get the second group if it is really there (there is
# probably a better way to do this in CMake)
if ("${_inc_path}/include" STREQUAL "${_orig_inc}")
set (_multilib "")
else ()
string (REGEX REPLACE "${_multilib_regexp}" "\\2" _multilib "${_orig_inc}")
endif ()
else ()
set (_multilib "")
endif ()
# some modules does not have a library, use the directory of the
# header files to find what would be the library dir.
if (NOT ${suite}-${module}_LIBRARY)
# this suffix is gotten from UseMultiArch.cmake
set (_lib_path "${_inc_path}/${CMAKE_INSTALL_LIBDIR}")
else ()
get_filename_component (_lib_path "${${suite}-${module}_LIBRARY}" PATH)
endif ()
# if we have a source tree, dune.module is available there
set (_dune_mod "${_inc_path}/dune.module")
if (NOT EXISTS "${_dune_mod}")
set (_dune_mod "")
endif ()
if (NOT _dune_mod)
# look for the build tree; if we found the library, then the
# dune.module file should be in a sub-directory
get_filename_component (_immediate "${_lib_path}" NAME)
if ("${_immediate}" STREQUAL "${CMAKE_LIBRARY_ARCHITECTURE}")
# remove multi-arch part of the library path to get parent
get_filename_component (_lib_path "${_lib_path}" PATH)
endif ()
set (_dune_mod "${_lib_path}${_multilib}/dunecontrol/${suite}-${module}/dune.module")
if (NOT EXISTS "${_dune_mod}")
# use the name itself as a flag for whether it was found or not
set (_dune_mod "")
endif ()
endif ()
# if it is not available, it may make havoc having empty defines in the source
# code later, so we bail out early
if (${suite}-${module}_FIND_REQUIRED AND NOT _dune_mod)
message (FATAL_ERROR "Failed to locate dune.module for ${suite}-${module}")
endif ()
# parse the file for the Version: field
set (_ver_regexp "[ ]*Version:[ ]*([0-9]+)\\.([0-9]+)(.*)")
file (STRINGS "${_dune_mod}" _ver_field REGEX "${_ver_regexp}")
string (REGEX REPLACE "${_ver_regexp}" "\\1" _major "${_ver_field}")
string (REGEX REPLACE "${_ver_regexp}" "\\2" _minor "${_ver_field}")
string (REGEX REPLACE "${_ver_regexp}" "\\3" _revision "${_ver_field}")
# revision may or may not be there
set (_rev_regexp "\\.([0-9]+).*")
if (_revision MATCHES "${_rev_regexp}")
string (REGEX REPLACE "${_rev_regexp}" "\\1" _revision "${_revision}")
else ()
set (_revision "0")
endif ()
# generate variable for what we have found
string (TOUPPER "${suite}" _SUITE)
string (TOUPPER "${module}" _MODULE)
string (REPLACE "-" "_" _MODULE "${_MODULE}")
if ((NOT DEFINED ${_SUITE}_${_MODULE}_VERSION_MAJOR) AND
(NOT DEFINED ${_SUITE}_${_MODULE}_VERSION_MINOR) AND
(NOT DEFINED ${_SUITE}_${_MODULE}_VERSION_REVISION))
set (${_SUITE}_${_MODULE}_VERSION_MAJOR "${_major}" PARENT_SCOPE)
set (${_SUITE}_${_MODULE}_VERSION_MINOR "${_minor}" PARENT_SCOPE)
set (${_SUITE}_${_MODULE}_VERSION_REVISION "${_revision}" PARENT_SCOPE)
endif ()
endfunction (find_dune_version suite module)