Skip to content
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
46 changes: 25 additions & 21 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true


##############################################################################
# 1) Linux – Clang / Ninja
##############################################################################
Expand All @@ -32,8 +31,8 @@ jobs:
sudo apt-get install -y git build-essential cmake ninja-build \
zip unzip curl pkg-config ca-certificates \
clang-21 lld-21 libc++-21-dev libc++abi-21-dev
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-21 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-21 100
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-21 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-21 100
sudo update-alternatives --install /usr/bin/lld lld /usr/bin/lld-21 100
- name: Linux (Clang) (x86-linux)
triplet: x86-linux
Expand All @@ -56,8 +55,8 @@ jobs:
# Install GCC 15 with multilib support
sudo apt-get install -y gcc-15-multilib g++-15-multilib
# Set up alternatives for Clang
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-21 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-21 100
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-21 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-21 100
sudo update-alternatives --install /usr/bin/lld lld /usr/bin/lld-21 100
# Set up alternatives for GCC
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-15 100
Expand All @@ -73,8 +72,8 @@ jobs:
sudo apt-get install -y git build-essential cmake ninja-build \
zip unzip curl pkg-config ca-certificates \
clang-21 lld-21 libc++-21-dev libc++abi-21-dev
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-21 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-21 100
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-21 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-21 100
sudo update-alternatives --install /usr/bin/lld lld /usr/bin/lld-21 100
fail-fast: false
env:
Expand All @@ -84,16 +83,6 @@ jobs:
shell: bash
run: ${{ matrix.install_cmd }}

- name: Verify compiler versions
shell: bash
run: |
echo "=== Clang ==="
clang --version
clang++ --version
echo "=== GCC ==="
gcc --version || true
g++ --version || true

- name: Checkout repository (with sub-modules)
uses: actions/checkout@v4
with:
Expand All @@ -115,13 +104,28 @@ jobs:
-DOMATH_BUILD_BENCHMARK=OFF \
-DVCPKG_MANIFEST_FEATURES="imgui;avx2;tests"

- name: Build
- name: Build and Run (non-coverage)
if: ${{ matrix.triplet != 'x64-linux' }}
shell: bash
run: cmake --build cmake-build/build/${{ matrix.preset }} --target unit_tests omath
run: |
cmake --build cmake-build/build/${{ matrix.preset }} --target unit_tests omath
./out/Release/unit_tests

- name: Run unit_tests
- name: Run clang coverage (x64-linux)
if: ${{ matrix.triplet == 'x64-linux' }}
shell: bash
run: ./out/Release/unit_tests
run: |
sudo apt-get update
sudo apt-get install -y lcov llvm-21
export PATH="/usr/lib/llvm-21/bin:$PATH"
NO_AVX=1 ./scripts/run_clang_coverage.sh build/clang-coverage-lcov

- name: Run coveralls (x64-linux)
if: ${{ matrix.triplet == 'x64-linux' }}
uses: coverallsapp/github-action@master
with:
path-to-lcov: ./build/clang-coverage-lcov/coverage/coverage.fixed.lcov
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Upload logs on failure
if: ${{ failure() }}
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
/out
*.DS_Store
/extlibs/vcpkg
.idea/workspace.xml
.idea/workspace.xml
/build/
*.gcov
70 changes: 68 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ project(omath VERSION ${OMATH_VERSION} LANGUAGES CXX)
include(CMakePackageConfigHelpers)
include(CheckCXXCompilerFlag)

include(cmake/Coverage.cmake)

if (MSVC)
check_cxx_compiler_flag("/arch:AVX2" COMPILER_SUPPORTS_AVX2)
else ()
Expand All @@ -23,7 +25,7 @@ option(OMATH_STATIC_MSVC_RUNTIME_LIBRARY "Force Omath to link static runtime" OF
option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build to improve general performance" ON)
option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" OFF)
option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" ON)

option(OMATH_ENABLE_COVERAGE "Enable compiling tests with coverage. (Linux only)" ON)

if (VCPKG_MANIFEST_FEATURES)
foreach (omath_feature IN LISTS VCPKG_MANIFEST_FEATURES)
Expand Down Expand Up @@ -60,6 +62,7 @@ if (${PROJECT_IS_TOP_LEVEL})
message(STATUS "[${PROJECT_NAME}]: ImGUI integration feature status ${OMATH_IMGUI_INTEGRATION}")
message(STATUS "[${PROJECT_NAME}]: Legacy features support ${OMATH_ENABLE_LEGACY}")
message(STATUS "[${PROJECT_NAME}]: Building using vcpkg ${OMATH_BUILD_VIA_VCPKG}")
message(STATUS "[${PROJECT_NAME}]: Coverage is ${OMATH_ENABLE_COVERAGE}")
endif ()

file(GLOB_RECURSE OMATH_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
Expand All @@ -76,6 +79,13 @@ add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_VERSION="${PROJECT_VERSION}")

# If forward_helpers.cpp is present, compile it with inlining disabled so that
# emitted symbols/debug-info are produced in that TU (helpful for coverage attribution).
# Delegate coverage-related configuration to cmake/Coverage.cmake
if(OMATH_ENABLE_COVERAGE AND CMAKE_HOST_LINUX AND OMATH_BUILD_TESTS)
omath_setup_coverage_for_root(${PROJECT_NAME})
endif()

if (OMATH_IMGUI_INTEGRATION)
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_IMGUI_INTEGRATION)

