Inital commit
CI / macOS (push) Has been cancelled
CI / Windows / Clang (push) Has been cancelled
CI / macOS (push) Has been cancelled
CI / Windows / Clang (push) Has been cancelled
This commit is contained in:
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
# ==============================================================================
|
||||
# Coverage
|
||||
# ==============================================================================
|
||||
# gcov-based coverage via --coverage, reported by gcovr.
|
||||
# Works with GCC and Clang on Linux and macOS out of the box.
|
||||
# Windows requires GCC (e.g. MinGW via scoop install gcc) or a Clang build
|
||||
# that includes compiler-rt (clang_rt.profile).
|
||||
#
|
||||
# Requires: gcovr on PATH (install via: uv tool install gcovr)
|
||||
# Usage: cmake -DENABLE_COVERAGE=ON ... then ninja coverage
|
||||
# Report: build/coverage/index.html
|
||||
# ==============================================================================
|
||||
|
||||
option(ENABLE_COVERAGE "Build with coverage instrumentation" OFF)
|
||||
|
||||
if (ENABLE_COVERAGE)
|
||||
if (NOT CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
|
||||
message(FATAL_ERROR "ENABLE_COVERAGE requires GCC or Clang")
|
||||
endif()
|
||||
|
||||
find_program(GCOVR_EXE gcovr REQUIRED)
|
||||
|
||||
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
# gcovr needs a single-token gcov executable. Wrap llvm-cov gcov in a
|
||||
# script placed in the build dir (guaranteed no spaces in path).
|
||||
# AppleClang ships llvm-cov inside Xcode, reached only via xcrun.
|
||||
if (WIN32)
|
||||
find_program(LLVM_COV_EXE llvm-cov REQUIRED)
|
||||
set(GCOV_EXECUTABLE "${CMAKE_BINARY_DIR}/llvm-gcov.bat")
|
||||
file(WRITE "${GCOV_EXECUTABLE}" "@echo off\r\n\"${LLVM_COV_EXE}\" gcov %*\r\n")
|
||||
elseif (CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
|
||||
find_program(XCRUN_EXE xcrun REQUIRED)
|
||||
set(GCOV_EXECUTABLE "${CMAKE_BINARY_DIR}/llvm-gcov.sh")
|
||||
file(WRITE "${GCOV_EXECUTABLE}" "#!/bin/sh\nexec xcrun llvm-cov gcov \"$@\"\n")
|
||||
file(CHMOD "${GCOV_EXECUTABLE}"
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE)
|
||||
else()
|
||||
find_program(LLVM_COV_EXE llvm-cov REQUIRED)
|
||||
set(GCOV_EXECUTABLE "${CMAKE_BINARY_DIR}/llvm-gcov.sh")
|
||||
file(WRITE "${GCOV_EXECUTABLE}" "#!/bin/sh\nexec \"${LLVM_COV_EXE}\" gcov \"$@\"\n")
|
||||
file(CHMOD "${GCOV_EXECUTABLE}"
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE)
|
||||
endif()
|
||||
message(STATUS "Coverage: enabled (gcovr: ${GCOVR_EXE}, gcov: llvm-cov gcov)")
|
||||
else()
|
||||
set(GCOV_EXECUTABLE "gcov")
|
||||
message(STATUS "Coverage: enabled (gcovr: ${GCOVR_EXE})")
|
||||
endif()
|
||||
|
||||
add_compile_options(--coverage -O0 -g)
|
||||
add_link_options(--coverage)
|
||||
endif()
|
||||
Vendored
+92
@@ -0,0 +1,92 @@
|
||||
# ==============================================================================
|
||||
# Find CMock
|
||||
# ==============================================================================
|
||||
# This module fetches the CMock mocking framework (depends on Unity).
|
||||
#
|
||||
# Targets provided:
|
||||
# CMock::CMock - The CMock library target
|
||||
#
|
||||
# Variables set:
|
||||
# CMock_FOUND - TRUE if CMock is available
|
||||
# CMock_LIBRARIES - The CMock library target (CMock::CMock)
|
||||
# CMock_INCLUDE_DIR - Include directories for CMock
|
||||
# CMock_VERSION - Version of CMock (if available)
|
||||
#
|
||||
# Generator variables (set when Ruby is found):
|
||||
# CMOCK_SCRIPT - Path to lib/cmock.rb
|
||||
# RUBY_EXECUTABLE - Path to ruby interpreter
|
||||
# ==============================================================================
|
||||
|
||||
if (DEFINED _FINDCMOCK_INCLUDED)
|
||||
return()
|
||||
endif()
|
||||
set(_FINDCMOCK_INCLUDED TRUE)
|
||||
|
||||
find_package(Unity REQUIRED)
|
||||
|
||||
if (DEFINED CMock_FIND_VERSION AND NOT CMock_FIND_VERSION STREQUAL "")
|
||||
set(CMOCK_VERSION "${CMock_FIND_VERSION}")
|
||||
else()
|
||||
set(CMOCK_VERSION "2.6.0")
|
||||
endif()
|
||||
|
||||
message(STATUS "Fetching CMock ${CMOCK_VERSION}")
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
cmock
|
||||
URL https://github.com/ThrowTheSwitch/CMock/archive/refs/tags/v${CMOCK_VERSION}.zip
|
||||
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
|
||||
)
|
||||
|
||||
# CMock uses Meson — bypass its build system and compile src/cmock.c directly.
|
||||
# FetchContent_MakeAvailable cannot be used here (no CMakeLists.txt in CMock),
|
||||
# so we call FetchContent_Populate directly and opt into the old policy.
|
||||
cmake_policy(PUSH)
|
||||
cmake_policy(SET CMP0169 OLD)
|
||||
FetchContent_GetProperties(cmock)
|
||||
if (NOT cmock_POPULATED)
|
||||
FetchContent_Populate(cmock)
|
||||
endif()
|
||||
cmake_policy(POP)
|
||||
|
||||
# The Ruby generator expects vendor/unity/auto/type_sanitizer.rb — populate
|
||||
# it from the Unity source we already have rather than needing a git submodule
|
||||
set(_cmock_vendor_auto "${cmock_SOURCE_DIR}/vendor/unity/auto")
|
||||
if (NOT EXISTS "${_cmock_vendor_auto}/type_sanitizer.rb")
|
||||
file(MAKE_DIRECTORY "${_cmock_vendor_auto}")
|
||||
file(COPY "${unity_SOURCE_DIR}/auto/" DESTINATION "${_cmock_vendor_auto}")
|
||||
endif()
|
||||
|
||||
if (NOT TARGET cmock)
|
||||
add_library(cmock STATIC "${cmock_SOURCE_DIR}/src/cmock.c")
|
||||
target_include_directories(cmock PUBLIC
|
||||
"${cmock_SOURCE_DIR}/src"
|
||||
"${unity_SOURCE_DIR}/src"
|
||||
)
|
||||
target_link_libraries(cmock PUBLIC unity)
|
||||
endif()
|
||||
|
||||
if (NOT TARGET CMock::CMock)
|
||||
add_library(CMock::CMock ALIAS cmock)
|
||||
endif()
|
||||
|
||||
set(CMock_FOUND TRUE)
|
||||
set(CMock_LIBRARIES CMock::CMock)
|
||||
set(CMock_VERSION "${CMOCK_VERSION}")
|
||||
set(CMock_INCLUDE_DIR "${cmock_SOURCE_DIR}/src")
|
||||
set(CMOCK_SCRIPT "${cmock_SOURCE_DIR}/lib/cmock.rb" CACHE FILEPATH "Path to CMock Ruby generator")
|
||||
|
||||
if (CMock_INCLUDE_DIR AND TARGET cmock)
|
||||
set_target_properties(cmock PROPERTIES
|
||||
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${CMock_INCLUDE_DIR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
find_program(RUBY_EXECUTABLE ruby)
|
||||
if (NOT RUBY_EXECUTABLE)
|
||||
message(WARNING "Ruby not found — CMock code generation unavailable")
|
||||
endif()
|
||||
|
||||
set(CMOCK_LICENSE_FILE "${cmock_SOURCE_DIR}/LICENSE.txt" CACHE FILEPATH "Path to CMock license file")
|
||||
Vendored
+67
@@ -0,0 +1,67 @@
|
||||
# ==============================================================================
|
||||
# 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)
|
||||
|
||||
# Unity sets INTERFACE_SYSTEM_INCLUDE_DIRECTORIES to a path inside the build
|
||||
# tree, which CMake rejects on newer versions. The path stays in
|
||||
# INTERFACE_INCLUDE_DIRECTORIES so headers are still found.
|
||||
if (TARGET unity)
|
||||
set_target_properties(unity PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "")
|
||||
endif()
|
||||
|
||||
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 (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")
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
# ==============================================================================
|
||||
# Compiler Flags
|
||||
# ==============================================================================
|
||||
# Sets BASE_OPTIONS (warning flags) and BASE_DEFINITIONS.
|
||||
# Apply per-target via target_compile_options / target_compile_definitions
|
||||
# to avoid polluting fetched dependencies.
|
||||
#
|
||||
# Requires: Platform.cmake (for IS_CLANG_OR_GCC / IS_MSVC)
|
||||
# ==============================================================================
|
||||
|
||||
set(BASE_DEFINITIONS "")
|
||||
set(BASE_LIBRARIES "")
|
||||
|
||||
set(BASE_OPTIONS "")
|
||||
if (IS_CLANG_OR_GCC)
|
||||
set(BASE_OPTIONS
|
||||
"-Wall"
|
||||
"-Wextra"
|
||||
"-Werror"
|
||||
)
|
||||
elseif (IS_MSVC)
|
||||
set(BASE_OPTIONS
|
||||
"/W4"
|
||||
"/WX"
|
||||
"/utf-8"
|
||||
)
|
||||
endif()
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
# ==============================================================================
|
||||
# IDE Integration
|
||||
# ==============================================================================
|
||||
# Groups dependency targets into folders for Visual Studio / Xcode.
|
||||
# Has no effect on the build.
|
||||
# ==============================================================================
|
||||
|
||||
function(set_target_folder target folder)
|
||||
if (TARGET ${target})
|
||||
set_target_properties(${target} PROPERTIES FOLDER ${folder})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if (CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR MATCHES "Xcode")
|
||||
set_target_folder(unity deps)
|
||||
set_target_folder(cmock deps)
|
||||
endif()
|
||||
Vendored
+64
@@ -0,0 +1,64 @@
|
||||
# ==============================================================================
|
||||
# Platform Detection
|
||||
# ==============================================================================
|
||||
# This module detects the current platform and compiler, setting IS_* variables
|
||||
# that can be used throughout the build system for conditional logic.
|
||||
#
|
||||
# Compiler flags set:
|
||||
# IS_CLANG_OR_GCC - TRUE if using Clang or GCC compiler
|
||||
# IS_MSVC - TRUE if using Microsoft Visual C++ compiler
|
||||
#
|
||||
# Platform flags set:
|
||||
# IS_WINDOWS - TRUE if building for Windows
|
||||
# IS_LINUX - TRUE if building for Linux
|
||||
# IS_MACOS - TRUE if building for macOS
|
||||
# IS_IOS - TRUE if building for iOS
|
||||
# IS_ANDROID - TRUE if building for Android
|
||||
# IS_EMSCRIPTEN - TRUE if building for WebAssembly via Emscripten
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Compiler Detection
|
||||
# ------------------------------------------------------------------------------
|
||||
set(IS_CLANG_OR_GCC FALSE)
|
||||
set(IS_MSVC FALSE)
|
||||
|
||||
if(MSVC)
|
||||
set(IS_MSVC TRUE)
|
||||
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
|
||||
set(IS_CLANG_OR_GCC TRUE)
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Platform Detection
|
||||
# ------------------------------------------------------------------------------
|
||||
set(IS_WINDOWS FALSE)
|
||||
set(IS_LINUX FALSE)
|
||||
set(IS_MACOS FALSE)
|
||||
set(IS_IOS FALSE)
|
||||
set(IS_ANDROID FALSE)
|
||||
set(IS_EMSCRIPTEN FALSE)
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
message(STATUS "Platform: Emscripten")
|
||||
set(IS_EMSCRIPTEN TRUE)
|
||||
elseif(ANDROID)
|
||||
message(STATUS "Platform: Android")
|
||||
set(IS_ANDROID TRUE)
|
||||
elseif(APPLE)
|
||||
if(IOS)
|
||||
message(STATUS "Platform: iOS")
|
||||
set(IS_IOS TRUE)
|
||||
else()
|
||||
message(STATUS "Platform: macOS")
|
||||
set(IS_MACOS TRUE)
|
||||
endif()
|
||||
elseif(WIN32)
|
||||
message(STATUS "Platform: Windows")
|
||||
set(IS_WINDOWS TRUE)
|
||||
elseif(UNIX)
|
||||
message(STATUS "Platform: Linux")
|
||||
set(IS_LINUX TRUE)
|
||||
else()
|
||||
message(FATAL_ERROR "Unknown platform!")
|
||||
endif()
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
# ==============================================================================
|
||||
# Sanitizers
|
||||
# ==============================================================================
|
||||
# AddressSanitizer (ASan) support.
|
||||
# Works with GCC/Clang on Linux and macOS, Clang on Windows (requires
|
||||
# compiler-rt with sanitizers), and MSVC on Windows (/fsanitize=address).
|
||||
#
|
||||
# Usage: cmake -DENABLE_ASAN=ON ...
|
||||
# ==============================================================================
|
||||
|
||||
option(ENABLE_ASAN "Build with AddressSanitizer" OFF)
|
||||
|
||||
if (ENABLE_ASAN)
|
||||
if (ENABLE_COVERAGE)
|
||||
message(FATAL_ERROR "ENABLE_ASAN and ENABLE_COVERAGE cannot be used together")
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
add_compile_options(/fsanitize=address)
|
||||
message(STATUS "ASan: enabled (MSVC)")
|
||||
elseif (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
|
||||
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
|
||||
add_link_options(-fsanitize=address)
|
||||
message(STATUS "ASan: enabled (${CMAKE_C_COMPILER_ID})")
|
||||
else()
|
||||
message(FATAL_ERROR "ENABLE_ASAN: unsupported compiler ${CMAKE_C_COMPILER_ID}")
|
||||
endif()
|
||||
endif()
|
||||
Reference in New Issue
Block a user