Skip to content

Commit

Permalink
Integrated Box2D with build system
Browse files Browse the repository at this point in the history
We introduced 2 custom CMake options:
- `VOLT_USE_SIMD` :: Enable SIMD math
- `VOLT_USE_AVX2` :: Enable AVX2 instruction set
  • Loading branch information
iWas-Coder committed Sep 23, 2024
1 parent f0f5ebf commit 0caefa8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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}")

Expand Down
21 changes: 21 additions & 0 deletions cmake/volt_options.cmake
Original file line number Diff line number Diff line change
@@ -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()
17 changes: 17 additions & 0 deletions vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
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})
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()

0 comments on commit 0caefa8

Please sign in to comment.