Skip to content

Commit

Permalink
Merge pull request #6 from maartenarnst/install
Browse files Browse the repository at this point in the history
cmake: Add options. Revise directory tree.
  • Loading branch information
romintomasetti authored Jun 17, 2024
2 parents 99ee7cf + f610cf9 commit 365df5b
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 22 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.ref == 'refs/heads/develop' }}
file: dockerfile
file: docker/dockerfile
tags: ${{ needs.set-vars.outputs.CI_IMAGE }}
cache-from: type=registry,ref=${{ needs.set-vars.outputs.CI_IMAGE }}
cache-to: type=inline
Expand All @@ -88,6 +88,10 @@ jobs:
cmake -S . --preset=OpenMP
cmake --build --preset=OpenMP
- name: Test.
run : |
ctest --preset=OpenMP
build-documentation:
needs: [set-vars, build-image]
runs-on: [ubuntu-latest]
Expand Down
84 changes: 65 additions & 19 deletions CMakeLists.txt
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()
26 changes: 25 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,33 @@
}
],
"buildPresets" : [
{
"name" : "default",
"configurePreset" : "default",
"inheritConfigureEnvironment" : true
},
{
"name" : "OpenMP",
"configurePreset" : "OpenMP",
"inherits" : "default"
}
],
"testPresets": [
{
"name" : "default",
"configurePreset" : "default",
"inheritConfigureEnvironment" : true,
"output" : {"outputOnFailure": true},
"execution" : {
"noTestsAction" : "error",
"stopOnFailure" : false,
"scheduleRandom" : true
}
},
{
"name" : "OpenMP",
"configurePreset" : "OpenMP"
"configurePreset" : "OpenMP",
"inherits" : "default"
}
]
}
File renamed without changes.
20 changes: 19 additions & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#--- Find Doxygen.
string(JSON Doxygen_REQUIRED_VERSION GET "${VERSION_JSON}" dependencies doxygen value)

find_package(
Doxygen
${DOXYGEN_VERSION}
${Doxygen_REQUIRED_VERSION}
REQUIRED
)

Expand All @@ -13,11 +15,27 @@ set(DOXYGEN_USE_MDFILE_AS_MAINPAGE ${HOMEPAGE_MD})
set(DOXYGEN_TIMESTAMP YES)
set(DOXYGEN_WARN_AS_ERROR YES)
set(DOXYGEN_SOURCE_BROWSER YES)
set(DOXYGEN_WARN_IF_UNDOCUMENTED NO)
set(DOXYGEN_GENERATE_TAGFILE "${CMAKE_CURRENT_BINARY_DIR}/html/${CMAKE_PROJECT_NAME}.tag")

#---- Extract files for documentation.
get_target_property(KokkosUtils_TARGET_FILES_FOR_DOC KokkosUtils INTERFACE_SOURCES)
get_property(KokkosUtils_FILES_FOR_DOC GLOBAL PROPERTY KokkosUtils_FILES_FOR_DOC)

#---- Add Doxygen as a target.
# See also https://cmake.org/cmake/help/latest/module/FindDoxygen.html.
doxygen_add_docs(
docs

# Homepage
${HOMEPAGE_MD}

# Headers from our KokkosUtils library target
${KokkosUtils_TARGET_FILES_FOR_DOC}

# Files added to the global property KokkosUtils_FILES_FOR_DOC
${KokkosUtils_FILES_FOR_DOC}

# Files NOT added to the global property KokkosUtils_FILES_FOR_DOC
${CMAKE_SOURCE_DIR}/docs/tests.dox
)
6 changes: 6 additions & 0 deletions docs/tests.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @defgroup automatedtests Automated test suite
* @{
* @defgroup unittests Unit tests
* @}
*/
15 changes: 15 additions & 0 deletions include/kokkos-utils/concepts/View.hpp
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
59 changes: 59 additions & 0 deletions tests/CMakeLists.txt
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)
5 changes: 5 additions & 0 deletions tests/concepts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### TEST : View ###
add_one_test(
TEST_NAME View
)

30 changes: 30 additions & 0 deletions tests/concepts/test_View.cpp
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

0 comments on commit 365df5b

Please sign in to comment.