Skip to content

Commit

Permalink
#354: Bump minimum CMake version to 3.23 and update find_package_loca…
Browse files Browse the repository at this point in the history
…l to work with packageName_ROOT
  • Loading branch information
JacobDomagala committed Jun 24, 2024
1 parent 33a4dce commit 44a10b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 59 deletions.
11 changes: 3 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
71 changes: 20 additions & 51 deletions cmake/load_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 44a10b9

Please sign in to comment.