Files
ctdd/deps/FindUnity.cmake
T
portersky cd19cc14c0 feat: add Unity color and check target
Enable UNITY_OUTPUT_COLOR and UNITY_INCLUDE_PRINT_FORMATTED via
compile definitions on the unity target so colors propagate to all
test suites automatically.

Add a 'check' custom target that builds all suites and runs CTest
with --output-on-failure and USES_TERMINAL, keeping ANSI colors
alive through Ninja's buffering.
2026-05-09 21:32:58 +02:00

66 lines
1.9 KiB
CMake

# ==============================================================================
# Find Unity
# ==============================================================================
# This module fetches the Unity unit testing framework.
#
# Targets provided:
# Unity::Unity - The Unity library target
#
# Variables set:
# Unity_FOUND - TRUE if Unity is available
# Unity_LIBRARIES - The Unity library target (Unity::Unity)
# Unity_INCLUDE_DIR - Include directories for Unity
# Unity_VERSION - Version of Unity (if available)
# ==============================================================================
if (DEFINED _FINDUNITY_INCLUDED)
return()
endif()
set(_FINDUNITY_INCLUDED TRUE)
if (DEFINED Unity_FIND_VERSION AND NOT Unity_FIND_VERSION STREQUAL "")
set(UNITY_VERSION "${Unity_FIND_VERSION}")
else()
set(UNITY_VERSION "2.6.1")
endif()
message(STATUS "Fetching Unity ${UNITY_VERSION}")
include(FetchContent)
FetchContent_Declare(
unity
URL https://github.com/ThrowTheSwitch/Unity/archive/refs/tags/v${UNITY_VERSION}.zip
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
FetchContent_MakeAvailable(unity)
if (NOT TARGET Unity::Unity)
if (TARGET unity)
add_library(Unity::Unity ALIAS unity)
else()
message(FATAL_ERROR "Could not fetch Unity; no target unity or Unity::Unity available")
endif()
endif()
set(Unity_FOUND TRUE)
set(Unity_LIBRARIES Unity::Unity)
set(Unity_VERSION "${UNITY_VERSION}")
set(Unity_INCLUDE_DIR "${unity_SOURCE_DIR}/src")
if (Unity_INCLUDE_DIR AND TARGET unity)
set_target_properties(unity PROPERTIES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${Unity_INCLUDE_DIR}"
)
endif()
if (TARGET unity)
target_compile_definitions(unity PUBLIC
UNITY_OUTPUT_COLOR
UNITY_INCLUDE_PRINT_FORMATTED
)
endif()
set(UNITY_LICENSE_FILE "${unity_SOURCE_DIR}/LICENSE.txt" CACHE FILEPATH "Path to Unity license file")