Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Modernize DEAL_II_PACKAGE_HANDLE macro and clean up Find*.cmake files #13325

Merged
merged 10 commits into from
Feb 7, 2022
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
MESSAGE(STATUS "This is CMake ${CMAKE_VERSION}")
MESSAGE(STATUS "")

CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we currently require 3.1 according to https://www.dealii.org/developer/readme.html
Do you need 3.3? If yes then we need to adjust.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I chose to simply bump to 3.3.0. It will make some cleanup of the CMake code I plan to do easier - and version 3.3.0 is reasonably ancient (Ubuntu 16.04 LTS already shipped 3.5.0). I have adjusted the readme and the rest of the documentation to state 3.3.0.


#
# We support all policy changes up to version 3.1.0. Thus, explicitly set
# all policies CMP0001 - CMP0054 to new for version 3.1 (and later) to
# avoid some unnecessary warnings.
# We support all policy changes up to version 3.3. Thus, explicitly set all
# policies CMP0001 - CMP0054 to new for version 3.3 (and later) to avoid
# some unnecessary warnings.
#
CMAKE_POLICY(VERSION 3.1.0)
CMAKE_POLICY(VERSION 3.3.0)

IF("${CMAKE_VERSION}" VERSION_LESS "3.11" AND POLICY CMP0037)
# allow to override "test" target for quick tests
Expand Down
115 changes: 63 additions & 52 deletions cmake/macros/macro_deal_ii_package_handle.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# search.
#

MACRO(DEAL_II_PACKAGE_HANDLE _feature _var)
MACRO(DEAL_II_PACKAGE_HANDLE _feature)

IF(DEFINED ${_feature}_VERSION)
MESSAGE(STATUS " ${_feature}_VERSION: ${${_feature}_VERSION}")
Expand All @@ -60,98 +60,109 @@ MACRO(DEAL_II_PACKAGE_HANDLE _feature _var)
SET(${_feature}_FOUND TRUE)
ENDIF()

SET(_variable ${_var})
SET(${_feature}_${_variable} "")
#
# Clear temporary variables
#
FOREACH(_suffix ${DEAL_II_LIST_SUFFIXES} ${DEAL_II_STRING_SUFFIXES})
set(_temp_${_suffix} "")
tamiko marked this conversation as resolved.
Show resolved Hide resolved
ENDFOREACH()

#
# State variables for parsing keywords and arguments. We store the
# currently encountered keyword in ${_current_suffix} and store the fact
# whether we encountered an "OPTIONAL" or "REQUIRED" keyword in
# ${_required}
#
SET(_current_suffix "")
SET(_required TRUE)
SET(_fine TRUE)
SET(_fill_clear FALSE)
SET(_clear "")

CLEAR_FEATURE(${_feature})
#
# A temporary list accumulating all variables that should be "cleared"
# when the feature gets disabled.
#
SET(_clear_variables_list "")

FOREACH(_arg ${ARGN})
IF(_arg MATCHES "^LIBRARIES(|_DEBUG|_RELEASE)$"
OR _arg MATCHES "^(|BUNDLED_|USER_)INCLUDE_DIRS$"
OR _arg MATCHES "^(|USER_)DEFINITIONS(|_DEBUG|_RELEASE)$"
OR _arg MATCHES "^CXX_FLAGS(|_DEBUG|_RELEASE)"
OR _arg MATCHES "^LINKER_FLAGS(|_DEBUG|_RELEASE)"
OR _arg MATCHES "^EXECUTABLE(|_DEBUG|_RELEASE)")

IF(_fine)
IF(_variable MATCHES "^CXX_FLAGS(|_DEBUG|_RELEASE)"
OR _variable MATCHES "^LINKER_FLAGS(|_DEBUG|_RELEASE)")
TO_STRING(${_feature}_${_variable} ${${_feature}_${_variable}})
ENDIF()
MESSAGE(STATUS " ${_feature}_${_variable}: ${${_feature}_${_variable}}")
ENDIF()

IF(("${_arg}" IN_LIST DEAL_II_LIST_SUFFIXES) OR
("${_arg}" IN_LIST DEAL_II_STRING_SUFFIXES) OR
("${_arg}" STREQUAL "CLEAR"))
#
# *Yay* a new keyword.
# We encountered a new keyword.
#
SET(_variable ${_arg})
SET(${_feature}_${_variable} "")
SET(_required TRUE)
SET(_fine TRUE)
SET(_current_suffix "${_arg}")

ELSEIF("${_arg}" STREQUAL "REQUIRED")
SET(_required TRUE)

ELSEIF("${_arg}" STREQUAL "OPTIONAL")
SET(_required FALSE)

