From 7ccf207c33fc7d61e2941a0f567be95eeb4c68af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 24 Feb 2025 13:01:36 +0100 Subject: [PATCH] Add support for CMake 4.0 --- CMakeLists.txt | 45 ++++++++++++++++---------------- cmake/FindCUDACompilerNVCC.cmake | 13 --------- cmake/walberla.patch | 6 +++++ 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed63501d311..d025b80660f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,14 +21,6 @@ cmake_minimum_required(VERSION 3.25.1) cmake_policy(VERSION 3.25.1) -if(POLICY CMP0167) - # use BoostConfig.cmake shipped with Boost 1.70+ instead of the one in CMake - cmake_policy(SET CMP0167 NEW) -endif() -if(POLICY CMP0169) - # use deprecated FetchContent_Populate function for h5xx dependency - cmake_policy(SET CMP0169 OLD) -endif() message(STATUS "CMake version: ${CMAKE_VERSION}") # CMake modules/macros are in a subdirectory to keep this file cleaner set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) @@ -64,6 +56,7 @@ endif() include(FeatureSummary) include(GNUInstallDirs) +include(ExternalProject) include(FetchContent) include(espresso_option_enum) include(espresso_enable_avx2_support) @@ -114,11 +107,6 @@ FetchContent_Declare( GIT_REPOSITORY https://github.com/hmenke/espresso-stokesian-dynamics.git GIT_TAG 90f6de70d1c0ac9cf468f2fc90f9c601139e4c88 ) -FetchContent_Declare( - h5xx - GIT_REPOSITORY https://github.com/h5md/h5xx.git - GIT_TAG 0.9.1 -) FetchContent_Declare( caliper GIT_REPOSITORY https://github.com/LLNL/Caliper.git @@ -509,19 +497,27 @@ if(ESPRESSO_BUILD_WITH_HDF5) ) endif() endif() - # We need to define our own h5xx target, since the project version we depend - # on is not fully compatible with modern CMake. - FetchContent_GetProperties(h5xx) - if(NOT h5xx_POPULATED) - FetchContent_Populate(h5xx) - endif() - add_library(h5xx INTERFACE) add_library(hdf5 INTERFACE) target_link_libraries(hdf5 INTERFACE $) target_include_directories(hdf5 INTERFACE $) - target_include_directories(h5xx - INTERFACE $) + # We need to define our own h5xx target, since the project version we depend + # on is not fully compatible with modern CMake. + add_library(h5xx INTERFACE) + # cmake-format: off + ExternalProject_Add( + h5xx_library + GIT_REPOSITORY https://github.com/h5md/h5xx.git + GIT_TAG 0.9.1 + PREFIX lib_h5xx + # header-only library: disable configuration/build/install steps + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + ) + # cmake-format: on + ExternalProject_Get_Property(h5xx_library SOURCE_DIR) + target_include_directories(h5xx INTERFACE $) target_compile_features(h5xx INTERFACE cxx_std_11) target_compile_definitions(h5xx INTERFACE H5XX_USE_MPI) add_library(espresso_h5xx_cpp_flags INTERFACE) @@ -670,6 +666,11 @@ endif() # Boost # +if(POLICY CMP0167) + # use BoostConfig.cmake shipped with Boost 1.70+ instead of the one in CMake + cmake_policy(SET CMP0167 NEW) +endif() + list(APPEND BOOST_COMPONENTS mpi serialization filesystem system) if(ESPRESSO_BUILD_TESTS) diff --git a/cmake/FindCUDACompilerNVCC.cmake b/cmake/FindCUDACompilerNVCC.cmake index d9600ecf6d7..40213d2ad32 100644 --- a/cmake/FindCUDACompilerNVCC.cmake +++ b/cmake/FindCUDACompilerNVCC.cmake @@ -19,22 +19,9 @@ # along with this program. If not, see . # -# Verify the NVCC compiler matches the NVIDIA toolkit, # include the toolkit libraries and declare a custom # `add_library()` wrapper function named `espresso_add_gpu_library()`. -file(REAL_PATH "${CUDAToolkit_ROOT}/bin/nvcc" ESPRESO_CUDAToolkit_ROOT_RESOLVED) -file(REAL_PATH "${CMAKE_CUDA_COMPILER}" ESPRESO_CMAKE_CUDA_COMPILER_RESOLVED) -if(NOT "${ESPRESO_CUDAToolkit_ROOT_RESOLVED}" STREQUAL "${ESPRESO_CMAKE_CUDA_COMPILER_RESOLVED}" - AND NOT ESPRESSO_INSIDE_DOCKER) - cmake_path(GET CMAKE_CUDA_COMPILER PARENT_PATH ESPRESSO_NVCC_EXECUTABLE_DIRNAME) - cmake_path(GET ESPRESSO_NVCC_EXECUTABLE_DIRNAME PARENT_PATH ESPRESSO_NVCC_EXECUTABLE_DIRNAME) - message( - WARNING - "Your nvcc compiler (${CMAKE_CUDA_COMPILER}) does not appear to match your CUDA toolkit installation (${CUDAToolkit_ROOT}). While ESPResSo will still compile, you might get unexpected crashes. Try hinting it with '-D CUDAToolkit_ROOT=\"${ESPRESSO_NVCC_EXECUTABLE_DIRNAME}\"'." - ) -endif() - set(CUDA_LINK_LIBRARIES_KEYWORD PUBLIC) set(CUDA_PROPAGATE_HOST_FLAGS OFF) diff --git a/cmake/walberla.patch b/cmake/walberla.patch index d2c8d8e24fb..46b4ab08d17 100644 --- a/cmake/walberla.patch +++ b/cmake/walberla.patch @@ -9,3 +9,9 @@ https://i10git.cs.fau.de/walberla/walberla/-/merge_requests/709 @@ -700 +700 @@ - begin_ = new T[0]; + begin_ = nullptr; +support for CMake 4.0 +--- cmake/FindOpenMesh.cmake ++++ cmake/FindOpenMesh.cmake +@@ -56 +56 @@ +-cmake_minimum_required(VERSION 3.5.0) ++cmake_minimum_required(VERSION 3.10.0)