diff --git a/CMakeLists.txt b/CMakeLists.txt index 385a09a09..10267b57d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,7 @@ endif() # we cannot generate dune.module since it is read by dunecontrol before # the build starts, so it makes sense to keep the data there then. include (OpmInit) +OpmSetPolicies() # Look for the opm-tests repository; if found the variable # HAVE_OPM_TESTS will be set to true. diff --git a/cmake/Modules/OpmFind.cmake b/cmake/Modules/OpmFind.cmake index 9eb0fc46b..1cab56d56 100644 --- a/cmake/Modules/OpmFind.cmake +++ b/cmake/Modules/OpmFind.cmake @@ -54,17 +54,6 @@ foreach (name IN LISTS _opm_proj_vars) endif (NOT DEFINED ${CMAKE_PROJECT_NAME}_${name}) endforeach (name) -# these dependencies needs special treatment -set (_opm_proj_exemptions - dune-common - dune-istl - dune-grid - dune-geometry - dune-uggrid - dune-alugrid - dune-localfunctions - dune-fem - ) # insert this boilerplate whenever we are going to find a new package macro (find_and_append_package_to prefix name) @@ -115,21 +104,6 @@ macro (find_and_append_package_to prefix name) endif (EXISTS ${${NAME}_ROOT}/${name}-config.cmake OR EXISTS ${${NAME}_ROOT}/${name}Config.cmake) endif (NOT DEFINED ${name}_DIR AND (DEFINED ${name}_ROOT OR DEFINED ${NAME}_ROOT)) - # these libraries need special handling which is not provided in - # the -config.cmake file, but which must be provided by this project, - # something which is done in our find module - list (FIND _opm_proj_exemptions "${name}" _${name}_exempted) - if ((NOT (_${name}_exempted EQUAL -1)) AND (DEFINED ${name}_DIR)) - set (${name}_ROOT "${${name}_DIR}") - # store this for later, in case we reconfigure - set (${name}_ROOT "${${name}_ROOT}" CACHE LOCATION "Path to ${name}") - # clear this to not use config mode - unset (${name}_DIR) - # variables that are given on the command-line is also put in the cache - # removing the local copy only "unshadows" this one - unset (${name}_DIR CACHE) - endif ((NOT (_${name}_exempted EQUAL -1)) AND (DEFINED ${name}_DIR)) - # if we're told not to look for the package, pretend it was never found if (CMAKE_DISABLE_FIND_PACKAGE_${name}) set (${name}_FOUND FALSE) @@ -151,10 +125,8 @@ macro (find_and_append_package_to prefix name) # and the likes which is only done via opm_find_package if ( (NOT DEFINED ${name}_FOUND AND NOT DEFINED ${NAME}_FOUND ) OR _search_components GREATER -1) - string(REGEX MATCH "(dune|opm)-.*" _is_opm ${name}) - if(_${name}_exempted LESS 0 AND NOT _is_opm) - find_package (${name} ${ARGN}) - elseif(_${name}_exempted GREATER -1) + string(REGEX MATCH "(opm)-.*" _is_opm ${name}) + if(NOT _is_opm) find_package (${name} ${ARGN}) else() if(${name}_DIR) diff --git a/cmake/Modules/OpmInit.cmake b/cmake/Modules/OpmInit.cmake index e0f8b93dc..0bdc2e51f 100644 --- a/cmake/Modules/OpmInit.cmake +++ b/cmake/Modules/OpmInit.cmake @@ -12,6 +12,59 @@ # This module should be the first to be included in the project, # because most of the others (OpmXxx.cmake) use these variables. +# for CMake >= 3.0, we need to change a few policies: +# +# - CMP0026 to allow access to the LOCATION target property +# - CMP0048 to indicate that we want to deal with the *VERSION* +# variables ourselves +# - CMP0064 to indicate that we want TEST if conditions to be evaluated +# - CMP0074 to indicate that _ROOT can be used to find package +# config files +macro(OpmSetPolicies) + if (POLICY CMP0026) + # Needed as we query LOCATION in OpmCompile.cmake and OpmSatellites.cmake + cmake_policy(SET CMP0026 OLD) + endif() + + if (POLICY CMP0048) + # We do not set version. Hence NEW should work and this can be removed later + cmake_policy(SET CMP0048 NEW) + endif() + + if(POLICY CMP0064) + cmake_policy(SET CMP0064 NEW) + endif() + + # set the behavior of the policy 0054 to NEW. (i.e. do not implicitly + # expand variables in if statements) + if (POLICY CMP0054) + cmake_policy(SET CMP0054 NEW) + endif() + + # set the behavior of policy 0074 to new as we always used _ROOT as the + # root of the installation + if(POLICY CMP0074) + cmake_policy(SET CMP0074 NEW) + endif() + + # include special + if (CMAKE_VERSION VERSION_LESS "2.8.3") + message (STATUS "Enabling compatibility modules for CMake 2.8.3") + list (APPEND CMAKE_MODULE_PATH "${OPM_MACROS_ROOT}/cmake/Modules/compat-2.8.3") + endif (CMAKE_VERSION VERSION_LESS "2.8.3") + + if (CMAKE_VERSION VERSION_LESS "2.8.5") + message (STATUS "Enabling compatibility modules for CMake 2.8.5") + list (APPEND CMAKE_MODULE_PATH "${OPM_MACROS_ROOT}/cmake/Modules/compat-2.8.5") + endif (CMAKE_VERSION VERSION_LESS "2.8.5") + + if (CMAKE_VERSION VERSION_LESS "2.8.7") + message (STATUS "Enabling compatibility modules for CMake 2.8.7") + list (APPEND CMAKE_MODULE_PATH "${OPM_MACROS_ROOT}/cmake/Modules/compat-2.8.7") + endif (CMAKE_VERSION VERSION_LESS "2.8.7") +endmacro() + + # helper macro to retrieve a single field of a dune.module file macro(OpmGetDuneModuleDirective field variable contents) string (REGEX MATCH ".*${field}:[ ]*([^\n]+).*" ${variable} "${contents}") diff --git a/cmake/Modules/OpmInstall.cmake b/cmake/Modules/OpmInstall.cmake index 7e1c5a730..eedfc5430 100644 --- a/cmake/Modules/OpmInstall.cmake +++ b/cmake/Modules/OpmInstall.cmake @@ -40,7 +40,7 @@ macro (opm_install opm) set (_sys_dbg_def OFF) endif (CMAKE_INSTALL_PREFIX STREQUAL "/usr") option (SYSTEM_DEBUG "Put .debug files in GDB debug file directory" ${_sys_dbg_def}) - set (DEBUG_FILE_DIRECTORY /usr/lib/debug CACHE LOCATION "GDB debug file directory") + set (DEBUG_FILE_DIRECTORY /usr/lib/debug CACHE PATH "GDB debug file directory") mark_as_advanced (DEBUG_FILE_DIRECTORY) if (SYSTEM_DEBUG AND NOT APPLE) set (_dbg_prefix "${DEBUG_FILE_DIRECTORY}/") diff --git a/cmake/Modules/OpmLibMain.cmake b/cmake/Modules/OpmLibMain.cmake index be1e74402..cd22b7332 100644 --- a/cmake/Modules/OpmLibMain.cmake +++ b/cmake/Modules/OpmLibMain.cmake @@ -15,55 +15,11 @@ # tests_hook Do special processing before tests are compiled # files_hook Do special processing before final targets are added -# for CMake >= 3.0, we need to change a few policies: -# -# - CMP0026 to allow access to the LOCATION target property -# - CMP0048 to indicate that we want to deal with the *VERSION* -# variables ourselves -# - CMP0064 to indicate that we want TEST if conditions to be evaluated -if (POLICY CMP0026) - cmake_policy(SET CMP0026 OLD) -endif() - -if (POLICY CMP0048) - cmake_policy(SET CMP0048 OLD) -endif() - -if(POLICY CMP0064) - cmake_policy(SET CMP0064 NEW) -endif() - -# set the behavior of the policy 0054 to NEW. (i.e. do not implicitly -# expand variables in if statements) -if (POLICY CMP0054) - cmake_policy(SET CMP0054 NEW) -endif() - -# include special -if (CMAKE_VERSION VERSION_LESS "2.8.3") - message (STATUS "Enabling compatibility modules for CMake 2.8.3") - list (APPEND CMAKE_MODULE_PATH "${OPM_MACROS_ROOT}/cmake/Modules/compat-2.8.3") -endif (CMAKE_VERSION VERSION_LESS "2.8.3") - -if (CMAKE_VERSION VERSION_LESS "2.8.5") - message (STATUS "Enabling compatibility modules for CMake 2.8.5") - list (APPEND CMAKE_MODULE_PATH "${OPM_MACROS_ROOT}/cmake/Modules/compat-2.8.5") -endif (CMAKE_VERSION VERSION_LESS "2.8.5") - -if (CMAKE_VERSION VERSION_LESS "2.8.7") - message (STATUS "Enabling compatibility modules for CMake 2.8.7") - list (APPEND CMAKE_MODULE_PATH "${OPM_MACROS_ROOT}/cmake/Modules/compat-2.8.7") -endif (CMAKE_VERSION VERSION_LESS "2.8.7") # don't write default flags into the cache, preserve that for user set values include (AddOptions) no_default_options () -# C++ project -project (${${project}_NAME}) -enable_language (C) -enable_language (CXX) - # Languages and global compiler settings if(CMAKE_VERSION VERSION_LESS 3.8) message(WARNING "CMake version does not support c++17, guessing -std=c++17")