From 53b9e9ac88a212618f39eba18c79fc2c4f619b8d Mon Sep 17 00:00:00 2001 From: Anthony Cabrera Date: Wed, 10 Jun 2026 21:01:41 +0000 Subject: [PATCH 1/2] [testing] add CMake infra for `cudaq/unittests` Signed-off-by: Anthony Cabrera --- cudaq/unittests/CMakeLists.txt | 88 ++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 cudaq/unittests/CMakeLists.txt diff --git a/cudaq/unittests/CMakeLists.txt b/cudaq/unittests/CMakeLists.txt new file mode 100644 index 00000000000..d2c109721ee --- /dev/null +++ b/cudaq/unittests/CMakeLists.txt @@ -0,0 +1,88 @@ +# ============================================================================ # +# Copyright (c) 2026 NVIDIA Corporation & Affiliates. # +# All rights reserved. # +# # +# This source code and the accompanying materials are made available under # +# the terms of the Apache License 2.0 which accompanies this distribution. # +# ============================================================================ # + +add_custom_target(CudaQUnitTests) +# The following property will be used to keep track of the unit test targets +# that we create with the `add_cudaq_unittest` function. We will use this +# property to add the tests to the `CudaQUnitTests` target and to create custom +# targets for each test that we can run with +# `{make,ninja, cmake --build build -target} check-`. +set_property(GLOBAL PROPERTY CUDAQ_UNIT_TEST_TARGETS "") + + +function(create_cudaq_unittest_check_target test_name check_target_name) + add_custom_target(check-${check_target_name} + COMMAND $ + DEPENDS ${test_name} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + USES_TERMINAL + ) +endfunction(create_cudaq_unittest_check_target) + +# This is a helper function to add a unit test to the CudaQUnitTests target. +# It creates an executable for the test and it takes the test name and a test label +# as arguments, as well as optional arguments for: +# - sources +# - includes +# - linked libraries +# - compile options +# - compile definitions +# for the test. +# The test will be added to the `CudaQUnitTests` target, and a custom target will +# be created for it that we can run with `make check-`. +function(add_cudaq_unittest test_name test_label) + set(options) + set(oneValueArgs) + set(multiValueArgs + SOURCES + INCLUDES + LINKED_LIBS + COMPILE_OPTS + COMPILE_DEFS + ) + + + cmake_parse_arguments(USER_ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + add_executable(${test_name} + ${USER_ARG_SOURCES} + ) + + if (USER_ARG_INCLUDES) + target_include_directories(${test_name} + PRIVATE + ${USER_ARG_INCLUDES} + ) + endif() + + if (USER_ARG_LINKED_LIBS) + target_link_libraries(${test_name} + PRIVATE + ${USER_ARG_LINKED_LIBS} + gtest_main + ) + endif() + + if (USER_ARG_COMPILE_DEFS) + target_compile_definitions(${test_name} + PRIVATE + ${USER_ARG_COMPILE_DEFS} + ) + endif() + + if (USER_ARG_COMPILE_OPTS) + target_compile_options(${test_name} + PRIVATE + ${USER_ARG_COMPILE_OPTS} + ) + endif() + + add_dependencies(CudaQUnitTests ${test_name}) + + set_property(GLOBAL APPEND PROPERTY CUDAQ_UNIT_TEST_TARGETS ${test_name}) +endfunction(add_cudaq_unittest) \ No newline at end of file From b3065b156557d7d469600303757b3f28fd0550c8 Mon Sep 17 00:00:00 2001 From: Anthony Cabrera Date: Wed, 10 Jun 2026 21:37:21 +0000 Subject: [PATCH 2/2] add link options Signed-off-by: Anthony Cabrera --- cudaq/unittests/CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cudaq/unittests/CMakeLists.txt b/cudaq/unittests/CMakeLists.txt index d2c109721ee..2d4a07d661b 100644 --- a/cudaq/unittests/CMakeLists.txt +++ b/cudaq/unittests/CMakeLists.txt @@ -41,6 +41,7 @@ function(add_cudaq_unittest test_name test_label) set(multiValueArgs SOURCES INCLUDES + LINK_OPTS LINKED_LIBS COMPILE_OPTS COMPILE_DEFS @@ -68,6 +69,14 @@ function(add_cudaq_unittest test_name test_label) ) endif() + if (USER_ARG_LINK_OPTS) + target_link_options(${test_name} + PRIVATE + ${USER_ARG_LINK_OPTS} + ) + endif() + + if (USER_ARG_COMPILE_DEFS) target_compile_definitions(${test_name} PRIVATE @@ -85,4 +94,4 @@ function(add_cudaq_unittest test_name test_label) add_dependencies(CudaQUnitTests ${test_name}) set_property(GLOBAL APPEND PROPERTY CUDAQ_UNIT_TEST_TARGETS ${test_name}) -endfunction(add_cudaq_unittest) \ No newline at end of file +endfunction(add_cudaq_unittest)