diff --git a/CMakeLists.txt b/CMakeLists.txt index 35b98c8..4ace624 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 3.20) + +include(CMakeDependentOption) include(cmake/build_type.cmake) include(cmake/c_compiler.cmake) +include(cmake/volt_options.cmake) include(cmake/cxx_compiler.cmake) include(cmake/c_compiler_options.cmake) include(cmake/cxx_compiler_options.cmake) @@ -19,6 +22,7 @@ set(CMAKE_PROJECT_VERSION 0.2-alpha) volt_set_c_compiler_options() volt_set_cxx_compiler_options() +volt_set_options() message(STATUS "The requested build target is ${CMAKE_SYSTEM}") diff --git a/cmake/volt_options.cmake b/cmake/volt_options.cmake new file mode 100644 index 0000000..22a4b65 --- /dev/null +++ b/cmake/volt_options.cmake @@ -0,0 +1,21 @@ +function (volt_set_options) + option(VOLT_USE_SIMD "Enable SIMD math" ON) + if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") + cmake_dependent_option(VOLT_USE_AVX2 "Enable AVX2 instruction set" ON "VOLT_USE_SIMD" OFF) + endif() + + # Check VOLT_USE_SIMD value is valid + if (NOT VOLT_USE_SIMD STREQUAL "ON" AND NOT VOLT_USE_SIMD STREQUAL "OFF") + message(WARNING "VOLT_USE_SIMD is set to an invalid value (${VOLT_USE_SIMD}), defaulting to ON") + set(VOLT_USE_SIMD ON CACHE STRING "Enable SIMD math" FORCE) + endif() + + # Check VOLT_USE_AVX2 value is valid + if (NOT VOLT_USE_AVX2 STREQUAL "ON" AND NOT VOLT_USE_AVX2 STREQUAL "OFF") + message(WARNING "VOLT_USE_AVX2 is set to an invalid value (${VOLT_USE_AVX2}), defaulting to ON") + set(VOLT_USE_AVX2 ON CACHE STRING "Enable AVX2 instruction set" FORCE) + endif() + + message(STATUS "Use SIMD: ${VOLT_USE_SIMD}") + message(STATUS "Use AVX2: ${VOLT_USE_AVX2}") +endfunction() diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index b14329b..1b75368 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -1,10 +1,12 @@ file(GLOB IMGUI_SRCS CONFIGURE_DEPENDS "imgui/*.cpp") +file(GLOB BOX2D_SRCS CONFIGURE_DEPENDS "box2d/src/*.c") file(GLOB RAYLIB_SRCS CONFIGURE_DEPENDS "raylib/src/*.c") file(GLOB IMGUIZMO_SRCS CONFIGURE_DEPENDS "imguizmo/*.cpp") file(GLOB_RECURSE YAML_CPP_SRCS CONFIGURE_DEPENDS "yaml-cpp/src/*.cpp") file(GLOB IMGUI_IMPL_RAYLIB_SRCS CONFIGURE_DEPENDS "imgui_impl_raylib/*.cpp") add_library(imgui OBJECT ${IMGUI_SRCS}) +add_library(box2d OBJECT ${BOX2D_SRCS}) add_library(raylib OBJECT ${RAYLIB_SRCS}) add_library(imguizmo OBJECT ${IMGUIZMO_SRCS}) add_library(yaml_cpp OBJECT ${YAML_CPP_SRCS}) @@ -12,12 +14,27 @@ add_library(imgui_impl_raylib OBJECT ${IMGUI_IMPL_RAYLIB_SRCS}) target_compile_definitions(raylib PRIVATE PLATFORM_DESKTOP) target_compile_definitions(yaml_cpp PRIVATE YAML_CPP_STATIC_DEFINE) +if (VOLT_USE_SIMD) + target_compile_definitions(box2d PRIVATE BOX2D_ENABLE_SIMD) +endif() target_include_directories(imguizmo SYSTEM PUBLIC imgui) +target_include_directories(box2d SYSTEM PUBLIC box2d/include) target_include_directories(imgui_impl_raylib SYSTEM PUBLIC imgui) +target_include_directories(box2d SYSTEM PUBLIC box2d/extern/simde) target_include_directories(yaml_cpp SYSTEM PUBLIC yaml-cpp/include) target_include_directories(imgui_impl_raylib SYSTEM PUBLIC raylib/src) target_include_directories(raylib SYSTEM PUBLIC raylib/src/external/glfw/include) target_compile_options(raylib PRIVATE "-w") +target_compile_options(box2d PRIVATE "-ffp-contract=off") target_compile_options(raylib PRIVATE "-Wno-implicit-function-declaration") + +if (VOLT_USE_AVX2) + target_compile_definitions(box2d PRIVATE BOX2D_AVX2) + if (MSVC) + target_compile_options(box2d PRIVATE "/arch:AVX2") + else() + target_compile_options(box2d PRIVATE "-mavx2") + endif() +endif()