Skip to content

Commit

Permalink
Merge pull request #355 from DARMA-tasking/354-bump-cmake_minimum_req…
Browse files Browse the repository at this point in the history
…uired-to-323-to-match-vt

#354: Bump minimum CMake version to 3.23 and update `find_package_local` to work with `packageName_ROOT`
  • Loading branch information
lifflander authored Jul 3, 2024
2 parents 33a4dce + bc9a21b commit 78f27b4
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 101 deletions.
23 changes: 9 additions & 14 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 @@ -109,14 +109,12 @@ option(kokkos_kernels_DISABLE "Disable Kokkos Kernels" OFF)

if (NOT kokkos_DISABLE)
# optional packages
optional_pkg_directory(kokkos "Kokkos" 1)

if (${kokkos_DIR_FOUND})
find_package_local(
kokkos "${kokkos_DIR}/" Kokkos "CMake/Kokkos/" "cmake/Kokkos/"
)
# Used to properly setup transitive dependency in checkpointConfig.cmake.in
set(CHECKPOINT_HAS_KOKKOS_LIBRARY 1)
optional_pkg_directory(Kokkos "Kokkos" 1)

if (${Kokkos_DIR_FOUND})
find_package_local(Kokkos)
# Used to properly setup transitive dependency in checkpointConfig.cmake.in
set(CHECKPOINT_HAS_KOKKOS_LIBRARY 1)
else()
set(CHECKPOINT_HAS_KOKKOS_LIBRARY 0)
endif()
Expand All @@ -126,11 +124,8 @@ if (NOT kokkos_kernels_DISABLE)
# optional packages
optional_pkg_directory(KokkosKernels "Kokkos kernels" 1)

if (KokkosKernels_DIR_FOUND)
find_package_local(
KokkosKernels "${KokkosKernels_DIR}/" KokkosKernels
"CMake/KokkosKernels/" "cmake/KokkosKernels/"
)
if (${KokkosKernels_DIR_FOUND})
find_package_local(KokkosKernels)
# Used to properly setup transitive dependency in checkpointConfig.cmake.in
set(CHECKPOINT_HAS_KOKKOS_KERNELS_LIBRARY 1)
else()
Expand Down
4 changes: 2 additions & 2 deletions ci/build_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ cmake -G "${CMAKE_GENERATOR:-Ninja}" \
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH:-}" \
-DCMAKE_INSTALL_PREFIX="$CHECKPOINT_BUILD/install" \
-DGTEST_ROOT="${GTEST_ROOT}" \
-Dkokkos_DIR="${KOKKOS_ROOT}" \
-DKokkosKernels_DIR="${KOKKOS_KERNELS_ROOT}" \
-DKokkos_ROOT="${KOKKOS_ROOT}" \
-DKokkosKernels_ROOT="${KOKKOS_KERNELS_ROOT}" \
"$CHECKPOINT"

if test "${CHECKPOINT_DOXYGEN_ENABLED:-0}" -eq 1
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/kokkos-kernels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mkdir build
cd build

cmake -G "${CMAKE_GENERATOR:-Ninja}" \
-DCMAKE_PREFIX_PATH="${KOKKOS_ROOT}/cmake" \
-DCMAKE_PREFIX_PATH="${KOKKOS_ROOT}/lib/cmake" \
-DCMAKE_INSTALL_PREFIX="$kokkos_build/install" \
"$kokkos"
cmake --build . --target install
6 changes: 2 additions & 4 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 All @@ -55,11 +53,11 @@ ENV GTEST_ROOT=/pkgs/gtest/install

COPY ./ci/deps/kokkos.sh kokkos.sh
RUN ./kokkos.sh 4.1.00 /pkgs 0
ENV KOKKOS_ROOT=/pkgs/kokkos/install/lib
ENV KOKKOS_ROOT=/pkgs/kokkos/install

COPY ./ci/deps/kokkos-kernels.sh kokkos-kernels.sh
RUN ./kokkos-kernels.sh 4.1.00 /pkgs
ENV KOKKOS_KERNELS_ROOT=/pkgs/kokkos-kernels/install/lib
ENV KOKKOS_KERNELS_ROOT=/pkgs/kokkos-kernels/install

ENV MPI_EXTRA_FLAGS="" \
CMAKE_PREFIX_PATH="/lib/x86_64-linux-gnu/" \
Expand Down
6 changes: 2 additions & 4 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 All @@ -59,11 +57,11 @@ ENV GTEST_ROOT=/pkgs/gtest/install

