Skip to content

Commit 8e177a9

Browse files
authored
Merge pull request #122 from dssgabriel/cmake
Modernizing CMake and packaging
2 parents be3f6c6 + 27fc42d commit 8e177a9

File tree

10 files changed

+365
-233
lines changed

10 files changed

+365
-233
lines changed

CMakeLists.txt

Lines changed: 66 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,96 @@
1+
#@HEADER
2+
# ************************************************************************
3+
#
4+
# Kokkos v. 4.0
5+
# Copyright (2022) National Technology & Engineering
6+
# Solutions of Sandia, LLC (NTESS).
7+
#
8+
# Under the terms of Contract DE-NA0003525 with NTESS,
9+
# the U.S. Government retains certain rights in this software.
10+
#
11+
# Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12+
# See https://kokkos.org/LICENSE for license information.
13+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14+
#
15+
#@HEADER
16+
117
# 3.9: MPI::MPI_CXX
218
# 3.12: CMAKE_PROJECT_VERSION_MAJOR
319
# 3.15: PUBLIC_HEADER files for interface libraries
4-
cmake_minimum_required(VERSION 3.12)
5-
project(KokkosComm VERSION 0.0.2)
20+
# 3.23: FILE_SETs for easy export of header-only libraries
21+
cmake_minimum_required(VERSION 3.23)
22+
23+
project(
24+
KokkosComm
25+
LANGUAGES
26+
CXX
27+
VERSION 0.2.0
28+
DESCRIPTION "Experimental MPI interfaces (and more!) for the Kokkos C++ Performance Portability Programming ecosystem"
29+
HOMEPAGE_URL "https://kokkos.org/kokkos-comm/"
30+
)
631

732
option(KokkosComm_ENABLE_PERFTESTS "Build KokkosComm perf tests" OFF)
8-
option(KokkosComm_ENABLE_TESTS "Build KokkosComm perf tests" OFF)
33+
option(KokkosComm_ENABLE_TESTS "Build KokkosComm tests" OFF)
934
option(KokkosComm_ENABLE_MPI "Build KokkosComm with MPI transport" ON)
1035

11-
12-
## resolve options
36+
# Resolve options
1337
set(KOKKOSCOMM_ENABLE_PERFTESTS ${KokkosComm_ENABLE_PERFTESTS} CACHE BOOL "" FORCE)
1438
set(KOKKOSCOMM_ENABLE_TESTS ${KokkosComm_ENABLE_TESTS} CACHE BOOL "" FORCE)
1539
set(KOKKOSCOMM_ENABLE_MPI ${KokkosComm_ENABLE_MPI} CACHE BOOL "" FORCE)
1640

1741
find_package(Kokkos REQUIRED)
18-
find_package(MPI REQUIRED)
19-
20-
message(STATUS "Kokkos Comm: MPI_VERSION = ${MPI_VERSION}")
21-
message(STATUS "Kokkos Comm: MPI_CXX_COMPILER = ${MPI_CXX_COMPILER}")
22-
message(STATUS "Kokkos Comm: MPI_CXX_COMPILE_OPTIONS = ${MPI_CXX_COMPILE_OPTIONS}")
23-
message(STATUS "Kokkos Comm: MPI_CXX_COMPILE_DEFINITIONS = ${MPI_CXX_COMPILE_DEFINITIONS}")
24-
message(STATUS "Kokkos Comm: MPI_CXX_INCLUDE_DIRS = ${MPI_CXX_INCLUDE_DIRS}")
25-
message(STATUS "Kokkos Comm: MPI_CXX_LINK_FLAGS = ${MPI_CXX_LINK_FLAGS}")
26-
message(STATUS "Kokkos Comm: MPI_CXX_LIBRARIES = ${MPI_CXX_LIBRARIES}")
27-
42+
if(KOKKOSCOMM_ENABLE_MPI)
43+
find_package(MPI REQUIRED)
44+
endif()
2845

29-
include(cmake/flags.cmake)
3046
add_subdirectory(src)
31-
kokkoscomm_add_cxx_flags(TARGET KokkosComm INTERFACE)
47+
if(KOKKOSCOMM_ENABLE_TESTS)
48+
add_subdirectory(unit_tests)
49+
endif()
50+
if(KOKKOSCOMM_ENABLE_PERFTESTS)
51+
add_subdirectory(perf_tests)
52+
endif()
3253

