forked from OPM/opm-upscaling
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import cmake/ from commit 5f82198c in opm-core
- Loading branch information
Showing
56 changed files
with
6,952 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,281 @@ | ||
# -*- mode: cmake; tab-width: 2; indent-tabs-mode: t; truncate-lines: t; compile-command: "cmake -Wdev" -*- | ||
# vim: set filetype=cmake autoindent tabstop=2 shiftwidth=2 noexpandtab softtabstop=2 nowrap: | ||
|
||
# key information about the library | ||
set (project "opm-core") | ||
set (${project}_NAME "${project}") | ||
set (${project}_DESCRIPTION "Open Porous Media Initiative Core Library") | ||
set (${project}_DIR "opm") | ||
set (${project}_VERSION_MAJOR 1) | ||
set (${project}_VERSION_MINOR 0) | ||
set (doxy_dir "Documentation") | ||
|
||
# defines that must be present in config.h for our headers | ||
set (${project}_CONFIG_VAR | ||
HAVE_AGMG | ||
HAVE_DUNE_ISTL | ||
HAVE_DYNAMIC_BOOST_TEST | ||
HAVE_ERT | ||
HAVE_SUITESPARSE_UMFPACK_H | ||
HAVE_NULLPTR | ||
HAVE_STATIC_ASSERT | ||
) | ||
|
||
# dependencies | ||
set (${project}_DEPS | ||
# compile with C99 support if available | ||
"C99" | ||
# compile with C++0x/11 support if available | ||
"CXX11Features" | ||
# various runtime library enhancements | ||
"Boost 1.39.0 | ||
COMPONENTS date_time filesystem system unit_test_framework REQUIRED" | ||
# matrix library | ||
"BLAS REQUIRED" | ||
"LAPACK REQUIRED" | ||
# Tim Davis' SuiteSparse archive | ||
"SuiteSparse COMPONENTS umfpack" | ||
# solver | ||
"SUPERLU" | ||
# xml processing (for config parsing) | ||
"TinyXML" | ||
# Ensembles-based Reservoir Tools (ERT) | ||
"ERT" | ||
# DUNE dependency | ||
"dune-istl" | ||
) | ||
|
||
# C++ project | ||
cmake_minimum_required (VERSION 2.8) | ||
project (${${project}_NAME}) | ||
enable_language (C) | ||
enable_language (CXX) | ||
|
||
# additional search modules | ||
set (${project}_MODULE_DIR "${PROJECT_SOURCE_DIR}/cmake/Modules") | ||
list (APPEND CMAKE_MODULE_PATH ${${project}_MODULE_DIR}) | ||
|
||
# print system information to better pinpoint issues from log alone | ||
include (UseSystemInfo) | ||
system_info () | ||
|
||
# very early try to print repo id (to pinpoint version if something goes wrong) | ||
include (UseVCSInfo) | ||
vcs_info () | ||
|
||
# include special | ||
if (CMAKE_VERSION VERSION_LESS "2.8.7") | ||
message (STATUS "Enabling backward compatibility modules for CMake ${CMAKE_VERSION}") | ||
list (APPEND CMAKE_MODULE_PATH "${${project}_MODULE_DIR}/compat-2.8.7") | ||
endif (CMAKE_VERSION VERSION_LESS "2.8.7") | ||
|
||
# default settings: build static debug library | ||
include (OpmDefaults) | ||
opm_defaults (${project}) | ||
message (STATUS "Build type: ${CMAKE_BUILD_TYPE}") | ||
|
||
# use tricks to do faster builds | ||
include (UseFastBuilds) | ||
|
||
# precompiled headers | ||
include (UsePrecompHeaders) | ||
|
||
# macro to set standard variables (INCLUDE_DIRS, LIBRARIES etc.) | ||
include (OpmFind) | ||
find_and_append_package_list_to (${project} ${${project}_DEPS}) | ||
|
||
# remove the dependency on the testing framework from the main library; | ||
# it is not possible to query for Boost twice with different components. | ||
list (REMOVE_ITEM ${project}_LIBRARIES ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) | ||
|
||
# don't import more libraries than we need to | ||
include (UseOnlyNeeded) | ||
|
||
# put debug information into every executable | ||
include (UseDebugSymbols) | ||
|
||
# optimize full if we're not doing a debug build | ||
include (UseOptimization) | ||
|
||
# turn on all warnings | ||
include (UseWarnings) | ||
|
||
# detect if Boost is in a shared library | ||
include (UseDynamicBoost) | ||
|
||
# needed for Debian installation scheme | ||
include (UseMultiArch) | ||
|
||
# this module contains code to figure out which files is where | ||
include (OpmFiles) | ||
opm_auto_dirs () | ||
|
||
# put libraries in lib/ | ||
opm_out_dirs () | ||
|
||
# identify the compilation units in the library | ||
opm_sources (${project}) | ||
|
||
# enumerate all testing programs in test/ directory | ||
opm_find_tests () | ||
|
||
# tutorial programs are found in the tutorials/ directory | ||
opm_find_tutorials () | ||
|
||
# example programs are found in the examples/ directory | ||
opm_find_examples () | ||
|
||
### --- begin AGMG specific --- ### | ||
# Algebraic Multigrid must be compiled together with our program; | ||
# if it is not available, then remove our corresponding component | ||
find_package (AGMG) | ||
if (AGMG_FOUND) | ||
list (APPEND ${project}_SOURCES ${AGMG_SOURCES}) | ||
endif (AGMG_FOUND) | ||
### --- end AGMG specific --- ### | ||
|
||
### --- begin opm-core specific --- ### | ||
# these solvers are only compiled in if their dependency is found | ||
if (NOT AGMG_FOUND) | ||
list (REMOVE_ITEM opm-core_SOURCES | ||
${PROJECT_SOURCE_DIR}/${opm-core_DIR}/core/linalg/LinearSolverAGMG.cpp | ||
) | ||
endif (NOT AGMG_FOUND) | ||
if (NOT dune-istl_FOUND) | ||
list (REMOVE_ITEM opm-core_SOURCES | ||
${PROJECT_SOURCE_DIR}/${opm-core_DIR}/core/linalg/LinearSolverIstl.cpp | ||
) | ||
endif (NOT dune-istl_FOUND) | ||
if (NOT SuiteSparse_FOUND) | ||
list (REMOVE_ITEM opm-core_SOURCES | ||
${PROJECT_SOURCE_DIR}/${opm-core_DIR}/core/linalg/call_umfpack.c | ||
${PROJECT_SOURCE_DIR}/${opm-core_DIR}/core/linalg/LinearSolverUmfpack.cpp | ||
) | ||
list (REMOVE_ITEM tutorial_SOURCES | ||
${PROJECT_SOURCE_DIR}/${tutorial_DIR}/tutorial2.cpp | ||
${PROJECT_SOURCE_DIR}/${tutorial_DIR}/tutorial3.cpp | ||
${PROJECT_SOURCE_DIR}/${tutorial_DIR}/tutorial4.cpp | ||
) | ||
list (REMOVE_ITEM examples_SOURCES | ||
${PROJECT_SOURCE_DIR}/${examples_DIR}/spu_2p.cpp | ||
) | ||
endif (NOT SuiteSparse_FOUND) | ||
|
||
# these files are provided in source control, but can only compile with Matlab | ||
# available; we are not supposed to include the TinyXML test prog. regardless | ||
list (REMOVE_ITEM opm-core_SOURCES | ||
${PROJECT_SOURCE_DIR}/${opm-core_DIR}/core/grid/cpgpreprocess/mxgrdecl.c | ||
${PROJECT_SOURCE_DIR}/${opm-core_DIR}/core/grid/cpgpreprocess/processgrid.c | ||
${PROJECT_SOURCE_DIR}/${opm-core_DIR}/core/utility/parameters/tinyxml/xmltest.cpp | ||
) | ||
|
||
# remove inline TinyXML if a system version was found | ||
if (TinyXML_FOUND) | ||
file (GLOB_RECURSE _inline_tinyxml "${opm-core_DIR}/core/utility/parameters/tinyxml/*") | ||
foreach (_file IN LISTS _inline_tinyxml) | ||
list (REMOVE_ITEM opm-core_SOURCES ${_file}) | ||
endforeach (_file) | ||
endif (TinyXML_FOUND) | ||
|
||
# anyhow remove it from the header list (so it doesn't get installed) | ||
list (REMOVE_ITEM opm-core_HEADERS "${opm-core_DIR}/core/utility/parameters/tinyxml/tinystr.h") | ||
list (REMOVE_ITEM opm-core_HEADERS "${opm-core_DIR}/core/utility/parameters/tinyxml/tinyxml.h") | ||
|
||
# HAVE_ERT is used as an #ifdef, not as an #if in the source code, if it | ||
# is not true, then it should be unset altogether | ||
if (NOT HAVE_ERT) | ||
set (HAVE_ERT) | ||
list (REMOVE_ITEM examples_SOURCES | ||
${PROJECT_SOURCE_DIR}/examples/import_rewrite.cpp | ||
) | ||
endif (NOT HAVE_ERT) | ||
### --- end opm-core specific --- ### | ||
|
||
# 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 | ||
# includes the necessary defines by the dependencies | ||
include (ConfigVars) | ||
list (APPEND ${project}_CONFIG_VARS ${${project}_CONFIG_VAR}) | ||
set (CONFIG_H "${PROJECT_BINARY_DIR}/config.h") | ||
configure_vars ( | ||
FILE CXX ${CONFIG_H} | ||
WRITE ${${project}_CONFIG_VARS} | ||
) | ||
|
||
include (UseFortranWrappers) | ||
define_fc_func ( | ||
APPEND ${CONFIG_H} | ||
IF HAVE_AGMG # HAVE_BLAS HAVE_LAPACK | ||
) | ||
|
||
# compile main library; pull in all required includes and libraries | ||
include (OpmCompile) | ||
opm_compile (${project}) | ||
|
||
# installation target: copy the library together with debug and | ||
# configuration files to system directories | ||
include (OpmInstall) | ||
opm_install (${project}) | ||
message (STATUS "This build defaults to installing in ${CMAKE_INSTALL_PREFIX}") | ||
|
||
# installation of CMake modules to help user programs locate the library | ||
include (OpmProject) | ||
opm_cmake_config (${project}) | ||
|
||
# routines to build satellites such as tests, tutorials and samples | ||
include (OpmSatellites) | ||
|
||
# tutorial programs are found in the tutorials/ directory | ||
opm_compile_satellites (${project} tutorial "" "") | ||
opm_compile_satellites (${project} examples "" "") | ||
|
||
# infrastructure for testing | ||
enable_testing () | ||
include (CTest) | ||
|
||
### --- begin opm-core specific --- ### | ||
# conditionally disable tests when features aren't available | ||
macro (cond_disable_test name) | ||
if ((NOT DEFINED HAVE_${name}) OR (NOT HAVE_${name})) | ||
message (STATUS "${name} test disabled, since ${name} is not found.") | ||
string (TOLOWER "${name}" name_lower) | ||
get_filename_component (test_${name}_FILE "tests/test_${name_lower}.cpp" ABSOLUTE) | ||
list (REMOVE_ITEM tests_SOURCES "${test_${name}_FILE}") | ||
endif ((NOT DEFINED HAVE_${name}) OR (NOT HAVE_${name})) | ||
endmacro (cond_disable_test name) | ||
cond_disable_test ("AGMG") | ||
cond_disable_test ("ERT") | ||
### --- end opm-core specific --- ### | ||
|
||
# make datafiles necessary for tests available in output directory | ||
opm_data (tests datafiles "${tests_DIR}" "*.xml") | ||
opm_compile_satellites (${project} tests "" "${tests_REGEXP}") | ||
|
||
# use this target to run all tests | ||
add_custom_target (check | ||
COMMAND ${CMAKE_CTEST_COMMAND} | ||
DEPENDS tests | ||
COMMENT "Checking if library is functional" | ||
VERBATIM | ||
) | ||
|
||
# generate documentation from source code with Doxygen; | ||
# setup install target for this documentation | ||
include (OpmDoc) | ||
opm_doc (${project} ${doxy_dir}) | ||
|
||
# provide compatibility with using this build in dunecontrol | ||
include (DuneCompat) | ||
include (LibtoolArchives) | ||
configure_la (${project} ${${project}_TARGET} ${project}_LIBTOOL_ARCHIVE) | ||
|
||
### clean in-source builds ### | ||
include (OpmDistClean) | ||
opm_dist_clean (${project}) | ||
|
||
# smart wrapper that auto-parallelizes builds | ||
file (COPY | ||
GNUmakefile | ||
DESTINATION ${PROJECT_BINARY_DIR} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# this is included after opm-core_NAME is set | ||
set(CTEST_PROJECT_NAME "${${project}_NAME}") | ||
set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC") | ||
set(CTEST_DROP_METHOD "http") | ||
set(CTEST_DROP_SITE "opm-project.org") | ||
set(CTEST_DROP_LOCATION "/CDash/submit.php?project=${${project}_NAME}") | ||
set(CTEST_DROP_SITE_CDASH TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# GNUmakefile is processed before Makefile, which is why we arrive here | ||
# first; when we call the other makefile, then we must specify its real | ||
# name with the -f parameter | ||
|
||
# figure out the number of processors from the system, add one and round | ||
# to nearest integer. this is the maximum number of processes we want running | ||
# at the same time (one for each core and one stuck on I/O) | ||
# if we are running this is a VM, then /proc won't be mounted and we revert | ||
# to single CPU processing | ||
CPUINFO:=/proc/cpuinfo | ||
NUM_CPUS:=$(shell test -r $(CPUINFO) && grep -P -c '^processor\t:' $(CPUINFO) || echo 0) | ||
PROCS:=$(shell echo "("$(NUM_CPUS)+1")"/1 | bc) | ||
|
||
# use these utilities if they are available | ||
IONICE:=$(shell test -x "$$(which ionice)" && echo ionice -c2 -n7) | ||
NICE:=$(shell test -x "$$(which nice)" && echo nice) | ||
|
||
# we do dependency management the right way; don't attempt to cache | ||
export CCACHE_DISABLE:=1 | ||
|
||
# ignore that there may be files with these names, we are going to call | ||
# the other make regardless | ||
.PHONY: __everything $(MAKECMDGOALS) | ||
|
||
# outsource the processing to the real makefile, running in parallel and | ||
# in a nice environment so that it doesn't hog our workstation. if there | ||
# is nothing else happening on the box, then it will run just as fast | ||
# the leading plus makes us run this regardless of options, see | ||
# http://www.gnu.org/software/make/manual/make.html#Instead-of-Execution | ||
__everything: | ||
# only put on a parallel flag if there isn't already one; otherwise we | ||
# get the warning "-jN forced in submake: disabling jobserver mode". | ||
# this have to happen inside the rule, because -j option is removed from | ||
# MAKEFLAGS outside | ||
+@$(IONICE) $(NICE) $(MAKE) --no-print-directory -f Makefile $(if $(findstring -j,$(MAKEFLAGS)),,-j $(PROCS)) $(MAKECMDGOALS) | ||
|
||
# automatically generate all the goals we are asked to make and delegate | ||
# processing of them to the real makefile through the dependency (since | ||
# everything depends on the same thing, then we only call the other make | ||
# once). the dummy command is just there to make sure that make doesn't | ||
# show the "Nothing to do for `foo'" message after processing | ||
$(MAKECMDGOALS): __everything | ||
@true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# - Add options without repeating them on the command line | ||
# | ||
# Synopsis: | ||
# | ||
# add_options (lang build opts) | ||
# | ||
# where: | ||
# | ||
# lang Name of the language whose compiler should receive the | ||
# options, e.g. CXX. If a comma-separated list is received | ||
# then the option is added for all those languages. Use the | ||
# special value ALL_LANGUAGES for these languages: CXX, C | ||
# and Fortran | ||
# | ||
# build Kind of build to which this options should apply, | ||
# such as DEBUG and RELEASE. This can also be a comma- | ||
# separated list. Use the special value ALL_BUILDS to apply | ||
# to all builds. | ||
# | ||
# opts List of options to add. Each should be quoted. | ||
# | ||
# Example: | ||
# | ||
# add_options (CXX RELEASE "-O3" "-DNDEBUG" "-Wall") | ||
|
||
function (add_options langs builds) | ||
# special handling of empty language specification | ||
if ("${langs}" STREQUAL "ALL_LANGUAGES") | ||
set (langs CXX C Fortran) | ||
endif ("${langs}" STREQUAL "ALL_LANGUAGES") | ||
foreach (lang IN LISTS langs) | ||
# prepend underscore if necessary | ||
foreach (build IN LISTS builds) | ||
if (NOT ("${build}" STREQUAL "ALL_BUILDS")) | ||
set (_bld "_${build}") | ||
string (TOUPPER "${_bld}" _bld) | ||
else (NOT ("${build}" STREQUAL "ALL_BUILDS")) | ||
set (_bld "") | ||
endif (NOT ("${build}" STREQUAL "ALL_BUILDS")) | ||
foreach (_opt IN LISTS ARGN) | ||
set (_var "CMAKE_${lang}_FLAGS${_bld}") | ||
#message (STATUS "Adding \"${_opt}\" to \${${_var}}") | ||
# remove it first | ||
string (REPLACE "${_opt}" "" _without "${${_var}}") | ||
string (STRIP "${_without}" _without) | ||
# if it wasn't there, then add it at the end | ||
if ("${_without}" STREQUAL "${${_var}}") | ||
# don't add any extra spaces if no options yet are set | ||
if (NOT ${${_var}} STREQUAL "") | ||
set (${_var} "${${_var}} ${_opt}") | ||
else (NOT ${${_var}} STREQUAL "") | ||
set (${_var} "${_opt}") | ||
endif (NOT ${${_var}} STREQUAL "") | ||
set (${_var} "${${_var}}" PARENT_SCOPE) | ||
endif ("${_without}" STREQUAL "${${_var}}") | ||
endforeach (_opt) | ||
endforeach (build) | ||
endforeach (lang) | ||
endfunction (add_options lang build) |
Oops, something went wrong.