Files
opm-core/CMakeLists.txt

156 lines
5.1 KiB
CMake
Raw Normal View History

2012-11-14 12:45:48 +01:00
# -*- 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:
cmake_minimum_required (VERSION 2.8)
project (opm-core)
2012-11-15 11:36:50 +01:00
set (opm-core_MAJOR_VERSION 0)
set (opm-core_MINOR_VERSION 3)
2012-11-14 12:45:48 +01:00
enable_language (CXX)
# build debug by default
if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "Debug")
endif (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
message (STATUS "Build type: ${CMAKE_BUILD_TYPE}")
2012-11-14 12:45:48 +01:00
# all public header files are together with the source
set (opm-core_INCLUDE_DIR "${PROJECT_SOURCE_DIR}")
list (APPEND opm-core_INCLUDE_DIRS "${opm-core_INCLUDE_DIR}")
2012-11-14 12:45:48 +01:00
# additional search modules
list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules")
# macro to set standard variables (INCLUDE_DIRS, LIBRARIES etc.)
include (OpmFind)
# dependencies
list (APPEND opm-core_DEPS
# compile with C++0x/11 support if available
"CXX11Features REQUIRED"
# matrix library
"BLAS REQUIRED"
"LAPACK REQUIRED"
# Tim Davis' SuiteSparse archive
"SuiteSparse COMPONENTS umfpack"
# solver
"SUPERLU"
# xml processing (for config parsing)
"LibXml2 REQUIRED"
# various runtime library enhancements
"Boost 1.39.0
COMPONENTS date_time filesystem system unit_test_framework REQUIRED"
# DUNE dependency
"dune-istl"
)
find_and_append_package_list (${opm-core_DEPS})
2012-11-29 12:36:29 +01:00
# put debug information into every executable
include (UseDebugSymbols)
2012-11-29 13:09:56 +01:00
# optimize full if we're not doing a debug build
include (UseOptimization)
2012-11-29 13:12:13 +01:00
# turn on all warnings
include (UseWarnings)
# detect if Boost is in a shared library
include (UseDynamicBoost)
2012-11-17 00:36:54 +01:00
2012-11-14 12:45:48 +01:00
# put libraries in lib/
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
2012-11-14 12:45:48 +01:00
# find all the source code
file (GLOB_RECURSE opm-core_SOURCES "opm/*.c" "opm/*.cpp")
# these files are provided in source control, but can only compile with Matlab
# available
list (REMOVE_ITEM opm-core_SOURCES
${PROJECT_SOURCE_DIR}/opm/core/grid/cpgpreprocess/mxgrdecl.c
${PROJECT_SOURCE_DIR}/opm/core/grid/cpgpreprocess/processgrid.c
${PROJECT_SOURCE_DIR}/opm/core/utility/parameters/tinyxml/xmltest.cpp
${PROJECT_SOURCE_DIR}/opm/core/linalg/LinearSolverAGMG.cpp
)
# we don't try to find any of these
set (HAVE_AGMG 0)
set (HAVE_ERT)
# 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)
set (opm-core_CONFIG_VAR
HAVE_AGMG
HAVE_DUNE_ISTL
HAVE_DYNAMIC_BOOST_TEST
HAVE_ERT
HAVE_SUITESPARSE_UMFPACK_H
HAVE_NULLPTR
HAVE_STATIC_ASSERT
)
list (APPEND opm-core_CONFIG_VARS ${opm-core_CONFIG_VAR})
configure_vars (
FILE "${PROJECT_BINARY_DIR}/config.h"
WRITE ${opm-core_CONFIG_VARS}
)
# some CMake properties do not do list expansion
list (REMOVE_DUPLICATES opm-core_LINKER_FLAGS)
string (REPLACE ";" " " opm-core_LINKER_FLAGS_STR "${opm-core_LINKER_FLAGS}")
remove_duplicate_libraries (opm-core)
2012-11-14 12:45:48 +01:00
# create this library
include_directories (${opm-core_INCLUDE_DIRS})
link_directories (${opm-core_LIBRARY_DIRS})
add_definitions (${opm-core_DEFINITIONS})
2012-11-14 12:45:48 +01:00
add_library (opmcore SHARED ${opm-core_SOURCES})
2012-11-15 11:36:50 +01:00
set_target_properties (opmcore PROPERTIES
SOVERSION ${opm-core_MAJOR_VERSION}
VERSION ${opm-core_MAJOR_VERSION}.${opm-core_MINOR_VERSION}
LINK_FLAGS "${opm-core_LINKER_FLAGS_STR}"
2012-11-15 11:36:50 +01:00
)
target_link_libraries (opmcore ${opm-core_LIBRARIES})
2012-11-29 12:36:29 +01:00
# queue this executable to be stripped
strip_debug_symbols (LIBRARY opmcore)
# we need to know the name of the library which is generated
get_target_property (opm-core_LIBRARY opmcore LOCATION)
# write configuration file to locate library
set (opm-core_VERSION "${opm-core_MAJOR_VERSION}.${opm-core_MINOR_VERSION}")
configure_file (
${PROJECT_SOURCE_DIR}/opm-core-config.cmake.in
${PROJECT_BINARY_DIR}/opm-core-config.cmake
@ONLY
)
### test programs ###
# find the source code
file (GLOB_RECURSE tests_SOURCES "tests/*.c" "tests/*.cpp")
# 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")
# compile each of these separately
foreach (test_FILE IN LISTS tests_SOURCES)
get_filename_component (test_NAME "${test_FILE}" NAME_WE)
add_executable (${test_NAME} ${test_FILE})
set_target_properties (${test_NAME} PROPERTIES
LINK_FLAGS "${opm-core_LINKER_FLAGS_STR}"
)
target_link_libraries (${test_NAME} opmcore ${opm-core_LIBRARIES})
2012-11-29 12:36:29 +01:00
strip_debug_symbols (RUNTIME ${test_NAME})
endforeach (test_FILE)