diff --git a/CMakeLists.txt b/CMakeLists.txt index 8da5a63..14f03a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ option(OMATH_ENABLE_LUA "omath bindings for lua" 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_ENABLE_MODULES "Build omath C++ module interface" OFF) if(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}]: Lua feature status ${OMATH_ENABLE_LUA}") message(STATUS "[${PROJECT_NAME}]: Gcem feature status ${OMATH_USE_GCEM}") + message(STATUS "[${PROJECT_NAME}]: Modules feature status ${OMATH_ENABLE_MODULES}") endif() if(OMATH_STATIC_MSVC_RUNTIME_LIBRARY) @@ -99,6 +101,20 @@ else() add_library(${PROJECT_NAME} STATIC ${OMATH_SOURCES} ${OMATH_HEADERS}) 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) target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_ENABLE_LUA) @@ -239,6 +255,10 @@ target_include_directories( # Installation rules +if(OMATH_ENABLE_MODULES) + set(OMATH_MODULE_FILE_SET FILE_SET omath_modules DESTINATION modules) +endif() + # Install the library install( TARGETS ${PROJECT_NAME} @@ -247,6 +267,7 @@ install( LIBRARY DESTINATION lib COMPONENT ${PROJECT_NAME} # For shared libraries RUNTIME DESTINATION bin COMPONENT ${PROJECT_NAME} # For executables (on # Windows) + ${OMATH_MODULE_FILE_SET} ) # Install headers as part of omath_component diff --git a/include/omath/linear_algebra/mat.hpp b/include/omath/linear_algebra/mat.hpp index 231d215..17f501f 100644 --- a/include/omath/linear_algebra/mat.hpp +++ b/include/omath/linear_algebra/mat.hpp @@ -588,13 +588,13 @@ namespace omath }; template [[nodiscard("You must use row matrix")]] - constexpr static Mat<1, 4, Type, St> mat_row_from_vector(const Vector3& vector) noexcept + constexpr Mat<1, 4, Type, St> mat_row_from_vector(const Vector3& vector) noexcept { return {{vector.x, vector.y, vector.z, 1}}; } template [[nodiscard("You must use column matrix")]] - constexpr static Mat<4, 1, Type, St> mat_column_from_vector(const Vector3& vector) noexcept + constexpr Mat<4, 1, Type, St> mat_column_from_vector(const Vector3& vector) noexcept { return {{vector.x}, {vector.y}, {vector.z}, {1}}; } @@ -711,7 +711,7 @@ namespace omath template [[nodiscard("You must use camera view matrix")]] - OMATH_CONSTEXPR static Mat<4, 4, Type, St> mat_camera_view(const Vector3& forward, const Vector3& right, + OMATH_CONSTEXPR Mat<4, 4, Type, St> mat_camera_view(const Vector3& forward, const Vector3& right, const Vector3& up, const Vector3& camera_origin) noexcept { return Mat<4, 4, Type, St> diff --git a/modules/omath.cppm b/modules/omath.cppm new file mode 100644 index 0000000..f879c84 --- /dev/null +++ b/modules/omath.cppm @@ -0,0 +1,64 @@ +module; + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(OMATH_USE_AVX2) +#include +#endif + +#if defined(OMATH_USE_GCEM) +#include +#endif + +#if defined(OMATH_IMGUI_INTEGRATION) +#include +#endif + +#if defined(_WIN32) +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include +#elif defined(__APPLE__) +#include +#elif defined(__linux__) || defined(__unix__) +#include +#endif + +export module omath; + +export +{ +#include "omath/omath.hpp" +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 824b6e9..d3d00b9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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") 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( ${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" diff --git a/tests/modules/unit_test_module.cpp b/tests/modules/unit_test_module.cpp new file mode 100644 index 0000000..e174663 --- /dev/null +++ b/tests/modules/unit_test_module.cpp @@ -0,0 +1,11 @@ +#include + +import omath; + +TEST(UnitTestModule, ImportOmath) +{ + const omath::Vector2 vec{1.f, 2.f}; + + EXPECT_FLOAT_EQ(vec.x, 1.f); + EXPECT_FLOAT_EQ(vec.y, 2.f); +}