From 44a10b9fed74a17fa593515f45226ec33c91cae6 Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Sun, 23 Jun 2024 23:14:36 +0200 Subject: [PATCH] #354: Bump minimum CMake version to 3.23 and update find_package_local to work with packageName_ROOT --- CMakeLists.txt | 11 ++----- cmake/load_package.cmake | 71 +++++++++++----------------------------- 2 files changed, 23 insertions(+), 59 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c74c262..bc756454 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.17) +cmake_minimum_required(VERSION 3.23) project(checkpoint VERSION 1.4.0) include(cmake/turn_on_warnings.cmake) @@ -112,9 +112,7 @@ if (NOT kokkos_DISABLE) optional_pkg_directory(kokkos "Kokkos" 1) if (${kokkos_DIR_FOUND}) - find_package_local( - kokkos "${kokkos_DIR}/" Kokkos "CMake/Kokkos/" "cmake/Kokkos/" - ) + find_package_local(kokkos Kokkos) # Used to properly setup transitive dependency in checkpointConfig.cmake.in set(CHECKPOINT_HAS_KOKKOS_LIBRARY 1) else() @@ -127,10 +125,7 @@ if (NOT kokkos_kernels_DISABLE) optional_pkg_directory(KokkosKernels "Kokkos kernels" 1) if (KokkosKernels_DIR_FOUND) - find_package_local( - KokkosKernels "${KokkosKernels_DIR}/" KokkosKernels - "CMake/KokkosKernels/" "cmake/KokkosKernels/" - ) + find_package_local(KokkosKernels KokkosKernels) # Used to properly setup transitive dependency in checkpointConfig.cmake.in set(CHECKPOINT_HAS_KOKKOS_KERNELS_LIBRARY 1) else() diff --git a/cmake/load_package.cmake b/cmake/load_package.cmake index 693b6fb4..b4fee42c 100644 --- a/cmake/load_package.cmake +++ b/cmake/load_package.cmake @@ -21,7 +21,7 @@ macro(require_pkg_directory pkg_name pkg_user_name) endif() endmacro(require_pkg_directory) -macro(find_package_local pkg_name pkg_directory pkg_other_name) +macro(find_package_local pkg_name pkg_other_name) get_directory_property(hasParent PARENT_DIRECTORY) if(hasParent) # Skip this logic when this macro was not invoked from the @@ -32,63 +32,32 @@ macro(find_package_local pkg_name pkg_directory pkg_other_name) #message(STATUS "skipping find_package for ${pkg_name}") else() + if(DEFINED ${pkg_name}_DIR AND NOT DEFINED ${pkg_name}_ROOT) + set(${pkg_name}_ROOT ${${pkg_name}_DIR}) + endif() + message( - STATUS "find_package_local: pkg name=\"${pkg_name}\", " - "directory=\"${pkg_directory}\"" + STATUS "find_package_local: pkg name=\"${pkg_name}\", ${pkg_name}_ROOT=\"${${pkg_name}_ROOT}\"" ) - # Rest of the arguments are potential relative search paths wrt the - # ${pkg_directory} - set(prefix_args ${ARGN}) - - # Default search paths: root, /cmake and /CMake subdirectories - list(APPEND prefix_args "/" "/cmake" "/CMake") - # Whether we loaded the package in the following loop with find_package() set(${pkg_name}_PACKAGE_LOADED 0) - foreach(prefix ${prefix_args}) - set(potential_path ${pkg_directory}/${prefix}) - # message("prefix: ${potential_path}") - if (EXISTS "${potential_path}") - # message(STATUS "find_package_local: trying path: ${potential_path}") - - # Search locally only for package based on the user's supplied path; if - # this fails try to next one. Even if the directory exists (tested above) - # this might fail if a directory does not have the config file - find_package( - ${pkg_name} - PATHS ${potential_path} - NAMES ${pkg_name} ${pkg_other_name} - NO_CMAKE_PACKAGE_REGISTRY - NO_CMAKE_BUILDS_PATH - NO_CMAKE_SYSTEM_PATH - NO_CMAKE_SYSTEM_PACKAGE_REGISTRY - NO_SYSTEM_ENVIRONMENT_PATH - QUIET - ) - - # Break out of the search loop now that we have found the path - if (${${pkg_name}_FOUND}) - message(STATUS "find_package_local: found with prefix: ${prefix}: ${${pkg_name}_DIR}") - set(${pkg_name}_PACKAGE_LOADED 1) - break() - endif() - endif() - endforeach() - - if (NOT ${${pkg_name}_PACKAGE_LOADED}) - message(STATUS "find_package_local: can not find package: ${pkg_name}") - - foreach(prefix ${prefix_args}) - set(path ${${pkg_name}_DIR}/${prefix}) - message(STATUS "find_package_local: searched: ${path}") - endforeach() + # Search locally only for package based on the user's supplied path; + find_package( + ${pkg_name} + NAMES ${pkg_name} ${pkg_other_name} + NO_CMAKE_PACKAGE_REGISTRY + NO_CMAKE_BUILDS_PATH + NO_CMAKE_SYSTEM_PATH + NO_CMAKE_SYSTEM_PACKAGE_REGISTRY + NO_SYSTEM_ENVIRONMENT_PATH + QUIET + REQUIRED + ) - message( - FATAL_ERROR "find_package_local: can not find package: ${pkg_name}" - " tried to find_package(..) with above search paths" - ) + if(${pkg_name}_FOUND) + set(${pkg_name}_PACKAGE_LOADED 1) endif() endif() endmacro(find_package_local)