mirror of
https://github.com/orange-cpp/omath.git
synced 2026-06-15 03:34:35 +00:00
added modules support
This commit is contained in:
@@ -34,6 +34,7 @@ option(OMATH_ENABLE_LUA
|
|||||||
"omath bindings for lua" OFF)
|
"omath bindings for lua" OFF)
|
||||||
option(OMATH_ENABLE_HOOKING "omath will HooksManager that can hook DirectX/OpenGL automatically" OFF)
|
option(OMATH_ENABLE_HOOKING "omath will HooksManager that can hook DirectX/OpenGL automatically" OFF)
|
||||||
option(OMATH_USE_GCEM "omath will use gcem library to make more functions/methods constexpr" OFF)
|
option(OMATH_USE_GCEM "omath will use gcem library to make more functions/methods constexpr" OFF)
|
||||||
|
option(OMATH_ENABLE_MODULES "Build omath C++ module interface" OFF)
|
||||||
|
|
||||||
if(VCPKG_MANIFEST_FEATURES)
|
if(VCPKG_MANIFEST_FEATURES)
|
||||||
foreach(omath_feature IN LISTS VCPKG_MANIFEST_FEATURES)
|
foreach(omath_feature IN LISTS VCPKG_MANIFEST_FEATURES)
|
||||||
@@ -84,6 +85,7 @@ if(${PROJECT_IS_TOP_LEVEL})
|
|||||||
message(STATUS "[${PROJECT_NAME}]: Valgrind feature status ${OMATH_ENABLE_VALGRIND}")
|
message(STATUS "[${PROJECT_NAME}]: Valgrind feature status ${OMATH_ENABLE_VALGRIND}")
|
||||||
message(STATUS "[${PROJECT_NAME}]: Lua feature status ${OMATH_ENABLE_LUA}")
|
message(STATUS "[${PROJECT_NAME}]: Lua feature status ${OMATH_ENABLE_LUA}")
|
||||||
message(STATUS "[${PROJECT_NAME}]: Gcem feature status ${OMATH_USE_GCEM}")
|
message(STATUS "[${PROJECT_NAME}]: Gcem feature status ${OMATH_USE_GCEM}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: Modules feature status ${OMATH_ENABLE_MODULES}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(OMATH_STATIC_MSVC_RUNTIME_LIBRARY)
|
if(OMATH_STATIC_MSVC_RUNTIME_LIBRARY)
|
||||||
@@ -99,6 +101,20 @@ else()
|
|||||||
add_library(${PROJECT_NAME} STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
|
add_library(${PROJECT_NAME} STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(OMATH_ENABLE_MODULES)
|
||||||
|
if(CMAKE_VERSION VERSION_LESS 3.28)
|
||||||
|
message(FATAL_ERROR "OMATH_ENABLE_MODULES requires CMake 3.28 or newer")
|
||||||
|
endif()
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_SCAN_FOR_MODULES ON)
|
||||||
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||||
|
target_compile_options(${PROJECT_NAME} PRIVATE /wd5244)
|
||||||
|
endif()
|
||||||
|
target_sources(
|
||||||
|
${PROJECT_NAME}
|
||||||
|
PUBLIC FILE_SET omath_modules TYPE CXX_MODULES BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/modules"
|
||||||
|
FILES "${CMAKE_CURRENT_SOURCE_DIR}/modules/omath.cppm")
|
||||||
|
endif()
|
||||||
|
|
||||||
if (OMATH_ENABLE_LUA)
|
if (OMATH_ENABLE_LUA)
|
||||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_ENABLE_LUA)
|
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_ENABLE_LUA)
|
||||||
|
|
||||||
@@ -239,6 +255,10 @@ target_include_directories(
|
|||||||
|
|
||||||
# Installation rules
|
# Installation rules
|
||||||
|
|
||||||
|
if(OMATH_ENABLE_MODULES)
|
||||||
|
set(OMATH_MODULE_FILE_SET FILE_SET omath_modules DESTINATION modules)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Install the library
|
# Install the library
|
||||||
install(
|
install(
|
||||||
TARGETS ${PROJECT_NAME}
|
TARGETS ${PROJECT_NAME}
|
||||||
@@ -247,6 +267,7 @@ install(
|
|||||||
LIBRARY DESTINATION lib COMPONENT ${PROJECT_NAME} # For shared libraries
|
LIBRARY DESTINATION lib COMPONENT ${PROJECT_NAME} # For shared libraries
|
||||||
RUNTIME DESTINATION bin COMPONENT ${PROJECT_NAME} # For executables (on
|
RUNTIME DESTINATION bin COMPONENT ${PROJECT_NAME} # For executables (on
|
||||||
# Windows)
|
# Windows)
|
||||||
|
${OMATH_MODULE_FILE_SET}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Install headers as part of omath_component
|
# Install headers as part of omath_component
|
||||||
|
|||||||
@@ -588,13 +588,13 @@ namespace omath
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR> [[nodiscard("You must use row matrix")]]
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR> [[nodiscard("You must use row matrix")]]
|
||||||
constexpr static Mat<1, 4, Type, St> mat_row_from_vector(const Vector3<Type>& vector) noexcept
|
constexpr Mat<1, 4, Type, St> mat_row_from_vector(const Vector3<Type>& vector) noexcept
|
||||||
{
|
{
|
||||||
return {{vector.x, vector.y, vector.z, 1}};
|
return {{vector.x, vector.y, vector.z, 1}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR> [[nodiscard("You must use column matrix")]]
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR> [[nodiscard("You must use column matrix")]]
|
||||||
constexpr static Mat<4, 1, Type, St> mat_column_from_vector(const Vector3<Type>& vector) noexcept
|
constexpr Mat<4, 1, Type, St> mat_column_from_vector(const Vector3<Type>& vector) noexcept
|
||||||
{
|
{
|
||||||
return {{vector.x}, {vector.y}, {vector.z}, {1}};
|
return {{vector.x}, {vector.y}, {vector.z}, {1}};
|
||||||
}
|
}
|
||||||
@@ -711,7 +711,7 @@ namespace omath
|
|||||||
|
|
||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
|
||||||
[[nodiscard("You must use camera view matrix")]]
|
[[nodiscard("You must use camera view matrix")]]
|
||||||
OMATH_CONSTEXPR static Mat<4, 4, Type, St> mat_camera_view(const Vector3<Type>& forward, const Vector3<Type>& right,
|
OMATH_CONSTEXPR Mat<4, 4, Type, St> mat_camera_view(const Vector3<Type>& forward, const Vector3<Type>& right,
|
||||||
const Vector3<Type>& up, const Vector3<Type>& camera_origin) noexcept
|
const Vector3<Type>& up, const Vector3<Type>& camera_origin) noexcept
|
||||||
{
|
{
|
||||||
return Mat<4, 4, Type, St>
|
return Mat<4, 4, Type, St>
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
module;
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
#include <cassert>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <expected>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <format>
|
||||||
|
#include <functional>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <initializer_list>
|
||||||
|
#include <iterator>
|
||||||
|
#include <limits>
|
||||||
|
#include <memory>
|
||||||
|
#include <memory_resource>
|
||||||
|
#include <numbers>
|
||||||
|
#include <numeric>
|
||||||
|
#include <optional>
|
||||||
|
#include <queue>
|
||||||
|
#include <ranges>
|
||||||
|
#include <span>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <tuple>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <utility>
|
||||||
|
#include <variant>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#if defined(OMATH_USE_AVX2)
|
||||||
|
#include <immintrin.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(OMATH_USE_GCEM)
|
||||||
|
#include <gcem.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(OMATH_IMGUI_INTEGRATION)
|
||||||
|
#include <imgui.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#ifndef NOMINMAX
|
||||||
|
#define NOMINMAX
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#include <mach-o/dyld.h>
|
||||||
|
#elif defined(__linux__) || defined(__unix__)
|
||||||
|
#include <link.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
export module omath;
|
||||||
|
|
||||||
|
export
|
||||||
|
{
|
||||||
|
#include "omath/omath.hpp"
|
||||||
|
}
|
||||||
@@ -7,6 +7,11 @@ include(GoogleTest)
|
|||||||
file(GLOB_RECURSE UNIT_TESTS_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/general/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/engines/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
|
file(GLOB_RECURSE UNIT_TESTS_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/general/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/engines/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
|
||||||
add_executable(${PROJECT_NAME} ${UNIT_TESTS_SOURCES} main.cpp)
|
add_executable(${PROJECT_NAME} ${UNIT_TESTS_SOURCES} main.cpp)
|
||||||
|
|
||||||
|
if(OMATH_ENABLE_MODULES)
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_SCAN_FOR_MODULES ON)
|
||||||
|
target_sources(${PROJECT_NAME} PRIVATE modules/unit_test_module.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
${PROJECT_NAME}
|
${PROJECT_NAME}
|
||||||
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
import omath;
|
||||||
|
|
||||||
|
TEST(UnitTestModule, ImportOmath)
|
||||||
|
{
|
||||||
|
const omath::Vector2<float> vec{1.f, 2.f};
|
||||||
|
|
||||||
|
EXPECT_FLOAT_EQ(vec.x, 1.f);
|
||||||
|
EXPECT_FLOAT_EQ(vec.y, 2.f);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user