Expand Down Expand Up @@ -135,6 +145,11 @@ if (OMATH_USE_AVX2)
endif ()
endif ()

if(EMSCRIPTEN)
target_compile_options(${PROJECT_NAME} PRIVATE -fexceptions)
target_link_options(${PROJECT_NAME} PRIVATE -fexceptions)
endif()

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)

if (OMATH_BUILD_TESTS)
Expand All @@ -150,6 +165,56 @@ if (OMATH_BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()

if(OMATH_ENABLE_COVERAGE AND CMAKE_HOST_LINUX AND OMATH_BUILD_TESTS)
# Configure coverage flags per-compiler:
# - For Clang/AppleClang use LLVM's instrumentation flags so the build
# produces .profraw files usable by llvm-profdata/llvm-cov.
# - For GCC use the traditional gcov flags (-fprofile-arcs -ftest-coverage).
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:-g>
$<$<CONFIG:Debug>:-fprofile-instr-generate>
$<$<CONFIG:Debug>:-fcoverage-mapping>
)
# No special link flags needed for Clang llvm profile instrumentation.
else()
# Default to GCC-style gcov instrumentation for other compilers.
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:-g>
$<$<CONFIG:Debug>:-fprofile-arcs>
$<$<CONFIG:Debug>:-ftest-coverage>
)
# Link-time flags to ensure coverage support for gcov
target_link_libraries(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:-fprofile-arcs>
$<$<CONFIG:Debug>:-ftest-coverage>
)
endif()

# Normalize recorded source file paths in debug info and coverage by
# rewriting build/source prefixes to a stable value. This helps tools
# like geninfo/gcov map execution addresses to canonical header paths.
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
# Map the absolute source and binary paths to a short placeholder
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" OMATH_SRC_PATH)
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}" OMATH_BUILD_PATH)
string(REPLACE "/" "\\/" OMATH_SRC_PATH_ESCAPED "${OMATH_SRC_PATH}")
string(REPLACE "/" "\\/" OMATH_BUILD_PATH_ESCAPED "${OMATH_BUILD_PATH}")

# Add compiler flags that rewrite recorded paths in debug info.
# Map them to '.' so geninfo can find sources relative to the
# build working directory used when collecting coverage.
target_compile_options(${PROJECT_NAME} PRIVATE
# Map source tree to one level up so geninfo running from the
# binary directory can find ../include/... and ../source/...
$<$<CONFIG:Debug>:-ffile-prefix-map=${OMATH_SRC_PATH}=..>
$<$<CONFIG:Debug>:-ffile-prefix-map=${OMATH_BUILD_PATH}=.>
$<$<CONFIG:Debug>:-fdebug-prefix-map=${OMATH_SRC_PATH}=..>
$<$<CONFIG:Debug>:-fdebug-prefix-map=${OMATH_BUILD_PATH}=.>
)
endif()
endif ()

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND OMATH_THREAT_WARNING_AS_ERROR)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
elseif (OMATH_THREAT_WARNING_AS_ERROR)
Expand All @@ -167,6 +232,8 @@ target_include_directories(${PROJECT_NAME}
$<INSTALL_INTERFACE:include> # Use this path when the project is installed
)

# Coverage targets are configured by cmake/Coverage.cmake via
# omath_setup_coverage_for_root().

# Installation rules

Expand All @@ -188,7 +255,6 @@ install(EXPORT ${PROJECT_NAME}Targets
DESTINATION lib/cmake/${PROJECT_NAME} COMPONENT ${PROJECT_NAME}
)


# Generate the omathConfigVersion.cmake file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/omathConfigVersion.cmake"
Expand Down
4 changes: 0 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@
"name": "linux-base",
"hidden": true,
"inherits": "base",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-21",
"CMAKE_CXX_COMPILER": "clang++-21"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
Expand Down
Loading
Loading