COPY ./ci/deps/kokkos.sh kokkos.sh
RUN ./kokkos.sh 4.1.00 /pkgs 1
ENV KOKKOS_ROOT=/pkgs/kokkos/install/lib
ENV KOKKOS_ROOT=/pkgs/kokkos/install

COPY ./ci/deps/kokkos-kernels.sh kokkos-kernels.sh
RUN ./kokkos-kernels.sh 4.1.00 /pkgs
ENV KOKKOS_KERNELS_ROOT=/pkgs/kokkos-kernels/install/lib
ENV KOKKOS_KERNELS_ROOT=/pkgs/kokkos-kernels/install

ENV MPI_EXTRA_FLAGS="" \
PATH=/usr/lib/ccache/:$PATH
Expand Down
8 changes: 5 additions & 3 deletions 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 All @@ -53,11 +55,11 @@ ENV CC=/opt/intel/install/bin/icc \

COPY ./ci/deps/kokkos.sh kokkos.sh
RUN ./kokkos.sh 4.1.00 /pkgs 1
ENV KOKKOS_ROOT=/pkgs/kokkos/install/lib
ENV KOKKOS_ROOT=/pkgs/kokkos/install

COPY ./ci/deps/kokkos-kernels.sh kokkos-kernels.sh
RUN ./kokkos-kernels.sh 4.1.00 /pkgs
ENV KOKKOS_KERNELS_ROOT=/pkgs/kokkos-kernels/install/lib
ENV KOKKOS_KERNELS_ROOT=/pkgs/kokkos-kernels/install

ENV MPI_EXTRA_FLAGS="" \
PATH=/usr/lib/ccache/:$PATH \
Expand Down
6 changes: 3 additions & 3 deletions 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 All @@ -47,11 +47,11 @@ ENV GTEST_ROOT=/pkgs/gtest/install

COPY ./ci/deps/kokkos.sh kokkos.sh
RUN ./kokkos.sh 4.1.00 /pkgs 1
ENV KOKKOS_ROOT=/pkgs/kokkos/install/lib
ENV KOKKOS_ROOT=/pkgs/kokkos/install

COPY ./ci/deps/kokkos-kernels.sh kokkos-kernels.sh
RUN ./kokkos-kernels.sh 4.1.00 /pkgs
ENV KOKKOS_KERNELS_ROOT=/pkgs/kokkos-kernels/install/lib
ENV KOKKOS_KERNELS_ROOT=/pkgs/kokkos-kernels/install

ENV MPI_EXTRA_FLAGS="" \
CMAKE_PREFIX_PATH="/lib/x86_64-linux-gnu/" \
Expand Down
6 changes: 3 additions & 3 deletions 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 All @@ -48,7 +48,7 @@ ENV GTEST_ROOT=/pkgs/gtest/install

COPY ./ci/deps/kokkos.sh kokkos.sh
RUN ./kokkos.sh 4.1.00 /pkgs 0
ENV KOKKOS_ROOT=/pkgs/kokkos/install/lib
ENV KOKKOS_ROOT=/pkgs/kokkos/install

RUN mkdir -p /nvcc_wrapper/build && \
wget https://raw.githubusercontent.com/kokkos/kokkos/master/bin/nvcc_wrapper -P /nvcc_wrapper/build && \
Expand All @@ -60,7 +60,7 @@ ENV MPI_EXTRA_FLAGS="" \

COPY ./ci/deps/kokkos-kernels.sh kokkos-kernels.sh
RUN ./kokkos-kernels.sh 4.1.00 /pkgs
ENV KOKKOS_KERNELS_ROOT=/pkgs/kokkos-kernels/install/lib
ENV KOKKOS_KERNELS_ROOT=/pkgs/kokkos-kernels/install

FROM base as build
COPY . /checkpoint
Expand Down
4 changes: 2 additions & 2 deletions ci/docker/ubuntu-22.04-clang-cpp.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ ENV GTEST_ROOT=/pkgs/gtest/install

COPY ./ci/deps/kokkos.sh kokkos.sh
RUN ./kokkos.sh 4.1.00 /pkgs 0
ENV KOKKOS_ROOT=/pkgs/kokkos/install/lib
ENV KOKKOS_ROOT=/pkgs/kokkos/install

