improved cmake, removed useless cmake files

This commit is contained in:
2025-04-30 21:26:25 +03:00
parent faeef594b9
commit 998c8f3a43
14 changed files with 30 additions and 74 deletions

View File

@@ -11,15 +11,19 @@ option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON) option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
option(OMATH_IMGUI_INTEGRATION "Omath will define method to convert omath types to imgui types" OFF) option(OMATH_IMGUI_INTEGRATION "Omath will define method to convert omath types to imgui types" OFF)
option(OMATH_BUILD_EXAMPLES "Build example projects with you can learn & play" OFF) option(OMATH_BUILD_EXAMPLES "Build example projects with you can learn & play" OFF)
option(OMATH_STATIC_MSVC_RUNTIME_LIBRARY "Force Omath to link static runtime" OFF) 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_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_USE_UNITY_BUILD "Will enable unity build to speed up compilation" ON)
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")
if (OMATH_BUILD_AS_SHARED_LIBRARY) if (OMATH_BUILD_AS_SHARED_LIBRARY)
add_library(omath SHARED source/matrix.cpp) add_library(omath SHARED ${OMATH_SOURCES} ${OMATH_HEADERS})
else() else ()
add_library(omath STATIC source/matrix.cpp) add_library(omath STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
endif() endif ()
message(STATUS "Building on ${CMAKE_HOST_SYSTEM_NAME}") message(STATUS "Building on ${CMAKE_HOST_SYSTEM_NAME}")
add_library(omath::omath ALIAS omath) add_library(omath::omath ALIAS omath)
@@ -28,28 +32,28 @@ if (OMATH_IMGUI_INTEGRATION)
target_compile_definitions(omath PUBLIC OMATH_IMGUI_INTEGRATION) target_compile_definitions(omath PUBLIC OMATH_IMGUI_INTEGRATION)
# IMGUI is being linked as submodule # IMGUI is being linked as submodule
if(TARGET imgui) if (TARGET imgui)
target_link_libraries(omath PUBLIC imgui) target_link_libraries(omath PUBLIC imgui)
install(TARGETS imgui install(TARGETS imgui
EXPORT omathTargets EXPORT omathTargets
ARCHIVE DESTINATION lib ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib LIBRARY DESTINATION lib
RUNTIME DESTINATION bin) RUNTIME DESTINATION bin)
else() else ()
# Assume that IMGUI linked via VCPKG. # Assume that IMGUI linked via VCPKG.
find_package(imgui CONFIG REQUIRED) find_package(imgui CONFIG REQUIRED)
target_link_libraries(omath PUBLIC imgui::imgui) target_link_libraries(omath PUBLIC imgui::imgui)
endif() endif ()
endif() endif ()
if (OMATH_USE_AVX2) if (OMATH_USE_AVX2)
target_compile_definitions(omath PUBLIC OMATH_USE_AVX2) target_compile_definitions(omath PUBLIC OMATH_USE_AVX2)
endif() endif ()
if (OMATH_SUPRESS_SAFETY_CHECKS) if (OMATH_SUPRESS_SAFETY_CHECKS)
target_compile_definitions(omath PUBLIC OMATH_SUPRESS_SAFETY_CHECKS) target_compile_definitions(omath PUBLIC OMATH_SUPRESS_SAFETY_CHECKS)
endif() endif ()
set_target_properties(omath PROPERTIES set_target_properties(omath PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
@@ -61,37 +65,35 @@ if (OMATH_USE_UNITY_BUILD)
set_target_properties(omath PROPERTIES set_target_properties(omath PROPERTIES
UNITY_BUILD ON UNITY_BUILD ON
UNITY_BUILD_BATCH_SIZE 20) UNITY_BUILD_BATCH_SIZE 20)
endif() endif ()
if (OMATH_STATIC_MSVC_RUNTIME_LIBRARY) if (OMATH_STATIC_MSVC_RUNTIME_LIBRARY)
set_target_properties(omath PROPERTIES set_target_properties(omath PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
) )
endif() endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(omath PRIVATE -mavx2 -mfma) target_compile_options(omath PRIVATE -mavx2 -mfma)
endif() endif ()
target_compile_features(omath PUBLIC cxx_std_23) target_compile_features(omath PUBLIC cxx_std_23)
add_subdirectory(source) if (OMATH_BUILD_TESTS)
if(OMATH_BUILD_TESTS)
add_subdirectory(extlibs) add_subdirectory(extlibs)
add_subdirectory(tests) add_subdirectory(tests)
endif() endif ()
if (OMATH_BUILD_EXAMPLES) if (OMATH_BUILD_EXAMPLES)
add_subdirectory(examples) add_subdirectory(examples)
endif() endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND OMATH_THREAT_WARNING_AS_ERROR) if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND OMATH_THREAT_WARNING_AS_ERROR)
target_compile_options(omath PRIVATE /W4 /WX) target_compile_options(omath PRIVATE /W4 /WX)
elseif(OMATH_THREAT_WARNING_AS_ERROR) elseif (OMATH_THREAT_WARNING_AS_ERROR)
target_compile_options(omath PRIVATE -Wall -Wextra -Wpedantic -Werror) target_compile_options(omath PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif() endif ()
target_include_directories(omath target_include_directories(omath
PUBLIC PUBLIC

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE box.cpp)

View File

@@ -1,11 +0,0 @@
target_sources(omath PRIVATE
matrix.cpp
color.cpp
)
add_subdirectory(projectile_prediction)
add_subdirectory(pathfinding)
add_subdirectory(projection)
add_subdirectory(collision)
add_subdirectory(engines)
add_subdirectory(3d_primitives)

View File

@@ -1,3 +0,0 @@
target_sources(omath PRIVATE
line_tracer.cpp
)

View File

@@ -1,4 +0,0 @@
add_subdirectory(source_engine)
add_subdirectory(opengl_engine)
add_subdirectory(iw_engine)
add_subdirectory(unity_engine)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE camera.cpp formulas.cpp)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE camera.cpp formulas.cpp)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE camera.cpp formulas.cpp)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE formulas.cpp camera.cpp)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE navigation_mesh.cpp a_star.cpp)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE proj_pred_engine_legacy.cpp projectile.cpp target.cpp proj_pred_engine_avx2.cpp proj_pred_engine.cpp)

