From c7e70da2c50bc3175b92024900dae0f82b181fa3 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Thu, 2 Apr 2020 19:44:32 +0200 Subject: [PATCH 1/6] Do not call project another time in OpmLibMain Each project should and does this in their own top level CMakeLists.cmake at the very beginning anyway. --- cmake/Modules/OpmLibMain.cmake | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cmake/Modules/OpmLibMain.cmake b/cmake/Modules/OpmLibMain.cmake index be1e74402..4c63bcd8c 100644 --- a/cmake/Modules/OpmLibMain.cmake +++ b/cmake/Modules/OpmLibMain.cmake @@ -59,11 +59,6 @@ endif (CMAKE_VERSION VERSION_LESS "2.8.7") 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") From 742d8943ca05daf9faa110523abff820881a93bd Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Thu, 2 Apr 2020 19:52:21 +0200 Subject: [PATCH 2/6] Move policy settings to OpmInit and into a macro OpmSetPolicies(). OpmInit.cmake is one of the first includes and most importantly before the opm-*-prereqs.cmake files are include. The macro is needed to make the policies set in all CMakefiles. OpmSetPolicies should be called in the toplevel CMakeLists.txt file. This fixes a lot of warnings experienced in downstream modules that got triggered by the opm-*-prereqs.cmake files. At some calls the policies were at other not. On the other hand new warnings about soon to be deprecated policies CMP0026 and CMP0048 appear at least for cmake version 3.13.4. But that should be fixed in another PR. --- CMakeLists.txt | 1 + cmake/Modules/OpmInit.cmake | 43 ++++++++++++++++++++++++++++++++++ cmake/Modules/OpmLibMain.cmake | 39 ------------------------------ 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47f2d6b93..c4f871cb4 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/OpmInit.cmake b/cmake/Modules/OpmInit.cmake index e0f8b93dc..b85fad24d 100644 --- a/cmake/Modules/OpmInit.cmake +++ b/cmake/Modules/OpmInit.cmake @@ -12,6 +12,49 @@ # 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 +macro(OpmSetPolicies) + 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") +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/OpmLibMain.cmake b/cmake/Modules/OpmLibMain.cmake index 4c63bcd8c..cd22b7332 100644 --- a/cmake/Modules/OpmLibMain.cmake +++ b/cmake/Modules/OpmLibMain.cmake @@ -15,45 +15,6 @@ # 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) From 636ce45596a53656bd25537ef57a9ea0db69277f Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Thu, 2 Apr 2020 20:02:07 +0200 Subject: [PATCH 3/6] Set policy CMP0074 to NEW. We have been using _ROOT like it is intended now. --- cmake/Modules/OpmInit.cmake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmake/Modules/OpmInit.cmake b/cmake/Modules/OpmInit.cmake index b85fad24d..c8ddd97ba 100644 --- a/cmake/Modules/OpmInit.cmake +++ b/cmake/Modules/OpmInit.cmake @@ -18,6 +18,8 @@ # - 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) cmake_policy(SET CMP0026 OLD) @@ -37,6 +39,12 @@ macro(OpmSetPolicies) 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") From 67072633856f69ab80bf14f6ce9490fe8d112de9 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Thu, 2 Apr 2020 21:49:50 +0200 Subject: [PATCH 4/6] DUNE does not need special treatment. No need to set *_ROOT for it, which triggers a CMP0074 warning as the policy settings do not survive find_package calls. --- cmake/Modules/OpmFind.cmake | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) 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) From eb22f6cfd94d927dcd7a9c70e0b61464cd54d13f Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Thu, 2 Apr 2020 22:06:16 +0200 Subject: [PATCH 5/6] [CMake] Set PATH instead of LOCATION. --- cmake/Modules/OpmInstall.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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}/") From 8816549f2ff6ed995b504a98b9cd050b730c2ef5 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Thu, 2 Apr 2020 22:23:15 +0200 Subject: [PATCH 6/6] Try to set CMP0048 to NEW as we do not use VERSION --- cmake/Modules/OpmInit.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/OpmInit.cmake b/cmake/Modules/OpmInit.cmake index c8ddd97ba..0bdc2e51f 100644 --- a/cmake/Modules/OpmInit.cmake +++ b/cmake/Modules/OpmInit.cmake @@ -22,11 +22,13 @@ # 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) - cmake_policy(SET CMP0048 OLD) + # We do not set version. Hence NEW should work and this can be removed later + cmake_policy(SET CMP0048 NEW) endif() if(POLICY CMP0064)