Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move target logic into test cmakelist #53

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
rbberger marked this conversation as resolved.
Show resolved Hide resolved
target_compile_definitions(portsofcall_iface INTERFACE PORTABILITY_STRATEGY_CUDA)
endif()

target_link_libraries(portsofcall_iface INTERFACE Catch2::Catch2)
Expand Down
Loading