Skip to content

Commit

Permalink
Merge pull request #53 from lanl/jmm/cleanup-tests
Browse files Browse the repository at this point in the history
move target logic into test cmakelist
  • Loading branch information
Yurlungur authored Sep 4, 2024
2 parents f3775d1 + 3862f84 commit b8392bc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
"Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles.")
endif()

option (PORTS_OF_CALL_BUILD_TESTING "Test the current installation")
option (PORTS_OF_CALL_BUILD_TESTING "Test the current installation" OFF)
# off by default but possible to turn on
if (PORTS_OF_CALL_BUILD_TESTING)
set(PORTS_OF_CALL_TEST_PORTABILITY_STRATEGY "None" CACHE STRING
"Portability strategy used by tests")
set_property(CACHE PORTS_OF_CALL_TEST_PORTABILITY_STRATEGY
PROPERTY STRINGS None Cuda Kokkos)
endif()

# CONFIGURATION LOGIC
# ----------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion spack-repo/packages/ports-of-call/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PortsOfCall(CMakePackage):
variant("test", default=False, description="Build tests")

depends_on("cmake@3.12:")
depends_on("catch2@3.0.1:", when"+test")
depends_on("catch2@3.0.1:", when="+test")

def cmake_args(self):
args = [
Expand Down
19 changes: 16 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ if(NOT TARGET Catch2::Catch2)
find_package(Catch2 QUIET)
if(NOT Catch2_FOUND)
message(STATUS "Fetching Catch2 as needed")
# idiomatic FetchContent
include(FetchContent)
FetchContent_Declare(
Catch2
Expand All @@ -29,14 +28,28 @@ endif()
# this interface target is to collect
# compile/link options for the test
add_library(portsofcall_iface INTERFACE)
if (PORTABILITY_STRATEGY_KOKKOS)
if (PORTS_OF_CALL_TEST_PORTABILITY_STRATEGY STREQUAL "Kokkos")
if(NOT TARGET Kokkos::kokkos)
find_package(Kokkos REQUIRED)
find_package(Kokkos QUIET)
if(NOT Kokkos_FOUND)
message(STATUS "Fetching Kokkos as needed")
include(FetchContent)
FetchContent_Declare(
Kokkos
GIT_REPOSITORY https://github.com/kokkos/kokkos.git
# This is most recent but any version that supports C++17 is
# fine
GIT_TAG 4.3.01)
FetchContent_MakeAvailable(Kokkos)
endif()
endif()

target_link_libraries(portsofcall_iface INTERFACE Kokkos::kokkos)
# this comes with ports-of-call target
target_compile_definitions(portsofcall_iface INTERFACE PORTABILITY_STRATEGY_KOKKOS)
elseif (PORTS_OF_CALL_TEST_PORTABILITY_STRATEGY STREQUAL "Cuda")
message(FATAL_ERROR "Cuda tests not yet fully supported")
target_compile_definitions(portsofcall_iface INTERFACE PORTABILITY_STRATEGY_CUDA)
endif()

target_link_libraries(portsofcall_iface INTERFACE Catch2::Catch2)
Expand Down

0 comments on commit b8392bc

Please sign in to comment.