From 8e411771c2dd0d5bb6cea786160da8f128cc57d9 Mon Sep 17 00:00:00 2001 From: Orange Date: Tue, 15 Jul 2025 11:48:27 +0300 Subject: [PATCH 1/2] Adds option to enable legacy classes Introduces a CMake option to enable legacy classes, allowing for backward compatibility with older code. This ensures that older codebases can still function while new development can utilize updated classes. --- CMakeLists.txt | 6 ++++++ include/omath/matrix.hpp | 4 ++++ source/matrix.cpp | 3 +++ 3 files changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d5891f..af67dd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,8 @@ 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" ON) +option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" OFF) + file(GLOB_RECURSE OMATH_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp") file(GLOB_RECURSE OMATH_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp") @@ -56,6 +58,10 @@ if (OMATH_SUPRESS_SAFETY_CHECKS) target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_SUPRESS_SAFETY_CHECKS) endif () +if (OMATH_ENABLE_LEGACY) + target_compile_options(${PROJECT_NAME} PUBLIC OMATH_ENABLE_LEGACY) +endif () + set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" diff --git a/include/omath/matrix.hpp b/include/omath/matrix.hpp index 1e2df87..a8dc520 100644 --- a/include/omath/matrix.hpp +++ b/include/omath/matrix.hpp @@ -1,4 +1,7 @@ #pragma once + +#ifdef OMATH_ENABLE_LEGACY + #include "omath/vector3.hpp" #include #include @@ -106,3 +109,4 @@ namespace omath std::unique_ptr m_data; }; } // namespace omath +#endif diff --git a/source/matrix.cpp b/source/matrix.cpp index 428aaa8..322ea96 100644 --- a/source/matrix.cpp +++ b/source/matrix.cpp @@ -1,3 +1,5 @@ +#ifdef OMATH_ENABLE_LEGACY + #include "omath/matrix.hpp" #include "omath/angles.hpp" #include "omath/vector3.hpp" @@ -359,3 +361,4 @@ namespace omath m_data = nullptr; } } // namespace omath +#endif From 1aa62cb39663e0bad936c3f1b9bf58c5e979c7b6 Mon Sep 17 00:00:00 2001 From: Orange Date: Tue, 15 Jul 2025 11:51:14 +0300 Subject: [PATCH 2/2] Enables legacy code compilation The changes encapsulate the matrix tests within an `#ifdef` block, allowing conditional compilation based on whether `OMATH_ENABLE_LEGACY` is defined. This enables the legacy code to be compiled only when needed. --- tests/general/unit_test_matrix.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/general/unit_test_matrix.cpp b/tests/general/unit_test_matrix.cpp index ec56cbc..b7543c6 100644 --- a/tests/general/unit_test_matrix.cpp +++ b/tests/general/unit_test_matrix.cpp @@ -1,6 +1,9 @@ // // Created by vlad on 5/18/2024. // + +#ifdef OMATH_ENABLE_LEGACY + #include #include #include "omath/vector3.hpp" @@ -177,4 +180,5 @@ TEST_F(UnitTestMatrix, AssignmentOperator_Move) EXPECT_FLOAT_EQ(m3.at(0, 0), 1.0f); EXPECT_EQ(m2.row_count(), 0); // m2 should be empty after the move EXPECT_EQ(m2.columns_count(), 0); -} \ No newline at end of file +} +#endif