33-
## Version config file
54+
# -- PACKAGING -- #
55+
include(CMakePackageConfigHelpers)
56+
include(GNUInstallDirs)
57+
58+
# Generate version config header
3459
set(KOKKOSCOMM_VERSION_MAJOR ${CMAKE_PROJECT_VERSION_MAJOR} CACHE STRING "" FORCE)
3560
set(KOKKOSCOMM_VERSION_MINOR ${CMAKE_PROJECT_VERSION_MINOR} CACHE STRING "" FORCE)
3661
set(KOKKOSCOMM_VERSION_PATCH ${CMAKE_PROJECT_VERSION_PATCH} CACHE STRING "" FORCE)
3762
configure_file(
38-
${CMAKE_CURRENT_LIST_DIR}/cmake/KokkosComm_config.hpp.in
39-
${CMAKE_CURRENT_BINARY_DIR}/src/KokkosComm_config.hpp
40-
@ONLY
63+
${PROJECT_SOURCE_DIR}/cmake/KokkosComm_config.hpp.in
64+
${PROJECT_BINARY_DIR}/src/KokkosComm/config.hpp
65+
@ONLY
4166
)
4267

43-
# this sets CMAKE_INSTALL_[...]DIR
44-
include(GNUInstallDirs)
45-
46-
target_include_directories(KokkosComm INTERFACE
47-
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/>
48-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
68+
# Generate package config file
69+
configure_package_config_file(
70+
${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in
71+
${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommConfig.cmake
72+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/KokkosComm
73+
NO_SET_AND_CHECK_MACRO
74+
NO_CHECK_REQUIRED_COMPONENTS_MACRO
4975
)
5076

51-
## Package config file
52-
include(CMakePackageConfigHelpers)
53-
configure_package_config_file (
54-
${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in
55-
${PROJECT_BINARY_DIR}/cmake/KokkosComm/${PROJECT_NAME}Config.cmake
56-
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
57-
NO_SET_AND_CHECK_MACRO
58-
NO_CHECK_REQUIRED_COMPONENTS_MACRO
59-
)
77+
# Generate package version file
6078
write_basic_package_version_file(
61-
${PROJECT_BINARY_DIR}/cmake/KokkosComm/${PROJECT_NAME}Version.cmake
62-
COMPATIBILITY SameMajorVersion
63-
)
64-
65-
export (
66-
TARGETS KokkosComm
67-
NAMESPACE "${PROJECT_NAME}::"
68-
FILE ${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommTargets.cmake
79+
${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommVersion.cmake
80+
COMPATIBILITY SameMajorVersion
81+
ARCH_INDEPENDENT # KokkosComm is a header-only library
6982
)
7083

71-
72-
install(
73-
TARGETS KokkosComm
74-
EXPORT KokkosCommTargets # does this do anything?
75-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
76-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
77-
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
78-
# install the include tree
79-
install(
80-
DIRECTORY "src/"
81-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
82-
FILES_MATCHING PATTERN "*.hpp")
83-
# install the configured files
84+
# Install CMake package files
8485
install(
85-
DIRECTORY "${PROJECT_BINARY_DIR}/src/"
86-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
87-
FILES_MATCHING PATTERN "*.hpp")
88-
install(
89-
FILES
90-
"${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommConfig.cmake"
91-
"${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommVersion.cmake"
92-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/KokkosComm/
86+
FILES
87+
${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommConfig.cmake
88+
${PROJECT_BINARY_DIR}/cmake/KokkosComm/KokkosCommVersion.cmake
89+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/KokkosComm
9390
)
9491
install(
95-
EXPORT KokkosCommTargets
96-
NAMESPACE "${PROJECT_NAME}::"
97-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
92+
EXPORT KokkosCommTargets
93+
FILE KokkosCommTargets.cmake
94+
NAMESPACE KokkosComm::
95+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/KokkosComm
9896
)
99-
100-
101-
if(KOKKOSCOMM_ENABLE_TESTS)
102-
enable_testing()
103-
add_subdirectory(unit_tests)
104-
endif()
105-
if(KOKKOSCOMM_ENABLE_PERFTESTS)
106-
enable_testing()
107-
add_subdirectory(perf_tests)
108-
endif()

cmake/Config.cmake.in

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1+
#@HEADER
2+
# ************************************************************************
3+
#
4+
# Kokkos v. 4.0
5+
# Copyright (2022) National Technology & Engineering
6+
# Solutions of Sandia, LLC (NTESS).
7+
#
8+
# Under the terms of Contract DE-NA0003525 with NTESS,
9+
# the U.S. Government retains certain rights in this software.
10+
#
11+
# Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12+
# See https://kokkos.org/LICENSE for license information.
13+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14+
#
15+
#@HEADER
16+
117
@PACKAGE_INIT@
218

319
GET_FILENAME_COMPONENT(KokkosComm_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
4-
INCLUDE("${KokkosComm_CMAKE_DIR}/KokkosCommTargets.cmake")
5-
UNSET(KokkosComm_CMAKE_DIR)
620

721
include(CMakeFindDependencyMacro)
822
find_dependency(MPI)
923
find_dependency(Kokkos)
1024

11-
set(KOKKOSCOMM_ENABLE_MPI @KOKKOSCOMM_ENABLE_MPI@)
12-
13-
## FIXME: do we need this?
14-
set(KokkosComm_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@" )
15-
set(KokkosComm_DATA_DIR "@CMAKE_INSTALL_PREFIX@/@RELATIVE_DATA_INSTALL_DIR@" )
16-
set(KokkosComm_ICONS_DIR "@CMAKE_INSTALL_PREFIX@/share/icons" )
17-
set(KokkosComm_CONFIG_DIR "${installedPrefix}/@CONFIG_INSTALL_DIR@" )
25+
INCLUDE("${KokkosComm_CMAKE_DIR}/KokkosCommTargets.cmake")
26+
UNSET(KokkosComm_CMAKE_DIR)

cmake/flags.cmake

Lines changed: 0 additions & 66 deletions
This file was deleted.

perf_tests/CMakeLists.txt

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,54 @@
1-
cmake_minimum_required(VERSION 3.12) # same as Kokkos Comm
2-
project(KokkosCommPerfTests VERSION 0.0.2)
1+
#@HEADER
2+
# ************************************************************************
3+
#
4+
# Kokkos v. 4.0
5+
# Copyright (2022) National Technology & Engineering
6+
# Solutions of Sandia, LLC (NTESS).
7+
#
8+
# Under the terms of Contract DE-NA0003525 with NTESS,
9+
# the U.S. Government retains certain rights in this software.
10+
#
11+
# Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12+
# See https://kokkos.org/LICENSE for license information.
13+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14+
#
15+
#@HEADER
16+
17+
cmake_minimum_required(VERSION 3.23) # same as KokkosComm
18+
19+
project(
20+
KokkosCommPerfTests
21+
VERSION 0.2.0
22+
LANGUAGES
23+
CXX
24+
DESCRIPTION "Performance tests for the KokkosComm experimental communication interfaces"
25+
)
326

427
enable_testing()
528

629
# Treat the perf tests as a separate project
7-
# If not included in the Kokkos Comm build,
8-
# find Kokkos Comm to do a standalone build
9-
if (NOT TARGET KokkosComm::KokkosComm)
30+
# If not included in the Kokkos Comm build, find Kokkos Comm to do a standalone build
31+
if(NOT TARGET KokkosComm::KokkosComm)
1032
find_package(KokkosComm REQUIRED)
1133
endif()
1234

1335
include(FetchContent)
1436

1537
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
16-
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
17-
cmake_policy(SET CMP0135 NEW)
38+
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
39+
cmake_policy(SET CMP0135 NEW)
1840
endif()
1941

2042
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
21-
FetchContent_Declare(
22-
benchmark
23-
URL https://github.com/google/benchmark/archive/refs/tags/v1.8.3.zip
24-
)
25-
# FetchContent_MakeAvailable(benchmark)
26-
# was making install install benchmark as well
43+
FetchContent_Declare(benchmark URL https://github.com/google/benchmark/archive/refs/tags/v1.8.3.zip)
44+
# FetchContent_MakeAvailable(benchmark) was making install benchmark as well
2745
# EXCLUDE_FROM_ALL here seems to be the magic
28-
if (NOT benchmark_POPULATED)
46+
if(NOT benchmark_POPULATED)
2947
FetchContent_Populate(benchmark)
3048
add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR} EXCLUDE_FROM_ALL)
3149
endif()
3250
unset(BENCHMARK_ENABLE_TESTING)
3351

34-
if (KOKKOSCOMM_ENABLE_MPI)
52+
if(KOKKOSCOMM_ENABLE_MPI)
3553
add_subdirectory(mpi)
3654
endif(KOKKOSCOMM_ENABLE_MPI)

perf_tests/mpi/CMakeLists.txt

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
1-
add_executable(perf_test-main test_main.cpp
1+
#@HEADER
2+
# ************************************************************************
3+
#
4+
# Kokkos v. 4.0
5+
# Copyright (2022) National Technology & Engineering
6+
# Solutions of Sandia, LLC (NTESS).
7+
#
8+
# Under the terms of Contract DE-NA0003525 with NTESS,
9+
# the U.S. Government retains certain rights in this software.
10+
#
11+
# Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12+
# See https://kokkos.org/LICENSE for license information.
13+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14+
#
15+
#@HEADER
16+
17+
add_executable(perf-test-main)
18+
target_sources(
19+
perf-test-main
20+
PRIVATE
21+
test_main.cpp
222
test_sendrecv.cpp
323
test_2dhalo.cpp
424
test_osu_latency.cpp
5-
)
6-
if(KOKKOSCOMM_ENABLE_TESTS)
7-
kokkoscomm_add_cxx_flags(TARGET perf_test-main)
8-
endif()
9-
target_link_libraries(perf_test-main KokkosComm::KokkosComm benchmark::benchmark)
10-
add_test(NAME perf_test-main
11-
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ./perf_test-main)
25+
)
26+
target_link_libraries(
27+
perf-test-main
28+
KokkosComm::KokkosComm
29+
benchmark::benchmark
30+
)
31+
add_test(
32+
NAME perf-test-main
33+
COMMAND
34+
${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ./perf-test-main
35+
)

0 commit comments

Comments
 (0)