ELSEIF(_arg MATCHES "^(optimized|debug|general)$"
AND "${_variable}" STREQUAL "LIBRARIES")
#
# Keywords are special...
#
LIST(APPEND ${_feature}_${_variable} ${_arg})
ELSEIF("${_arg}" STREQUAL "CLEAR")
SET(_fill_clear TRUE)
AND "${_current_suffix}" STREQUAL "LIBRARIES")
LIST(APPEND _temp_${_current_suffix} ${_arg})

ELSE()
IF ("${_current_suffix}" STREQUAL "")
MESSAGE(FATAL_ERROR
"Internal configuration error: the second "
"argument to DEAL_II_PACKAGE_HANDLE must be a keyword"
)
ENDIF()

MARK_AS_ADVANCED(${_arg})
IF(_fill_clear)

IF("${_current_suffix}" STREQUAL "CLEAR")
IF(NOT _arg MATCHES "^(optimized|debug|general)$")
LIST(APPEND _clear ${_arg})
LIST(APPEND _clear_variables_list ${_arg})
ENDIF()

ELSE()

IF("${${_arg}}" MATCHES "^\\s*$" OR "${${_arg}}" MATCHES "-NOTFOUND")
IF(_required AND _fine)
IF(_required)
IF("${${_arg}}" MATCHES "^\\s*$")
MESSAGE(STATUS
" ${_feature}_${_variable}: *** Required variable \"${_arg}\" empty ***"
" ${_feature}_${_current_suffix}: *** Required variable \"${_arg}\" empty ***"
)
ELSE()
MESSAGE(STATUS
" ${_feature}_${_variable}: *** Required variable \"${_arg}\" set to NOTFOUND ***"
" ${_feature}_${_current_suffix}: *** Required variable \"${_arg}\" set to NOTFOUND ***"
)
ENDIF()
SET(${_feature}_FOUND FALSE)
SET(_fine FALSE)
ENDIF()
ELSE()
LIST(APPEND ${_feature}_${_variable} ${${_arg}})
LIST(APPEND _temp_${_current_suffix} ${${_arg}})
ENDIF()
ENDIF()
ENDIF()
ENDFOREACH()

SET(${_feature}_CLEAR_VARIABLES ${_clear} CACHE INTERNAL "")

IF(_fine)
IF(_variable MATCHES "^CXX_FLAGS(|_DEBUG|_RELEASE)"
OR _variable MATCHES "^LINKER_FLAGS(|_DEBUG|_RELEASE)")
TO_STRING(${_feature}_${_variable} ${${_feature}_${_variable}})
ENDIF()
MESSAGE(STATUS " ${_feature}_${_variable}: ${${_feature}_${_variable}}")
ENDIF()

IF(${_feature}_FOUND)
#
# Deduplicate entries:
# Deduplicate and stringify entries:
#
FOREACH(_suffix ${DEAL_II_LIST_SUFFIXES})
IF(_suffix MATCHES "INCLUDE_DIRS$")
REMOVE_DUPLICATES(${_feature}_${_suffix})
REMOVE_DUPLICATES(_temp_${_suffix})
ELSE()
REMOVE_DUPLICATES(${_feature}_${_suffix} REVERSE)
REMOVE_DUPLICATES(_temp_${_suffix} REVERSE)
ENDIF()
ENDFOREACH()
FOREACH(_suffix ${_DEAL_II_STRING_SUFFIXES})
TO_STRING(_temp_${_suffix} ${_temp_${_suffix}})
ENDFOREACH()

