32 lines
950 B
CMake
32 lines
950 B
CMake
# Copyright (c) 2026 Dominic Masters
|
|
#
|
|
# This software is released under the MIT License.
|
|
# https://opensource.org/licenses/MIT
|
|
|
|
find_package(cmocka REQUIRED)
|
|
|
|
# Function to create a test executable from a single .c file
|
|
function(dusktest TEST_C_FILE)
|
|
# Create target name from file name
|
|
get_filename_component(TEST_NAME ${TEST_C_FILE} NAME_WE)
|
|
|
|
# Create the executable target
|
|
add_executable(${TEST_NAME})
|
|
|
|
# Setup some compiler definitions.
|
|
target_compile_definitions(${TEST_NAME} PRIVATE
|
|
DUSK_TEST_ASSERT=1
|
|
)
|
|
|
|
# Add the test file
|
|
target_sources(${TEST_NAME} PRIVATE ${TEST_C_FILE})
|
|
|
|
# Add sources, both common and test-specific
|
|
target_include_directories(${TEST_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR} ${DUSK_TEST_DIR})
|
|
|
|
# Link against DuskCore and cmocka
|
|
target_link_libraries(${TEST_NAME} PUBLIC ${DUSK_LIBRARY_TARGET_NAME} cmocka)
|
|
|
|
# Add as a CTest
|
|
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
|
|
endfunction() |