COPY ./ci/deps/kokkos-kernels.sh kokkos-kernels.sh
RUN ./kokkos-kernels.sh 4.1.00 /pkgs
ENV KOKKOS_KERNELS_ROOT=/pkgs/kokkos-kernels/install/lib
ENV KOKKOS_KERNELS_ROOT=/pkgs/kokkos-kernels/install

ENV MPI_EXTRA_FLAGS="" \
CMAKE_PREFIX_PATH="/lib/x86_64-linux-gnu/" \
Expand Down
5 changes: 3 additions & 2 deletions cmake/checkpointConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include(${SELF_DIR}/checkpointTargets.cmake)
include(CMakeFindDependencyMacro)

if (@CHECKPOINT_HAS_KOKKOS_LIBRARY@)
set (kokkos_DIR @kokkos_DIR@)
find_dependency(kokkos REQUIRED HINTS @kokkos_DIR@ NAMES Kokkos)
set (Kokkos_DIR @Kokkos_DIR@)
set (Kokkos_ROOT @Kokkos_ROOT@)
find_dependency(kokkos REQUIRED HINTS @Kokkos_DIR@ @Kokkos_ROOT@ NAMES Kokkos)
endif()
83 changes: 23 additions & 60 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)
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
# Skip this logic when this macro was not invoked from the
Expand All @@ -32,64 +32,28 @@ 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_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)

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()

message(
FATAL_ERROR "find_package_local: can not find package: ${pkg_name}"
" tried to find_package(..) with above search paths"
)
endif()
find_package(
${pkg_name}
NAMES ${pkg_name}
NO_CMAKE_PACKAGE_REGISTRY
NO_CMAKE_BUILDS_PATH
NO_CMAKE_SYSTEM_PATH
NO_CMAKE_SYSTEM_PACKAGE_REGISTRY
NO_SYSTEM_ENVIRONMENT_PATH
QUIET
REQUIRED
)
endif()
endmacro(find_package_local)

Expand All @@ -108,12 +72,11 @@ macro(optional_pkg_directory pkg_name pkg_user_name assume_found_if_hasparent)
endif()
else()
#message(STATUS "optional_pkg_directory: name=${pkg_name}")
option(${pkg_name}_DIR "Root folder for ${pkg_user_name} installation" OFF)
if (NOT ${pkg_name}_DIR)
if (NOT ${pkg_name}_DIR AND NOT ${pkg_name}_ROOT)
message(
STATUS
"Path for ${pkg_user_name} library (optional) not specified "
"with -D${pkg_name}_DIR="
"with -D${pkg_name}_DIR= or -D${pkg_name}_ROOT="
)
message(
STATUS
Expand All @@ -124,7 +87,7 @@ macro(optional_pkg_directory pkg_name pkg_user_name assume_found_if_hasparent)
message(
STATUS
"Path for ${pkg_user_name} library (optional) specified "
"with -D${pkg_name}_DIR=${${pkg_name}_DIR}"
"with -D${pkg_name}_DIR=${${pkg_name}_DIR} -D${pkg_name}_ROOT=${${pkg_name}_ROOT}"
)
set(${pkg_name}_DIR_FOUND 1)
endif()
Expand Down
2 changes: 1 addition & 1 deletion docs/md/checkpoint_learn_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build configuration:
| CMake Variable | Default Value | Description |
| ---------------------------------------------------- | ------------- | --------------------------------------------- |
| `gtest_DIR` | | Install directory for googletest |
| `kokkos_DIR` | | Install directory for kokkos |
| `Kokkos_DIR` | | Install directory for kokkos |
| `KokkosKernels_DIR` | | Install directory for kokkoskernels |
| `checkpoint_tests_enabled` | 0 | Build *checkpoint* tests |
| `checkpoint_mpi_enabled` | 0 | Build *checkpoint* with MPI for tests |
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ target_compile_features(${CHECKPOINT_LIBRARY} PUBLIC cxx_std_17)

include(CMakePrintHelpers)

if (${kokkos_DIR_FOUND})
if (KokkosKernels_DIR_FOUND)
if (${Kokkos_DIR_FOUND})
if (${KokkosKernels_DIR_FOUND})
message(STATUS "Checkpoint: Kokkos kernels enabled")
set(KERNELS 1)
# Kokkos Kernels historically installed its EXPORT targets in the Kokkos:: namespace, and several
Expand Down

0 comments on commit 78f27b4

Please sign in to comment.