View File

@@ -1 +0,0 @@
target_sources(omath PRIVATE camera.cpp)

View File

@@ -1,33 +1,13 @@
enable_testing() enable_testing()
project(unit-tests) project(unit_tests)
include(GoogleTest) include(GoogleTest)
add_executable(unit-tests
general/unit_test_prediction.cpp
general/unit_test_matrix.cpp
general/unit_test_mat.cpp
general/unit_test_a_star.cpp
general/unit_test_projection.cpp
general/unit_test_vector3.cpp
general/unit_test_vector2.cpp
general/unit_test_color.cpp
general/unit_test_vector4.cpp
general/unit_test_line_trace.cpp
general/unit_test_angles.cpp
general/unit_test_view_angles.cpp
general/unit_test_angle.cpp
general/unit_test_triangle.cpp
general/unit_test_box_primitive.cpp
engines/unit_test_open_gl.cpp file(GLOB_RECURSE UNIT_TESTS_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
engines/unit_test_unity_engine.cpp add_executable(unit_tests ${UNIT_TESTS_SOURCES})
engines/unit_test_source_engine.cpp
engines/unit_test_iw_engine.cpp
) set_target_properties(unit_tests PROPERTIES
set_target_properties(unit-tests PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
UNITY_BUILD ON UNITY_BUILD ON
@@ -36,6 +16,6 @@ set_target_properties(unit-tests PROPERTIES
CXX_STANDARD_REQUIRED ON) CXX_STANDARD_REQUIRED ON)
target_link_libraries(unit-tests PRIVATE gtest gtest_main omath::omath) target_link_libraries(unit_tests PRIVATE gtest gtest_main omath::omath)
gtest_discover_tests(unit-tests) gtest_discover_tests(unit_tests)

View File

@@ -5,7 +5,7 @@
#include <omath/engines/unity_engine/camera.hpp> #include <omath/engines/unity_engine/camera.hpp>
#include <omath/engines/unity_engine/constants.hpp> #include <omath/engines/unity_engine/constants.hpp>
#include <omath/engines/unity_engine/formulas.hpp> #include <omath/engines/unity_engine/formulas.hpp>
#include <print>
TEST(UnitTestUnityEngine, ForwardVector) TEST(UnitTestUnityEngine, ForwardVector)
{ {