CMake improvements (#201)
- Update CMake to parity with Box2D. Removed BOX3D_AVX2 due to runtime dispatch. - CI fixes for ubuntu - Doxygen refresh from Box2D
This commit is contained in:
parent
efca0c184d
commit
f36d061ba2
21 changed files with 724 additions and 251 deletions
|
|
@ -121,8 +121,6 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
|
|||
|
||||
add_library(box3d ${BOX3D_SOURCE_FILES} ${BOX3D_INCLUDE_FILES})
|
||||
|
||||
# target_link_libraries(box3d PRIVATE eastl)
|
||||
|
||||
target_include_directories(box3d
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
|
||||
|
|
@ -150,13 +148,13 @@ endif()
|
|||
|
||||
if (BOX3D_PROFILE)
|
||||
target_compile_definitions(box3d PRIVATE BOX3D_PROFILE)
|
||||
set(TRACY_DELAYED_INIT ON CACHE BOOL "Enable delayed init for Tracy" FORCE)
|
||||
set(TRACY_MANUAL_LIFETIME ON CACHE BOOL "Enable manual lifetime for Tracy" FORCE)
|
||||
set(TRACY_ENABLE ON CACHE BOOL "Enable profiling" FORCE)
|
||||
set(TRACY_MANUAL_LIFETIME ON CACHE BOOL "Enable manual lifetime for Tracy" FORCE)
|
||||
|
||||
FetchContent_Declare(
|
||||
tracy
|
||||
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
|
||||
GIT_TAG v0.13.1
|
||||
GIT_TAG v0.14.1
|
||||
GIT_SHALLOW TRUE
|
||||
GIT_PROGRESS TRUE
|
||||
)
|
||||
|
|
@ -171,15 +169,8 @@ if(BOX3D_VALIDATE)
|
|||
target_compile_definitions(box3d PRIVATE BOX3D_VALIDATE)
|
||||
endif()
|
||||
|
||||
if (BOX3D_DISABLE_SIMD)
|
||||
message(STATUS "Box3D SIMD disabled")
|
||||
target_compile_definitions(box3d PRIVATE BOX3D_DISABLE_SIMD)
|
||||
endif()
|
||||
|
||||
if (NOT BOX3D_AVX2)
|
||||
message(STATUS "Box3D AVX2 disabled")
|
||||
target_compile_definitions(box3d PRIVATE BOX3D_DISABLE_AVX2)
|
||||
endif()
|
||||
target_compile_definitions(box3d PRIVATE ${BOX3D_SIMD_DEFINITIONS})
|
||||
target_compile_options(box3d PRIVATE ${BOX3D_SIMD_OPTIONS})
|
||||
|
||||
if (BOX3D_DOUBLE_PRECISION)
|
||||
message(STATUS "Box3D double precision ON")
|
||||
|
|
@ -200,39 +191,38 @@ if (MSVC)
|
|||
# Visual Studio won't load the natvis unless it is in the project
|
||||
target_sources(box3d PRIVATE box3d.natvis)
|
||||
|
||||
# Warnings Wall is problematic in mixed C/C++, so using W4
|
||||
target_compile_options(box3d PRIVATE /W4)
|
||||
# target_compile_options(box3d PRIVATE /wd4820 /wd5045 /wd4061 /wd4711 /wd4514 /wd4365 /wd5219 /wd5039)
|
||||
target_compile_options(box3d PRIVATE /wd4820 /wd5045 /wd4061 /wd4711)
|
||||
# 4710 - warn about inline functions that are not inlined
|
||||
target_compile_options(box3d PRIVATE /wd4710 )
|
||||
|
||||
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||
target_compile_options(box3d PRIVATE -Wmissing-prototypes)
|
||||
if (CMAKE_GENERATOR MATCHES "Visual Studio")
|
||||
target_compile_options(box3d PRIVATE /MP)
|
||||
endif()
|
||||
|
||||
if (BOX3D_AVX2 AND NOT CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "^(x64|X86)$")
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
# clang-cl: /Wall maps to -Weverything which is far too aggressive
|
||||
target_compile_options(box3d PRIVATE /W4 -Wmissing-prototypes)
|
||||
else()
|
||||
# All Warnings with some disabled
|
||||
# 4820 - padding between members
|
||||
# 5045 - Spectre mitigation
|
||||
# 4061 - not handling all cases for an enum in a switch block
|
||||
# 4711 - function inlined without being marked for inline
|
||||
# 4710 - inline functions that are not inlined
|
||||
target_compile_options(box3d PRIVATE /Wall /wd4820 /wd5045 /wd4061 /wd4711 /wd4710)
|
||||
endif()
|
||||
|
||||
if (NOT BOX3D_DISABLE_SIMD AND NOT CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "^(x64|X86)$")
|
||||
set_source_files_properties(wide8.c PROPERTIES COMPILE_OPTIONS "/arch:AVX2")
|
||||
endif()
|
||||
|
||||
elseif (MINGW)
|
||||
message(STATUS "Box3D on MinGW")
|
||||
target_compile_options(box3d PRIVATE -Wmissing-prototypes -Wall -Wextra -pedantic -Wno-unused-value)
|
||||
elseif (APPLE)
|
||||
message(STATUS "Box3D on Apple")
|
||||
target_compile_options(box3d PRIVATE -Wmissing-prototypes -Wall -Wextra -pedantic)
|
||||
target_compile_options(box3d PRIVATE -Wmissing-prototypes -Wall -Wextra -pedantic -Wno-unused-value)
|
||||
elseif (EMSCRIPTEN)
|
||||
message(STATUS "Box3D on Emscripten")
|
||||
# SSE2/wasm SIMD flags are set directory-wide in the top-level CMakeLists so the
|
||||
# tests, which include simd.h, get them too.
|
||||
elseif (UNIX)
|
||||
message(STATUS "Box3D using Unix")
|
||||
target_compile_options(box3d PRIVATE -Wmissing-prototypes -Wall -Wextra -pedantic -Wno-unused-value)
|
||||
if ("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
|
||||
# raspberry pi
|
||||
# -mfpu=neon
|
||||
# target_compile_options(box3d PRIVATE)
|
||||
else()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "src" FILES ${BOX3D_SOURCE_FILES})
|
||||
|
|
@ -264,15 +254,69 @@ install(
|
|||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/box3d
|
||||
)
|
||||
|
||||
export(
|
||||
EXPORT box3dConfig
|
||||
NAMESPACE box3d::
|
||||
FILE "${PROJECT_BINARY_DIR}/box3dConfig.cmake"
|
||||
)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/box3dConfigVersion.cmake"
|
||||
"${PROJECT_BINARY_DIR}/box3dConfigVersion.cmake"
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
|
||||
install(
|
||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/box3dConfigVersion.cmake"
|
||||
FILES "${PROJECT_BINARY_DIR}/box3dConfigVersion.cmake"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/box3d"
|
||||
)
|
||||
|
||||
# Anchor every path to the .pc file itself so the install tree can be relocated,
|
||||
# by cmake --install --prefix or by moving it afterwards
|
||||
file(RELATIVE_PATH PKGCONFIG_PREFIX_REL "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" "${CMAKE_INSTALL_PREFIX}")
|
||||
string(REGEX REPLACE "/$" "" PKGCONFIG_PREFIX_REL "${PKGCONFIG_PREFIX_REL}")
|
||||
file(RELATIVE_PATH PKGCONFIG_LIBDIR_REL "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_FULL_LIBDIR}")
|
||||
file(RELATIVE_PATH PKGCONFIG_INCLUDEDIR_REL "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
|
||||
|
||||
# The file has to carry every PUBLIC define the exported target carries, or consumers
|
||||
# compile against different headers than the library was built with. Keep in sync
|
||||
# with the defines above.
|
||||
set(PKGCONFIG_CFLAGS "")
|
||||
if (BOX3D_DOUBLE_PRECISION)
|
||||
string(APPEND PKGCONFIG_CFLAGS " -DBOX3D_DOUBLE_PRECISION")
|
||||
endif()
|
||||
if (WIN32 AND BUILD_SHARED_LIBS)
|
||||
# base.h keys the dllimport off _WIN32, so MinGW needs this as much as MSVC
|
||||
string(APPEND PKGCONFIG_CFLAGS " -DBOX3D_DLL")
|
||||
endif()
|
||||
string(APPEND PKGCONFIG_CFLAGS "$<$<CONFIG:RELWITHDEBINFO>: -DB3_ENABLE_ASSERT>")
|
||||
|
||||
set(PKGCONFIG_LIBNAME "box3d$<$<CONFIG:Debug>:${CMAKE_DEBUG_POSTFIX}>")
|
||||
|
||||
# Plain pkg-config --libs skips Libs.private, and Box3D builds static by default, so
|
||||
# public link deps belong on the main line unless we are actually building a shared lib
|
||||
set(PKGCONFIG_LIBS "")
|
||||
set(PKGCONFIG_LIBS_PRIVATE "")
|
||||
if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(PKGCONFIG_LIBS_PRIVATE "-lm")
|
||||
else()
|
||||
set(PKGCONFIG_LIBS " -lm")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
configure_file(box3d.pc.in box3d.pc.gen @ONLY)
|
||||
|
||||
# The library name and the assert define vary by config, so finish the substitution
|
||||
# per config instead of once at configure time
|
||||
file(GENERATE
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/$<CONFIG>/box3d.pc"
|
||||
INPUT "${CMAKE_CURRENT_BINARY_DIR}/box3d.pc.gen"
|
||||
)
|
||||
|
||||
install(
|
||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/$<CONFIG>/box3d.pc"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -892,6 +892,9 @@ b3BodyTOIResult b3Body_TimeOfImpactMover( b3BodyId bodyId, b3Pos origin, const b
|
|||
return result;
|
||||
}
|
||||
|
||||
// This computes the deviation of the principal inertia values without computing eigenvalues.
|
||||
// It computes:
|
||||
// ((I1 - I2)^2 + (I1 - I3)^2 + (I2 - I3)^2) / (I1^2 + I2^2 + I3^2)
|
||||
// https://en.wikipedia.org/wiki/Cauchy_stress_tensor#Stress_deviator_tensor
|
||||
static void b3UpdateIsotropicInertia( b3World* world, b3Body* body, b3BodySim* bodySim )
|
||||
{
|
||||
|
|
|
|||
11
src/box3d.pc.in
Normal file
11
src/box3d.pc.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
prefix=${pcfiledir}/@PKGCONFIG_PREFIX_REL@
|
||||
exec_prefix=${prefix}
|
||||
libdir=${prefix}/@PKGCONFIG_LIBDIR_REL@
|
||||
includedir=${prefix}/@PKGCONFIG_INCLUDEDIR_REL@
|
||||
|
||||
Name: @PROJECT_NAME@
|
||||
Description: @PROJECT_DESCRIPTION@
|
||||
Version: @PROJECT_VERSION@
|
||||
Libs: -L${libdir} -l@PKGCONFIG_LIBNAME@@PKGCONFIG_LIBS@
|
||||
Libs.private: @PKGCONFIG_LIBS_PRIVATE@
|
||||
Cflags: -I${includedir}@PKGCONFIG_CFLAGS@
|
||||
|
|
@ -1868,7 +1868,7 @@ static void b3RecComputeQueryBounds( b3RecDrawQuery* q )
|
|||
// Sweep each point across the translation. A non-cast query has zero translation, so both ends
|
||||
// coincide and the duplicates fold away.
|
||||
b3Pos end = b3OffsetPos( q->origin, q->translation );
|
||||
b3Vec3 world[2 * B3_MAX_SHAPE_CAST_POINTS];
|
||||
b3Vec3 world[2 * B3_MAX_SHAPE_CAST_POINTS] = { 0 };
|
||||
int n = 0;
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -395,7 +395,7 @@ float b3IntersectRayTriangle( b3V32 rayStart, b3V32 rayDelta, b3V32 vertex1, b3V
|
|||
|
||||
B3_FORCE_INLINE b3AABB b3UnionV( b3AABB a, b3AABB b )
|
||||
{
|
||||
b3AABB result;
|
||||
b3AABB result = { 0 };
|
||||
b3StoreAABBV( &result, b3UnionAABBV( b3LoadAABBV( &a ), b3LoadAABBV( &b ) ), true );
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,6 +106,8 @@ static void b3IntegrateVelocitiesTask( b3SolverBlock block, b3StepContext* conte
|
|||
// I * (w2 - w1) + h * cross(w2, I * w2) = 0
|
||||
// This is all done in local coordinates where the Jacobian is easier to compute.
|
||||
// This improves the simulation of long skinny bodies.
|
||||
// If the principal inertia values of I are roughly equal (isotropic) then
|
||||
// cross(w2, I * w2) ~= 0, so this can be skipped.
|
||||
if ( sim->flags & b3_enableGyroscopicTorque )
|
||||
{
|
||||
// Get current rotation.
|
||||
|
|
|
|||
19
src/timer.c
19
src/timer.c
|
|
@ -169,12 +169,27 @@ static void b3SetCurrentThreadName( const char* name )
|
|||
HMODULE kernel = GetModuleHandleW( L"kernel32.dll" );
|
||||
if ( kernel != NULL )
|
||||
{
|
||||
// MSVC /Wall warns C4191 on every FARPROC function-pointer cast.
|
||||
// This is the intended use of GetProcAddress, so suppress locally.
|
||||
// MSVC /Wall warns C4191 and GCC/Clang -Wcast-function-type
|
||||
// warns on every FARPROC function-pointer cast. This is the
|
||||
// intended use of GetProcAddress, so suppress locally.
|
||||
#if defined( __clang__ )
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wcast-function-type"
|
||||
#elif defined( _MSC_VER )
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4191 )
|
||||
#elif defined( __GNUC__ )
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-function-type"
|
||||
#endif
|
||||
pfn = (b3SetThreadDescriptionFn)GetProcAddress( kernel, "SetThreadDescription" );
|
||||
#if defined( __clang__ )
|
||||
#pragma clang diagnostic pop
|
||||
#elif defined( _MSC_VER )
|
||||
#pragma warning( pop )
|
||||
#elif defined( __GNUC__ )
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
}
|
||||
resolved = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -323,7 +323,7 @@ static void b3SerTree( b3RecBuffer* buf, const b3DynamicTree* tree )
|
|||
|
||||
static void b3DesTree( b3SnapReader* r, b3DynamicTree* tree )
|
||||
{
|
||||
uint64_t version;
|
||||
uint64_t version = 0;
|
||||
b3SnapR_Bytes( r, &version, sizeof( uint64_t ) );
|
||||
int nodeEnd = b3SnapR_I32( r );
|
||||
int pairFreeList = b3SnapR_I32( r );
|
||||
|
|
|
|||
Loading…
Reference in a new issue