-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from maartenarnst/install
cmake: Add options. Revise directory tree.
- Loading branch information
Showing
10 changed files
with
229 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,85 @@ | ||
cmake_minimum_required(VERSION 3.12) | ||
cmake_minimum_required(VERSION 3.23) | ||
|
||
#---- Read the version file. | ||
file(READ version.json VERSION_JSON) | ||
|
||
#---- Get the version of kokkos-utils. | ||
string(JSON KOKKOS_UTILS_VERSION GET "${VERSION_JSON}" "kokkos-utils" "value") | ||
|
||
string(JSON DOXYGEN_VERSION GET "${VERSION_JSON}" dependencies doxygen value) | ||
string(JSON GOOGLETEST_VERSION GET "${VERSION_JSON}" dependencies googletest value) | ||
string(JSON KOKKOS_VERSION GET "${VERSION_JSON}" dependencies kokkos value) | ||
|
||
#---- Define the project. It uses C++ only. | ||
project( | ||
kokkos-utils | ||
VERSION ${KOKKOS_UTILS_VERSION} | ||
LANGUAGES CXX | ||
) | ||
|
||
#---- C++ standard that we need (at least). | ||
set(CMAKE_CXX_STANDARD 20 CACHE BOOL "" FORCE) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True CACHE BOOL "" FORCE) | ||
#---- Options. | ||
option(KokkosUtils_ENABLE_TESTS "Enable testing" ON) | ||
option(KokkosUtils_ENABLE_DOC "Enable documentation" ON) | ||
|
||
#---- Global property that helps us keep track of files that will automatically be added | ||
# to our Doxygen documentation. | ||
define_property(GLOBAL PROPERTY KokkosUtils_FILES_FOR_DOC | ||
BRIEF_DOCS "Files that will be added to the Doxygen documentation." | ||
) | ||
|
||
#---- Find Kokkos. | ||
find_package( | ||
Kokkos | ||
${KOKKOS_VERSION} | ||
REQUIRED | ||
# | ||
# Currently, we require the Kokkos::kokkoscore target. Other targets will be added as needed. | ||
string(JSON Kokkos_REQUIRED_VERSION GET "${VERSION_JSON}" dependencies kokkos value) | ||
|
||
if(NOT TARGET Kokkos::kokkoscore) | ||
find_package( | ||
Kokkos | ||
${Kokkos_REQUIRED_VERSION} | ||
CONFIG | ||
REQUIRED | ||
) | ||
else() | ||
if(DEFINED Kokkos_VERSION) | ||
if(NOT Kokkos_VERSION VERSION_GREATER_EQUAL Kokkos_REQUIRED_VERSION) | ||
message(FATAL_ERROR "Kokkos target(s) already set, but version not at least ${Kokkos_REQUIRED_VERSION}.") | ||
endif() | ||
else() | ||
message(WARNING "Kokkos target(s) already set, but could not check version.") | ||
endif() | ||
endif() | ||
|
||
#---- Build the Kokkos::utils library. | ||
add_library(KokkosUtils INTERFACE) | ||
add_library(Kokkos::utils ALIAS KokkosUtils) | ||
|
||
target_sources( | ||
KokkosUtils | ||
INTERFACE | ||
include/kokkos-utils/concepts/View.hpp | ||
) | ||
|
||
#---- Find Google Test. | ||
find_package( | ||
GTest | ||
${GOOGLETEST_VERSION} | ||
CONFIG | ||
REQUIRED | ||
target_include_directories( | ||
KokkosUtils | ||
INTERFACE | ||
"include/" | ||
) | ||
|
||
target_compile_features( | ||
KokkosUtils | ||
INTERFACE | ||
cxx_std_20 | ||
) | ||
|
||
target_compile_definitions( | ||
KokkosUtils | ||
INTERFACE | ||
KOKKOS_IMPL_PUBLIC_INCLUDE | ||
) | ||
|
||
#---- Testing. | ||
if(KokkosUtils_ENABLE_TESTS) | ||
enable_testing() | ||
add_subdirectory(tests) | ||
endif() | ||
|
||
#---- Documentation. | ||
add_subdirectory(docs) | ||
if(KokkosUtils_ENABLE_DOC) | ||
add_subdirectory(docs) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @defgroup automatedtests Automated test suite | ||
* @{ | ||
* @defgroup unittests Unit tests | ||
* @} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef KOKKOS_UTILS_CONCEPTS_VIEW_HPP | ||
#define KOKKOS_UTILS_CONCEPTS_VIEW_HPP | ||
|
||
#include "Kokkos_View.hpp" | ||
|
||
namespace Kokkos::utils::concepts | ||
{ | ||
|
||
//! Concept to specify that a type is a @c Kokkos::View. | ||
template <typename T> | ||
concept View = Kokkos::is_view_v<T>; | ||
|
||
} // namespace Kokkos::utils::concepts | ||
|
||
#endif // KOKKOS_UTILS_CONCEPTS_VIEW_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#--- Find GTest. | ||
string(JSON GTest_REQUIRED_VERSION GET "${VERSION_JSON}" dependencies googletest value) | ||
|
||
find_package( | ||
GTest | ||
${GTest_REQUIRED_VERSION} | ||
CONFIG | ||
REQUIRED | ||
) | ||
|
||
#--- Function to add a test. | ||
function(add_one_test) | ||
|
||
cmake_parse_arguments( | ||
aot_args | ||
"" | ||
"TEST_NAME" | ||
"" | ||
${ARGN} | ||
) | ||
|
||
# Set the test name, executable name and primary source file. | ||
set(TEST_NAME "test_${aot_args_TEST_NAME}") | ||
set(EXECUTABLE_NAME "test_${aot_args_TEST_NAME}") | ||
cmake_path(SET SOURCE_FILE "test_${aot_args_TEST_NAME}.cpp") | ||
cmake_path(ABSOLUTE_PATH SOURCE_FILE) | ||
|
||
# Add source file to the documentation list. | ||
set_property(GLOBAL APPEND PROPERTY KokkosUtils_FILES_FOR_DOC ${SOURCE_FILE}) | ||
|
||
# Create test executable. | ||
add_executable(${EXECUTABLE_NAME}) | ||
|
||
# Add the source file to the executable. | ||
target_sources( | ||
${EXECUTABLE_NAME} | ||
PRIVATE | ||
${SOURCE_FILE} | ||
) | ||
|
||
# Link the executable to the library, GTest and Kokkos. | ||
target_link_libraries( | ||
${EXECUTABLE_NAME} | ||
PRIVATE | ||
Kokkos::utils | ||
GTest::gtest_main | ||
Kokkos::kokkoscore | ||
) | ||
|
||
# Add the test to CTest. | ||
add_test( | ||
NAME ${EXECUTABLE_NAME} | ||
COMMAND $<TARGET_FILE:${EXECUTABLE_NAME}> | ||
) | ||
|
||
endfunction() | ||
|
||
### TESTS : concepts ### | ||
add_subdirectory(concepts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### TEST : View ### | ||
add_one_test( | ||
TEST_NAME View | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "gtest/gtest.h" | ||
|
||
#include "kokkos-utils/concepts/View.hpp" | ||
|
||
using execution_space = Kokkos::DefaultExecutionSpace; | ||
|
||
/** | ||
* @file | ||
* | ||
* @addtogroup unittests | ||
* | ||
* **Concepts related to @c Kokkos::View** | ||
* | ||
* This group of tests check the behavior of our concepts related to @c Kokkos::View. | ||
*/ | ||
|
||
namespace Kokkos::utils::tests::concepts | ||
{ | ||
|
||
//! @test Check that @ref Kokkos::utils::concepts::View works as expected. | ||
TEST(concepts, View) | ||
{ | ||
using view_1d_t = Kokkos::View<int[5] , execution_space>; | ||
using view_2d_t = Kokkos::View<int[5][5], execution_space>; | ||
|
||
static_assert(Kokkos::utils::concepts::View<view_1d_t>); | ||
static_assert(Kokkos::utils::concepts::View<view_2d_t>); | ||
} | ||
|
||
} // namespace Kokkos::utils::tests::concepts |