Merge branch '037_cmake'

This synchronises the opm-autodiff build system with that of opm-core.
This commit is contained in:
Bård Skaflestad 2013-09-24 15:55:13 +02:00
commit 341f0f666d
13 changed files with 137 additions and 38 deletions

View File

@ -37,6 +37,11 @@ function (add_options langs builds)
else (NOT ("${build}" STREQUAL "ALL_BUILDS")) else (NOT ("${build}" STREQUAL "ALL_BUILDS"))
set (_bld "") set (_bld "")
endif (NOT ("${build}" STREQUAL "ALL_BUILDS")) endif (NOT ("${build}" STREQUAL "ALL_BUILDS"))
# if we want everything in the "global" flag, then simply
# ignore the build type here and go add everything to that one
if (CMAKE_NOT_USING_CONFIG_FLAGS)
set (_bld "")
endif ()
foreach (_opt IN LISTS ARGN) foreach (_opt IN LISTS ARGN)
set (_var "CMAKE_${lang}_FLAGS${_bld}") set (_var "CMAKE_${lang}_FLAGS${_bld}")
#message (STATUS "Adding \"${_opt}\" to \${${_var}}") #message (STATUS "Adding \"${_opt}\" to \${${_var}}")
@ -61,22 +66,37 @@ function (add_options langs builds)
endfunction (add_options lang build) endfunction (add_options lang build)
# set varname to flag unless user has specified something that matches regex # set varname to flag unless user has specified something that matches regex
function (set_default_option varname flag regex) function (set_default_option lang varname flag regex)
if (NOT "$ENV{CXXFLAGS}" MATCHES "${regex}" # lang is either C, CXX or Fortran
AND NOT "${CMAKE_CXX_FLAGS}" MATCHES "${regex}" if ("${lang}" STREQUAL "Fortran")
AND NOT "${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}" MATCHES "${regex}") set (letter "F")
else ()
set (letter "${lang}")
endif ()
string (TOUPPER "${CMAKE_BUILD_TYPE}" _build)
if ((NOT ("$ENV{${letter}FLAGS}" MATCHES "${regex}"))
AND (NOT ("${CMAKE_${lang}_FLAGS}" MATCHES "${regex}"))
AND (NOT ("${CMAKE_${lang}_FLAGS_${_build}}" MATCHES "${regex}")))
set (${varname} ${flag} PARENT_SCOPE) set (${varname} ${flag} PARENT_SCOPE)
else (NOT "$ENV{CXXFLAGS}" MATCHES "${regex}" else ()
AND NOT "${CMAKE_CXX_FLAGS}" MATCHES "${regex}"
AND NOT "${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}" MATCHES "${regex}")
set (${varname} PARENT_SCOPE) set (${varname} PARENT_SCOPE)
endif (NOT "$ENV{CXXFLAGS}" MATCHES "${regex}" endif ()
AND NOT "${CMAKE_CXX_FLAGS}" MATCHES "${regex}"
AND NOT "${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}" MATCHES "${regex}")
endfunction (set_default_option) endfunction (set_default_option)
# note: this must be called before project() # clear default options as a proxy for not using any default options
# at all. there is one *huge* problem with this: CMake runs the platform
# initialization before executing any line at all in the project and
# there seems to be no way to disable that behaviour, so we cannot really
# distinguish between a platform default and something that the user has
# passed on the command line. the best thing we can do is to all user-
# defined setting if they are something other than the platform default.
macro (no_default_options) macro (no_default_options)
# prevent the platform probe to set options foreach (lang IN ITEMS C CXX Fortran)
set (CMAKE_NOT_USING_CONFIG_FLAGS TRUE) foreach (build IN ITEMS DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
if ("${CMAKE_${lang}_FLAGS_${build}}" STREQUAL "${CMAKE_${lang}_FLAGS_${build}_INIT}")
# for some strange reason we cannot clear this flag, only set it to empty
set (CMAKE_${lang}_FLAGS_${build} "")
endif ()
endforeach (build)
endforeach (lang)
endmacro (no_default_options) endmacro (no_default_options)

View File

@ -72,36 +72,39 @@ endif (NOT LAPACK_FOUND)
find_library (MATH_LIBRARY NAMES "m") find_library (MATH_LIBRARY NAMES "m")
set (SuiteSparse_EXTRA_LIBS ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${MATH_LIBRARY}) set (SuiteSparse_EXTRA_LIBS ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${MATH_LIBRARY})
# search paths for the library outside of standard system paths. these are the
# paths in which the package managers on various distros put the files
list (APPEND SuiteSparse_SEARCH_PATH "/usr") # Linux
list (APPEND SuiteSparse_SEARCH_PATH "/opt/local") # MacOS X
# if we don't get any further clues about where to look, then start # if we don't get any further clues about where to look, then start
# roaming around the system # roaming around the system
set (_no_default_path "") set (_no_default_path "")
# search system directories by default
set (SuiteSparse_SEARCH_PATH)
# pick up paths from the environment if specified there; these replace the # pick up paths from the environment if specified there; these replace the
# pre-defined paths so that we don't accidentially pick up old stuff # pre-defined paths so that we don't accidentially pick up old stuff
if (NOT $ENV{SuiteSparse_DIR} STREQUAL "") if (NOT $ENV{SuiteSparse_DIR} STREQUAL "")
set (SuiteSparse_SEARCH_PATH "$ENV{SuiteSparse_DIR}") set (SuiteSparse_SEARCH_PATH "$ENV{SuiteSparse_DIR}")
set (_no_default_path "NO_DEFAULT_PATH")
endif (NOT $ENV{SuiteSparse_DIR} STREQUAL "") endif (NOT $ENV{SuiteSparse_DIR} STREQUAL "")
if (${SuiteSparse_DIR}) if (SuiteSparse_DIR)
set (SuiteSparse_SEARCH_PATH "${SuiteSparse_DIR}") set (SuiteSparse_SEARCH_PATH "${SuiteSparse_DIR}")
set (_no_default_path "NO_DEFAULT_PATH") endif (SuiteSparse_DIR)
endif (${SuiteSparse_DIR})
# CMake uses _DIR suffix as default for config-mode files; it is unlikely # CMake uses _DIR suffix as default for config-mode files; it is unlikely
# that we are building SuiteSparse ourselves; use _ROOT suffix to specify # that we are building SuiteSparse ourselves; use _ROOT suffix to specify
# location to pre-canned binaries # location to pre-canned binaries
if (NOT $ENV{SuiteSparse_ROOT} STREQUAL "") if (NOT $ENV{SuiteSparse_ROOT} STREQUAL "")
set (SuiteSparse_SEARCH_PATH "$ENV{SuiteSparse_ROOT}") set (SuiteSparse_SEARCH_PATH "$ENV{SuiteSparse_ROOT}")
set (_no_default_path "NO_DEFAULT_PATH")
endif (NOT $ENV{SuiteSparse_ROOT} STREQUAL "") endif (NOT $ENV{SuiteSparse_ROOT} STREQUAL "")
if (${SuiteSparse_ROOT}) if (SuiteSparse_ROOT)
set (SuiteSparse_SEARCH_PATH "${SuiteSparse_ROOT}") set (SuiteSparse_SEARCH_PATH "${SuiteSparse_ROOT}")
endif (SuiteSparse_ROOT)
# most commonly, we use the uppercase version of this variable
if (SUITESPARSE_ROOT)
set (SuiteSparse_SEARCH_PATH "${SUITESPARSE_ROOT}")
endif (SUITESPARSE_ROOT)
# if we have specified a search path, then confine ourselves to that
if (SuiteSparse_SEARCH_PATH)
set (_no_default_path "NO_DEFAULT_PATH") set (_no_default_path "NO_DEFAULT_PATH")
endif (${SuiteSparse_ROOT}) endif (SuiteSparse_SEARCH_PATH)
# transitive closure of dependencies; after this SuiteSparse_MODULES is the # transitive closure of dependencies; after this SuiteSparse_MODULES is the
# full list of modules that must be found to satisfy the user's link demands # full list of modules that must be found to satisfy the user's link demands

View File

@ -60,3 +60,40 @@ macro (opm_defaults opm)
set (Boost_NO_BOOST_CMAKE ON) set (Boost_NO_BOOST_CMAKE ON)
endif (NOT BOOST_ROOT) endif (NOT BOOST_ROOT)
endmacro (opm_defaults opm) endmacro (opm_defaults opm)
# overwrite a cache entry's value, but keep docstring and type
# if not already in cache, then does nothing
function (update_cache name)
get_property (_help CACHE "${name}" PROPERTY HELPSTRING)
get_property (_type CACHE "${name}" PROPERTY TYPE)
if (NOT "${_type}" STREQUAL "")
#message ("Setting ${name} to \"${${name}}\" in cache.")
set ("${name}" "${${name}}" CACHE ${_type} "${_help}" FORCE)
endif ()
endfunction (update_cache name)
# put all compiler options currently set back into the cache, so that
# they can be queried from there (using ccmake for instance)
function (write_back_options)
# build type
update_cache (CMAKE_BUILD_TYPE)
# compilers
set (languages C CXX Fortran)
foreach (language IN LISTS _languages)
if (CMAKE_${language}_COMPILER)
update_cache (CMAKE_${language}_COMPILER)
endif ()
endforeach (language)
# flags (notice use of IN LISTS to get the empty variant)
set (buildtypes "" "_DEBUG" "_RELEASE" "_MINSIZEREL" "_RELWITHDEBINFO")
set (processors "C" "CXX" "Fortran" "EXE_LINKER" "MODULE_LINKER" "SHARED_LINKER")
foreach (processor IN LISTS processors)
foreach (buildtype IN LISTS buildtypes)
if (CMAKE_${processor}_FLAGS${buildtype})
update_cache (CMAKE_${processor}_FLAGS${buildtype})
endif ()
endforeach (buildtype)
endforeach (processor)
endfunction (write_back_options)

View File

@ -269,3 +269,6 @@ configure_file (
# make sure updated version information is available in the source code # make sure updated version information is available in the source code
include (UseVersion) include (UseVersion)
# update the cache for next run
write_back_options ()

View File

@ -16,7 +16,7 @@ is_compiler_gcc_compatible ()
# only debugging using the GNU toolchain is supported for now # only debugging using the GNU toolchain is supported for now
if (CXX_COMPAT_GCC) if (CXX_COMPAT_GCC)
# default debug level, if not specified by the user # default debug level, if not specified by the user
set_default_option (_dbg_flag "-ggdb3" "(^|\ )-g") set_default_option (CXX _dbg_flag "-ggdb3" "(^|\ )-g")
# add debug symbols to *all* targets, regardless. there WILL come a # add debug symbols to *all* targets, regardless. there WILL come a
# time when you need to find a bug which only manifests itself in a # time when you need to find a bug which only manifests itself in a

View File

@ -41,6 +41,11 @@ function (find_dune_version suite module)
# some modules does not have a library, use the directory of the # some modules does not have a library, use the directory of the
# header files to find what would be the library dir. # header files to find what would be the library dir.
# note that when we refer to a build tree, then the libraries always
# go into lib/, but we don't care about that because in that case,
# dune.module isn't in the lib/ directory anyway but must be retrieved
# from the source. hence, we only have to worry about the library
# directory of a system installation here.
if (NOT ${suite}-${module}_LIBRARY) if (NOT ${suite}-${module}_LIBRARY)
# this suffix is gotten from UseMultiArch.cmake # this suffix is gotten from UseMultiArch.cmake
set (_lib_path "${_inc_path}/${CMAKE_INSTALL_LIBDIR}") set (_lib_path "${_inc_path}/${CMAKE_INSTALL_LIBDIR}")
@ -51,6 +56,7 @@ function (find_dune_version suite module)
# if we have a source tree, dune.module is available there # if we have a source tree, dune.module is available there
set (_dune_mod "${_inc_path}/dune.module") set (_dune_mod "${_inc_path}/dune.module")
if (NOT EXISTS "${_dune_mod}") if (NOT EXISTS "${_dune_mod}")
set (_last_dune_mod_src "${_dune_mod}")
set (_dune_mod "") set (_dune_mod "")
endif () endif ()
@ -58,13 +64,19 @@ function (find_dune_version suite module)
# look for the build tree; if we found the library, then the # look for the build tree; if we found the library, then the
# dune.module file should be in a sub-directory # dune.module file should be in a sub-directory
get_filename_component (_immediate "${_lib_path}" NAME) get_filename_component (_immediate "${_lib_path}" NAME)
if ("${_immediate}" STREQUAL ".libs")
# remove autotools internal path
get_filename_component (_lib_path "${_lib_path}" PATH)
endif ()
get_filename_component (_immediate "${_lib_path}" NAME)
if ("${_immediate}" STREQUAL "${CMAKE_LIBRARY_ARCHITECTURE}") if ("${_immediate}" STREQUAL "${CMAKE_LIBRARY_ARCHITECTURE}")
# remove multi-arch part of the library path to get parent # remove multi-arch part of the library path to get parent
get_filename_component (_lib_path "${_lib_path}" PATH) get_filename_component (_lib_path "${_lib_path}" PATH)
endif () endif ()
get_filename_component (_immediate "${_lib_path}" NAME) get_filename_component (_immediate "${_lib_path}" NAME)
if (("${_immediate}" STREQUAL "${CMAKE_INSTALL_LIBDIR}") if (("${_immediate}" STREQUAL "${CMAKE_INSTALL_LIBDIR}")
OR ("${_immediate}" STREQUAL "lib")) OR ("${_immediate}" STREQUAL "lib")
OR ("${_immediate}" STREQUAL "${LIBDIR_MULTIARCH_UNAWARE}"))
# remove library part of the path; this also undo the suffix # remove library part of the path; this also undo the suffix
# we added if we used the library as a standin # we added if we used the library as a standin
get_filename_component (_lib_path "${_lib_path}" PATH) get_filename_component (_lib_path "${_lib_path}" PATH)
@ -72,18 +84,37 @@ function (find_dune_version suite module)
# from this point on, _lib_path does not contain an architecture- # from this point on, _lib_path does not contain an architecture-
# specific component anymore; dune.module is always put in straight # specific component anymore; dune.module is always put in straight
# noarch lib/ since it does not contain any paths to binaries # noarch lib/ since it does not contain any paths to binaries
set (_dune_mod "${_lib_path}/${LIBDIR_MULTIARCH_UNAWARE}${_multilib}/dunecontrol/${suite}-${module}/dune.module") set (_suffix "${_multilib}/dunecontrol/${suite}-${module}/dune.module")
set (_dune_mod "${_lib_path}/${LIBDIR_MULTIARCH_UNAWARE}${_suffix}")
if (NOT EXISTS "${_dune_mod}") if (NOT EXISTS "${_dune_mod}")
# use the name itself as a flag for whether it was found or not set (_last_dune_mod_bld "${_dune_mod}")
set (_dune_mod "") # one more try, if we have a private install, then it doesn't use
# e.g. lib64 but always lib (!)
if ("${LIBDIR_MULTIARCH_UNAWARE}" STREQUAL "lib")
set (_dune_mod "")
else ()
set (_dune_mod "${_lib_path}/lib${_suffix}")
if (NOT EXISTS "${_dune_mod}")
set (_last_dune_mod_pri "${_dune_mod}")
# use the name itself as a flag for whether it was found or not
set (_dune_mod "")
endif ()
endif ()
endif () endif ()
endif () endif ()
# if it is not available, it may make havoc having empty defines in the source # if it is not available, it may make havoc having empty defines in the source
# code later, so we bail out early # code later, so we bail out early
if (NOT _dune_mod) if (NOT _dune_mod)
if (${suite}-${module}_FIND_REQUIRED) if (${suite}-${module}_FOUND)
message (FATAL_ERROR "Failed to locate dune.module for ${suite}-${module}") set (_searched_paths "\"${_last_dune_mod_src}\"")
if (NOT ("${_last_dune_mod_bld}" STREQUAL ""))
set (_searched_paths "either ${_searched_paths} or \"${_last_dune_mod_bld}\"")
endif ()
if (NOT ("${_last_dune_mod_pri}" STREQUAL ""))
set (_searched_paths "${_searched_paths} or \"${_last_dune_mod_pri}\"")
endif ()
message (FATAL_ERROR "Failed to locate dune.module for ${suite}-${module} (looking for ${_searched_paths})")
else () else ()
return () return ()
endif () endif ()

View File

@ -17,7 +17,6 @@ if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
# Debian or Ubuntu? # Debian or Ubuntu?
if (EXISTS "/etc/debian_version") if (EXISTS "/etc/debian_version")
set (_libdir_def "lib/${CMAKE_LIBRARY_ARCHITECTURE}") set (_libdir_def "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
set (_libdir_noarch "lib")
else (EXISTS "/etc/debian_version") else (EXISTS "/etc/debian_version")
# 64-bit system? # 64-bit system?
if (CMAKE_SIZEOF_VOID_P EQUAL 8) if (CMAKE_SIZEOF_VOID_P EQUAL 8)

View File

@ -37,8 +37,8 @@ if (CXX_COMPAT_GCC)
endif (WITH_NATIVE) endif (WITH_NATIVE)
# default optimization flags, if not set by user # default optimization flags, if not set by user
set_default_option (_opt_dbg "-O0" "(^|\ )-O") set_default_option (CXX _opt_dbg "-O0" "(^|\ )-O")
set_default_option (_opt_rel "-O3" "(^|\ )-O") set_default_option (CXX _opt_rel "-O3" "(^|\ )-O")
# use these options for debug builds - no optimizations # use these options for debug builds - no optimizations
add_options (ALL_LANGUAGES "${_prof_DEBUG}" ${_opt_dbg} "-DDEBUG") add_options (ALL_LANGUAGES "${_prof_DEBUG}" ${_opt_dbg} "-DDEBUG")

View File

@ -39,6 +39,7 @@ function (distro_name varname)
file (GLOB has_os_release /etc/os-release) file (GLOB has_os_release /etc/os-release)
file (GLOB has_lsb_release /etc/lsb-release) file (GLOB has_lsb_release /etc/lsb-release)
file (GLOB has_sys_release /etc/system-release) file (GLOB has_sys_release /etc/system-release)
file (GLOB has_redhat_release /etc/redhat-release)
set (_descr) set (_descr)
# start with /etc/os-release, # start with /etc/os-release,
# see <http://0pointer.de/blog/projects/os-release.html> # see <http://0pointer.de/blog/projects/os-release.html>
@ -52,6 +53,8 @@ function (distro_name varname)
if (NOT _descr) if (NOT _descr)
if (NOT has_sys_release STREQUAL "") if (NOT has_sys_release STREQUAL "")
file (READ /etc/system-release _descr) file (READ /etc/system-release _descr)
elseif (NOT has_redhat_release STREQUAL "")
file (READ /etc/redhat-release _descr)
else (NOT has_sys_release STREQUAL "") else (NOT has_sys_release STREQUAL "")
# no yet known release file found # no yet known release file found
set (_descr "unknown") set (_descr "unknown")

View File

@ -6,7 +6,7 @@ is_compiler_gcc_compatible ()
if (CXX_COMPAT_GCC) if (CXX_COMPAT_GCC)
# default warnings flags, if not set by user # default warnings flags, if not set by user
set_default_option (_warn_flag "-Wall" "(^|\ )-W") set_default_option (CXX _warn_flag "-Wall" "(^|\ )-W")
if (_warn_flag) if (_warn_flag)
message (STATUS "All warnings enabled: ${_warn_flag}") message (STATUS "All warnings enabled: ${_warn_flag}")
add_options (ALL_LANGUAGES ALL_BUILDS "${_warn_flag}") add_options (ALL_LANGUAGES ALL_BUILDS "${_warn_flag}")

View File

@ -17,6 +17,7 @@ set (ewoms_DEPS
"dune-geometry REQUIRED" "dune-geometry REQUIRED"
"dune-grid REQUIRED" "dune-grid REQUIRED"
"dune-istl REQUIRED" "dune-istl REQUIRED"
"opm-core REQUIRED"
"opm-material REQUIRED" "opm-material REQUIRED"
# valgrind client requests # valgrind client requests
"Valgrind" "Valgrind"

View File

@ -17,5 +17,4 @@ set (opm-material_DEPS
"opm-core REQUIRED" "opm-core REQUIRED"
# DUNE dependency # DUNE dependency
"dune-common REQUIRED" "dune-common REQUIRED"
"dune-istl REQUIRED"
) )

View File

@ -145,7 +145,7 @@ VARS=()
# command that launches cmake; look for 2.8 if available # command that launches cmake; look for 2.8 if available
if [ "${CMAKE_COMMAND}" = "" ]; then if [ "${CMAKE_COMMAND}" = "" ]; then
if which cmake28 >/dev/null 2>&1; then if [ -x "$(command -v cmake28)" ]; then
CMAKE_COMMAND=cmake28 CMAKE_COMMAND=cmake28
else else
CMAKE_COMMAND=cmake CMAKE_COMMAND=cmake
@ -454,10 +454,12 @@ for a in "${VARS[@]}"; do
CC=*) CC=*)
# special processing for compiler options # special processing for compiler options
a=${a#CC=} a=${a#CC=}
[ -x "$(command -v $a)" ] && a=$(command -v "$a")
c_compiler=" -DCMAKE_C_COMPILER=\"${a/\"/\\\"}\"" c_compiler=" -DCMAKE_C_COMPILER=\"${a/\"/\\\"}\""
;; ;;
CXX=*) CXX=*)
a=${a#CXX=} a=${a#CXX=}
[ -x "$(command -v $a)" ] && a=$(command -v "$a")
cxx_compiler=" -DCMAKE_CXX_COMPILER=\"${a/\"/\\\"}\"" cxx_compiler=" -DCMAKE_CXX_COMPILER=\"${a/\"/\\\"}\""
;; ;;
CFLAGS=*) CFLAGS=*)
@ -470,6 +472,7 @@ for a in "${VARS[@]}"; do
;; ;;
FC=*) FC=*)
a=${a#FC=} a=${a#FC=}
[ -x "$(command -v $a)" ] && a=$(command -v "$a")
fort_compiler=" -DCMAKE_Fortran_COMPILER=\"${a/\"/\\\"}\"" fort_compiler=" -DCMAKE_Fortran_COMPILER=\"${a/\"/\\\"}\""
;; ;;
FFLAGS=*) FFLAGS=*)