#
# Write back into global variables:
#
CLEAR_FEATURE(${_feature})
FOREACH(_suffix ${DEAL_II_LIST_SUFFIXES} ${DEAL_II_STRING_SUFFIXES})
IF(NOT "${_temp_${_suffix}}" STREQUAL "")
set(${_feature}_${_suffix} "${_temp_${_suffix}}")
MESSAGE(STATUS " ${_feature}_${_suffix}: ${${_feature}_${_suffix}}")
ENDIF()
ENDFOREACH()

Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/FindADOLC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ DEAL_II_PACKAGE_HANDLE(ADOLC
LIBRARIES
REQUIRED ADOLC_LIBRARY
${_additional_library}
INCLUDE_DIRS
INCLUDE_DIRS
REQUIRED ADOLC_INCLUDE_DIR
${_additional_include_dirs}
USER_INCLUDE_DIRS
USER_INCLUDE_DIRS
REQUIRED ADOLC_INCLUDE_DIR
${_additional_include_dirs}
CLEAR ADOLC_INCLUDE_DIR ADOLC_LIBRARY ADOLC_SETTINGS_H
Expand Down
9 changes: 3 additions & 6 deletions cmake/modules/FindCUDA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ IF(CUDA_FOUND)
MESSAGE(STATUS "Configured to use CUDA installation at ${CUDA_TOOLKIT_ROOT_DIR}")
ENDIF()

SET(_cuda_libraries ${CUDA_LIBRARIES} ${CUDA_cusparse_LIBRARY}
${CUDA_cusolver_LIBRARY})
SET(_cuda_include_dirs ${CUDA_INCLUDE_DIRS})
DEAL_II_PACKAGE_HANDLE(CUDA
LIBRARIES REQUIRED _cuda_libraries
INCLUDE_DIRS REQUIRED _cuda_include_dirs
USER_INCLUDE_DIRS REQUIRED _cuda_include_dirs
LIBRARIES REQUIRED CUDA_LIBRARIES CUDA_cusparse_LIBRARY CUDA_cusolver_LIBRARY
INCLUDE_DIRS REQUIRED CUDA_INCLUDE_DIRS
USER_INCLUDE_DIRS REQUIRED CUDA_INCLUDE_DIRS
CLEAR
CUDA_cublas_device_LIBRARY
CUDA_cublas_LIBRARY
Expand Down
13 changes: 4 additions & 9 deletions cmake/modules/FindLAPACK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,13 @@ IF(NOT BUILD_SHARED_LIBS)
ENDIF()


SET(_lapack_include_dirs ${LAPACK_INCLUDE_DIRS})
SET(_lapack_libraries ${LAPACK_LIBRARIES})
SET(_lapack_linker_flags ${LAPACK_LINKER_FLAGS})
DEAL_II_PACKAGE_HANDLE(LAPACK
LIBRARIES
REQUIRED _lapack_libraries
REQUIRED LAPACK_LIBRARIES
OPTIONAL BLAS_LIBRARIES ${_additional_libraries}
LINKER_FLAGS OPTIONAL _lapack_linker_flags BLAS_LINKER_FLAGS
INCLUDE_DIRS
OPTIONAL _lapack_include_dirs
USER_INCLUDE_DIRS
OPTIONAL _lapack_include_dirs
LINKER_FLAGS OPTIONAL LAPACK_LINKER_FLAGS BLAS_LINKER_FLAGS
INCLUDE_DIRS OPTIONAL LAPACK_INCLUDE_DIRS
USER_INCLUDE_DIRS OPTIONAL LAPACK_INCLUDE_DIRS
CLEAR
atlas_LIBRARY atlcblas_LIBRARY atllapack_LIBRARY blas_LIBRARY
eigen_blas_LIBRARY f77blas_LIBRARY gslcblas_LIBRARY lapack_LIBRARY
Expand Down
16 changes: 8 additions & 8 deletions cmake/modules/FindSYMENGINE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ _symengine_feature_check(LLVM "#define.*HAVE_SYMENGINE_LLVM")

STRING(REGEX REPLACE
"(lib64|lib)\\/cmake\\/symengine\\/\\.\\.\\/\\.\\.\\/\\.\\.\\/" ""
_symengine_include_dirs "${SYMENGINE_INCLUDE_DIRS}"
SYMENGINE_INCLUDE_DIRS "${SYMENGINE_INCLUDE_DIRS}"
)
REMOVE_DUPLICATES(_symengine_include_dirs)
REMOVE_DUPLICATES(SYMENGINE_INCLUDE_DIRS)

#
# Get the full path for the SYMENGINE_LIBRARIES. Some of these libraries are
# Get the full path for the SYMENGINE_LIBRARIES. Some of these libraries are
# CMake targets, so we can query them directly for this information.
#
#
FOREACH(SYMENGINE_LIBRARY_NAME ${SYMENGINE_LIBRARIES})
IF (TARGET ${SYMENGINE_LIBRARY_NAME})
GET_PROPERTY(SYMENGINE_LIBRARY TARGET ${SYMENGINE_LIBRARY_NAME} PROPERTY LOCATION)
Expand All @@ -130,11 +130,11 @@ FOREACH(SYMENGINE_LIBRARY_NAME ${SYMENGINE_LIBRARIES})

SET(_symengine_libraries ${_symengine_libraries} ${SYMENGINE_LIBRARY})
ENDFOREACH()

SET(SYMENGINE_LIBRARIES ${_symengine_libraries})

DEAL_II_PACKAGE_HANDLE(SYMENGINE
LIBRARIES REQUIRED _symengine_libraries
INCLUDE_DIRS REQUIRED _symengine_include_dirs
USER_INCLUDE_DIRS REQUIRED _symengine_include_dirs
LIBRARIES REQUIRED SYMENGINE_LIBRARIES
INCLUDE_DIRS REQUIRED SYMENGINE_INCLUDE_DIRS
USER_INCLUDE_DIRS REQUIRED SYMENGINE_INCLUDE_DIRS
CLEAR SYMENGINE_SETTINGS_H SYMENGINE_SKIP_DEPENDENCIES SymEngine_DIR
)
4 changes: 2 additions & 2 deletions cmake/setup_deal_ii.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ SET(DEAL_II_LIST_SUFFIXES
)

SET(DEAL_II_STRING_SUFFIXES
CXX_FLAGS CXX_FLAGS_RELEASE CXX_FLAGS_DEBUG
LINKER_FLAGS LINKER_FLAGS_RELEASE LINKER_FLAGS_DEBUG
EXECUTABLE CXX_FLAGS CXX_FLAGS_RELEASE CXX_FLAGS_DEBUG LINKER_FLAGS
LINKER_FLAGS_RELEASE LINKER_FLAGS_DEBUG
)


Expand Down
2 changes: 1 addition & 1 deletion cmake/setup_write_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ FOREACH(_feature ${_deal_ii_features_sorted})
# Print the feature configuration:
#
FOREACH(_var2
C_COMPILER CXX_COMPILER Fortran_COMPILER EXE WITH_64BIT_BLAS_INDICES
C_COMPILER CXX_COMPILER Fortran_COMPILER WITH_64BIT_BLAS_INDICES
${DEAL_II_STRING_SUFFIXES} ${DEAL_II_LIST_SUFFIXES}
)
IF(DEFINED ${_feature}_${_var2})
Expand Down
2 changes: 1 addition & 1 deletion doc/developers/testsuite.html
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ <h2>Adding new categories</h2>
a <code>CMakeLists.txt</code> file into it containing
</p>
<pre>
CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
INCLUDE(../setup_testsubproject.cmake)
PROJECT(testsuite CXX)
INCLUDE(${DEAL_II_TARGET_CONFIG})
Expand Down
5 changes: 5 additions & 0 deletions doc/news/changes/minor/20220206Maier
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Changed: The minimum CMake version required to configure and build deal.II
has been raised to 3.3.0.
<br>
(Matthias Maier, 2022/02/06)

2 changes: 1 addition & 1 deletion doc/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h3>Additional software requirements</h3>
</p>
<ul>
<li>
<a href="http://www.cmake.org/" target="_top">CMake</a> version 3.1.0 or later
<a href="http://www.cmake.org/" target="_top">CMake</a> version 3.3.0 or later
</li>

<li>
Expand Down
2 changes: 1 addition & 1 deletion doc/users/CMakeLists.txt.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)

FIND_PACKAGE(deal.II 10.0.0 REQUIRED
HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
Expand Down
2 changes: 1 addition & 1 deletion doc/users/CMakeLists.txt.sample2
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SET(TARGET_SRC
${TARGET}.cc
)

CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
DEAL_II_INITIALIZE_CACHED_VARIABLES()
PROJECT(${TARGET} CXX)
DEAL_II_INVOKE_AUTOPILOT()
2 changes: 1 addition & 1 deletion doc/users/CMakeLists.txt.sample3
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ SET(TARGET_RUN
# a custom command line, e.g. mpirun -np 2 ${TARGET}
)

CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
DEAL_II_INITIALIZE_CACHED_VARIABLES()
PROJECT(${TARGET} CXX)
DEAL_II_INVOKE_AUTOPILOT()
6 changes: 3 additions & 3 deletions doc/users/cmake_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h2>Simple CMakeLists.txt</h2>
version):

<pre class="cmake">
CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)

FIND_PACKAGE(deal.II 10.0.0 REQUIRED
HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
Expand Down Expand Up @@ -271,7 +271,7 @@ <h3>Source directory layout</h3>
In this case the top level <code>CMakeLists.txt</code> file may be:
<pre class="cmake">
# top level CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
FIND_PACKAGE(deal.II 10.0.0 REQUIRED)

DEAL_II_INITIALIZE_CACHED_VARIABLES()
Expand Down Expand Up @@ -663,7 +663,7 @@ <h2>Autopilot style CMakeLists.txt</h2>
# You can specify additional files here!
)

CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
DEAL_II_INITIALIZE_CACHED_VARIABLES()
PROJECT(${TARGET} CXX)
DEAL_II_INVOKE_AUTOPILOT()
Expand Down
4 changes: 2 additions & 2 deletions doc/users/testsuite.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h3>Simple configuration</h3>
SET(TARGET step-1)
SET(TARGET_SRC step-1.cc)

CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
FIND_PACKAGE(deal.II 10.0.0 REQUIRED
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
)
Expand Down Expand Up @@ -215,7 +215,7 @@ <h3>Advanced configuration</h3>
<pre class="cmake">
# top-level CMakelists.txt

CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
FIND_PACKAGE(deal.II 10.0.0 REQUIRED
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
)
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# prune_tests - remove all testsuite subprojects
#

CMAKE_MINIMUM_REQUIRED(VERSION 3.1.0)
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)

MACRO(SET_IF_EMPTY _variable)
IF("${${_variable}}" STREQUAL "")
Expand Down