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

#354: Bump minimum CMake version to 3.23 and update find_package_local to work with packageName_ROOT #355

Merged
Merged
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
2 changes: 0 additions & 2 deletions ci/docker/ubuntu-18.04-clang-cpp.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ RUN ln -s \
ENV CC=${compiler} \
CXX=clang++

ARG arch

COPY ./ci/deps/cmake.sh cmake.sh
RUN ./cmake.sh 3.23.4 ${arch}

Expand Down
2 changes: 0 additions & 2 deletions ci/docker/ubuntu-18.04-gnu-cpp.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ RUN ln -s \
ENV CC=gcc \
CXX=g++

ARG arch

COPY ./ci/deps/cmake.sh cmake.sh
RUN ./cmake.sh 3.23.4 ${arch}

Expand Down
4 changes: 3 additions & 1 deletion ci/docker/ubuntu-18.04-intel-cpp.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ RUN ln -s \
/opt/intel/install/bin/icc \
/opt/intel/install/bin/gcc

ARG arch

COPY ./ci/deps/cmake.sh cmake.sh
RUN ./cmake.sh 3.18.4
RUN ./cmake.sh 3.23.4 ${arch}
ENV PATH=/cmake/bin/:$PATH

COPY ./ci/deps/gtest.sh gtest.sh
Expand Down
2 changes: 1 addition & 1 deletion ci/docker/ubuntu-20.04-gnu-docs.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RUN apt-get update -y -q && \
rm -rf /var/lib/apt/lists/*

COPY ./ci/deps/cmake.sh cmake.sh
RUN ./cmake.sh 3.18.4
RUN ./cmake.sh 3.23.4 ${arch}

ENV PATH=/cmake/bin/:$PATH
ENV LESSCHARSET=utf-8
Expand Down
2 changes: 1 addition & 1 deletion ci/docker/ubuntu-20.04-nvidia-cpp.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ENV CC=gcc \
CXX=g++

COPY ./ci/deps/cmake.sh cmake.sh
RUN ./cmake.sh 3.18.4
RUN ./cmake.sh 3.23.4 ${arch}

COPY ./ci/deps/mpich.sh mpich.sh
RUN ./mpich.sh 3.3.2 -j4
Expand Down
76 changes: 25 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)
JacobDomagala marked this conversation as resolved.
Show resolved Hide resolved
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
# Skip this logic when this macro was not invoked from the
Expand All @@ -32,63 +32,37 @@ 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}"
"${${pkg_name}_DIR}/cmake/${pkg_name}/"
"${${pkg_name}_DIR}/cmake/${pkg_other_name}/"
"${${pkg_name}_DIR}/CMake/${pkg_name}/"
"${${pkg_name}_DIR}/CMake/${pkg_other_name}/"
)
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)
cz4rs marked this conversation as resolved.
Show resolved Hide resolved

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
Loading