diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 13aee868..01cca253 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -19,23 +19,28 @@ jobs: name: Arch Linux (Clang) runs-on: ubuntu-latest container: archlinux:latest - + env: + VCPKG_ROOT: ${{ github.workspace }}/vcpkg steps: - name: Install basic tool-chain with pacman shell: bash run: | pacman -Sy --noconfirm archlinux-keyring pacman -Syu --noconfirm --needed \ - git base-devel clang cmake ninja + git base-devel clang cmake ninja zip unzip fmt - name: Checkout repository (with sub-modules) uses: actions/checkout@v4 with: submodules: recursive + - name: Set up vcpkg + shell: bash + run: | + git clone https://github.com/microsoft/vcpkg "$VCPKG_ROOT" - name: Configure (cmake --preset) shell: bash - run: cmake --preset linux-release -DOMATH_BUILD_TESTS=ON -DOMATH_BUILD_BENCHMARK=OFF + run: cmake --preset linux-release -DOMATH_BUILD_TESTS=ON -DOMATH_BUILD_BENCHMARK=OFF -DOMATH_BUILD_VIA_VCPKG=ON -DVCPKG_MANIFEST_FEATURES="imgui;avx2;tests" - name: Build shell: bash @@ -47,12 +52,14 @@ jobs: -############################################################################## -# 2) Windows – MSVC / Ninja -############################################################################## + ############################################################################## + # 2) Windows – MSVC / Ninja + ############################################################################## windows-build-and-test: name: Windows (MSVC) runs-on: windows-latest + env: + OMATH_BUILD_VIA_VCPKG: ON steps: - name: Checkout repository (with sub-modules) @@ -68,7 +75,7 @@ jobs: - name: Configure (cmake --preset) shell: bash - run: cmake --preset windows-release -DOMATH_BUILD_TESTS=ON -DOMATH_BUILD_BENCHMARK=OFF + run: cmake --preset windows-release -DOMATH_BUILD_TESTS=ON -DOMATH_BUILD_BENCHMARK=OFF -DOMATH_BUILD_VIA_VCPKG=ON -DVCPKG_MANIFEST_FEATURES="imgui;avx2;tests" - name: Build shell: bash diff --git a/.gitmodules b/.gitmodules index 87b94fb7..e69de29b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +0,0 @@ -[submodule "extlibs/googletest"] - path = extlibs/googletest - url = https://github.com/google/googletest.git -[submodule "extlibs/benchmark"] - path = extlibs/benchmark - url = https://github.com/google/benchmark.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 8338ee95..ed684ca1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.26) -project(omath VERSION 3.9.2 LANGUAGES CXX) +project(omath VERSION 4.0.0 LANGUAGES CXX) include(CMakePackageConfigHelpers) include(CheckCXXCompilerFlag) @@ -12,7 +12,7 @@ else () endif () option(OMATH_BUILD_TESTS "Build unit tests" ${PROJECT_IS_TOP_LEVEL}) -option(OMATH_BUILD_BENCHMARK "Build benchmarks" ${PROJECT_IS_TOP_LEVEL}) +option(OMATH_BUILD_BENCHMARK "Build benchmarks" OFF) option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON) option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF) option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ${COMPILER_SUPPORTS_AVX2}) @@ -21,7 +21,28 @@ option(OMATH_BUILD_EXAMPLES "Build example projects with you can learn & play" O option(OMATH_STATIC_MSVC_RUNTIME_LIBRARY "Force Omath to link static runtime" OFF) 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" OFF) +option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" ON) + +option(OMATH_BUILD_VIA_VCPKG "Will enable building using vcpkg, vcpkg will override some options that were set in vcpkg.json file, and search for dependencies using vcpkg" OFF) + +if (OMATH_BUILD_VIA_VCPKG AND NOT CMAKE_TOOLCHAIN_FILE) + message(FATAL_ERROR "[${PROJECT_NAME}] CMAKE_TOOLCHAIN_FILE IS EMPTY! Please set env variable called 'VCPKG_ROOT' to vcpkg root folder here is an example: 'C:/vcpkg' or '/home/user/vcpkg' ") +endif () + +if (OMATH_BUILD_VIA_VCPKG AND VCPKG_MANIFEST_FEATURES) + foreach (omath_feature IN LISTS VCPKG_MANIFEST_FEATURES) + if (omath_feature STREQUAL "imgui") + set(OMATH_IMGUI_INTEGRATION ON) + elseif (omath_feature STREQUAL "avx2") + set(OMATH_USE_AVX2 ${COMPILER_SUPPORTS_AVX2}) + elseif (omath_feature STREQUAL "tests") + set(OMATH_BUILD_TESTS ON) + elseif (omath_feature STREQUAL "benchmark") + set(OMATH_BUILD_BENCHMARK ON) + endif () + + endforeach () +endif () if (OMATH_USE_AVX2 AND NOT COMPILER_SUPPORTS_AVX2) message(WARNING "OMATH_USE_AVX2 requested, but compiler/target does not support AVX2. Disabling.") @@ -40,6 +61,7 @@ if (${PROJECT_IS_TOP_LEVEL}) message(STATUS "[${PROJECT_NAME}]: AVX2 feature status ${OMATH_USE_AVX2}") 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}") endif () file(GLOB_RECURSE OMATH_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp") @@ -84,7 +106,7 @@ if (OMATH_SUPRESS_SAFETY_CHECKS) endif () if (OMATH_ENABLE_LEGACY) - target_compile_options(${PROJECT_NAME} PUBLIC OMATH_ENABLE_LEGACY) + target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_ENABLE_LEGACY) endif () set_target_properties(${PROJECT_NAME} PROPERTIES @@ -117,9 +139,6 @@ endif () target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23) -add_subdirectory(extlibs) - - if (OMATH_BUILD_TESTS) add_subdirectory(tests) target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_BUILD_TESTS) diff --git a/CMakePresets.json b/CMakePresets.json index a37b0c3b..3aced04b 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -8,7 +8,10 @@ "binaryDir": "${sourceDir}/cmake-build/build/${presetName}", "installDir": "${sourceDir}/cmake-build/install/${presetName}", "cacheVariables": { - "CMAKE_CXX_COMPILER": "cl.exe" + "CMAKE_CXX_COMPILER": "cl.exe", + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "VCPKG_INSTALLED_DIR": "${sourceDir}/cmake-build/vcpkg_installed", + "CMAKE_MAKE_PROGRAM": "Ninja" }, "condition": { "type": "equals", @@ -24,6 +27,25 @@ "CMAKE_BUILD_TYPE": "Debug" } }, + { + "name": "windows-debug-vcpkg", + "displayName": "Debug", + "inherits": "windows-base", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "OMATH_BUILD_VIA_VCPKG": "ON", + "VCPKG_MANIFEST_FEATURES": "tests;imgui;avx2" + } + }, + { + "name": "windows-release-vcpkg", + "displayName": "Release", + "inherits": "windows-base", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "OMATH_BUILD_VIA_VCPKG": "ON" + } + }, { "name": "windows-release", "displayName": "Release", @@ -39,7 +61,10 @@ "binaryDir": "${sourceDir}/cmake-build/build/${presetName}", "installDir": "${sourceDir}/cmake-build/install/${presetName}", "cacheVariables": { - "CMAKE_CXX_COMPILER": "clang++" + "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "VCPKG_INSTALLED_DIR": "${sourceDir}/cmake-build/vcpkg_installed", + "CMAKE_MAKE_PROGRAM": "ninja" }, "condition": { "type": "equals", @@ -55,6 +80,15 @@ "CMAKE_BUILD_TYPE": "Debug" } }, + { + "name": "linux-debug-vcpkg", + "displayName": "Linux Debug", + "inherits": "linux-base", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "OMATH_BUILD_VIA_VCPKG": "ON" + } + }, { "name": "linux-release", "displayName": "Linux Release", @@ -63,6 +97,15 @@ "CMAKE_BUILD_TYPE": "Release" } }, + { + "name": "linux-release-vcpkg", + "displayName": "Linux Release", + "inherits": "linux-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "OMATH_BUILD_VIA_VCPKG": "ON" + } + }, { "name": "darwin-base", "hidden": true, @@ -86,6 +129,15 @@ "CMAKE_BUILD_TYPE": "Debug" } }, + { + "name": "darwin-debug-vcpkg", + "displayName": "Darwin Debug", + "inherits": "darwin-base", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "OMATH_BUILD_VIA_VCPKG": "ON" + } + }, { "name": "darwin-release", "displayName": "Darwin Release", @@ -93,6 +145,15 @@ "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } + }, + { + "name": "darwin-release-vcpkg", + "displayName": "Darwin Release", + "inherits": "darwin-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "OMATH_BUILD_VIA_VCPKG": "ON" + } } ] } \ No newline at end of file diff --git a/VERSION b/VERSION index 4764627f..0c89fc92 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.9.2 \ No newline at end of file +4.0.0 \ No newline at end of file diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 124e35a2..fe48e3a9 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -11,5 +11,9 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 23 CXX_STANDARD_REQUIRED ON) - -target_link_libraries(${PROJECT_NAME} PRIVATE benchmark::benchmark omath) \ No newline at end of file +if (TARGET benchmark::benchmark) + target_link_libraries(${PROJECT_NAME} PRIVATE benchmark::benchmark omath) +else() + find_package(benchmark CONFIG REQUIRED) + target_link_libraries(${PROJECT_NAME} PRIVATE benchmark::benchmark omath) +endif () diff --git a/extlibs/CMakeLists.txt b/extlibs/CMakeLists.txt deleted file mode 100644 index 3ed280fe..00000000 --- a/extlibs/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ - -if (OMATH_BUILD_TESTS) - add_subdirectory(googletest) -endif () - -if (OMATH_BUILD_BENCHMARK) - set(BENCHMARK_ENABLE_TESTING OFF) - add_subdirectory(benchmark) -endif () \ No newline at end of file diff --git a/extlibs/benchmark b/extlibs/benchmark deleted file mode 160000 index 2948b6a2..00000000 --- a/extlibs/benchmark +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2948b6a2e61ccabecc952c24794c6960d86c9ed6 diff --git a/extlibs/googletest b/extlibs/googletest deleted file mode 160000 index 52eb8108..00000000 --- a/extlibs/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 52eb8108c5bdec04579160ae17225d66034bd723 diff --git a/include/omath/linear_algebra/mat.hpp b/include/omath/linear_algebra/mat.hpp index a2721188..75c4848a 100644 --- a/include/omath/linear_algebra/mat.hpp +++ b/include/omath/linear_algebra/mat.hpp @@ -39,6 +39,7 @@ namespace omath class Mat final { public: + using ContainedType = Type; constexpr Mat() noexcept { clear(); diff --git a/include/omath/linear_algebra/vector2.hpp b/include/omath/linear_algebra/vector2.hpp index 2994144a..7f161736 100644 --- a/include/omath/linear_algebra/vector2.hpp +++ b/include/omath/linear_algebra/vector2.hpp @@ -221,7 +221,7 @@ namespace omath } #ifdef OMATH_IMGUI_INTEGRATION [[nodiscard]] - ImVec2 to_im_vec2() const noexcept + constexpr ImVec2 to_im_vec2() const noexcept { return {static_cast(this->x), static_cast(this->y)}; } diff --git a/include/omath/linear_algebra/vector4.hpp b/include/omath/linear_algebra/vector4.hpp index 25d6a6de..48b02785 100644 --- a/include/omath/linear_algebra/vector4.hpp +++ b/include/omath/linear_algebra/vector4.hpp @@ -184,7 +184,7 @@ namespace omath #ifdef OMATH_IMGUI_INTEGRATION [[nodiscard]] - ImVec4 to_im_vec4() const noexcept + constexpr ImVec4 to_im_vec4() const noexcept { return { static_cast(this->x), diff --git a/source/utility/pe_pattern_scan.cpp b/source/utility/pe_pattern_scan.cpp index 86259595..931f241b 100644 --- a/source/utility/pe_pattern_scan.cpp +++ b/source/utility/pe_pattern_scan.cpp @@ -233,7 +233,8 @@ namespace constexpr bool invalid_nt_header_file(const NtHeaderVariant& variant) { constexpr std::uint32_t nt_hdr_magic = 0x4550; - return std::visit([](const auto& header) -> bool { return header.signature != nt_hdr_magic; }, variant); + return std::visit([&nt_hdr_magic](const auto& header) -> bool { return header.signature != nt_hdr_magic; }, + variant); } struct ExtractedSection diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5d932572..67de285b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,5 +15,11 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON) -target_link_libraries(${PROJECT_NAME} PRIVATE gtest gtest_main omath::omath) + +if (TARGET gtest) + target_link_libraries(${PROJECT_NAME} PRIVATE gtest gtest_main omath::omath) +else() + find_package(GTest CONFIG REQUIRED) + target_link_libraries(${PROJECT_NAME} PRIVATE GTest::gtest GTest::gtest_main omath::omath) +endif() gtest_discover_tests(${PROJECT_NAME}) \ No newline at end of file diff --git a/tests/general/unit_test_imgui_intergration.cpp b/tests/general/unit_test_imgui_intergration.cpp new file mode 100644 index 00000000..0e6ddea1 --- /dev/null +++ b/tests/general/unit_test_imgui_intergration.cpp @@ -0,0 +1,39 @@ +// +// Created by Vlad on 10/23/2025. +// +#ifdef OMATH_IMGUI_INTEGRATION +#include +#include + +#define IMGUI_DEFINE_MATH_OPERATORS +#include + + + +using namespace omath; + +TEST(unit_test_imgui_intergration, Vector2ToImVec2) +{ + constexpr Vector2 omath_vector_2d = {1.f, 2.f}; + constexpr ImVec2 imgui_vector_2d = {1, 2.f}; + + constexpr auto converted = omath_vector_2d.to_im_vec2(); + EXPECT_NEAR(converted.x, imgui_vector_2d.x, 1.e-5f); + EXPECT_NEAR(converted.y, imgui_vector_2d.y, 1.e-5f); +} + +TEST(unit_test_imgui_intergration, Vector4ToImVec4) +{ + constexpr Vector4 omath_vector_2d = {1.f, 2.f, 3.f, 4.f}; + constexpr ImVec4 imgui_vector_4d = {1, 2.f, 3.f, 4.f}; + + constexpr auto converted = omath_vector_2d.to_im_vec4(); + + EXPECT_NEAR(converted.x, imgui_vector_4d.x, 1.e-5f); + EXPECT_NEAR(converted.y, imgui_vector_4d.y, 1.e-5f); + EXPECT_NEAR(converted.z, imgui_vector_4d.z, 1.e-5f); + EXPECT_NEAR(converted.w, imgui_vector_4d.w, 1.e-5f); +} + + +#endif diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json new file mode 100644 index 00000000..f14bf6ba --- /dev/null +++ b/vcpkg-configuration.json @@ -0,0 +1,14 @@ +{ + "default-registry": { + "kind": "git", + "baseline": "b1b19307e2d2ec1eefbdb7ea069de7d4bcd31f01", + "repository": "https://github.com/microsoft/vcpkg" + }, + "registries": [ + { + "kind": "artifact", + "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", + "name": "microsoft" + } + ] +} diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 00000000..3358a09a --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,42 @@ +{ + "name": "omath", + "version": "3.10.1", + "description": "General purpose math library", + "homepage": "https://github.com/orange-cpp/omath", + "license": "Zlib", + "supports": "windows | linux", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ], + "features": { + "avx2": { + "description": "Omath will use AVX2 to boost performance", + "supports": "!arm" + }, + "benchmark": { + "description": "Build benchmarks", + "dependencies": [ + "benchmark" + ] + }, + "imgui": { + "description": "Omath will define method to convert omath types to imgui types", + "dependencies": [ + "imgui" + ] + }, + "tests": { + "description": "Build unit-tests using GTest", + "dependencies": [ + "gtest" + ] + } + } +}