diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8735e84..7c0effe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,22 +22,22 @@ jobs: uses: lukka/get-cmake@v3.29.4 - name: Configure win-x64 - run: cmake -S "." -B "build_win_64" -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE:String=Distribution + run: cmake -S "." -B "build_win_64" -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE:String=Distribution -DGENERATE_DEBUG_SYMBOLS=OFF -DCMAKE_INSTALL_PREFIX:String="SDK" - name: Build win-x64 run: cmake --build build_win_64 --config Distribution - name: Configure win-x64 double - run: cmake -S "." -B "build_win_64_double" -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE:String=Distribution -DDOUBLE_PRECISION=ON + run: cmake -S "." -B "build_win_64_double" -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE:String=Distribution -DDOUBLE_PRECISION=ON -DGENERATE_DEBUG_SYMBOLS=OFF -DCMAKE_INSTALL_PREFIX:String="SDK" - name: Build win-x64 double run: cmake --build build_win_64_double --config Distribution - name: Configure win-arm64 - run: cmake -S "." -B "build_win_arm64" -G "Visual Studio 17 2022" -A ARM64 -DCMAKE_BUILD_TYPE:String=Distribution + run: cmake -S "." -B "build_win_arm64" -G "Visual Studio 17 2022" -A ARM64 -DCMAKE_BUILD_TYPE:String=Distribution -DGENERATE_DEBUG_SYMBOLS=OFF -DCMAKE_INSTALL_PREFIX:String="SDK" - name: Build win-arm64 run: cmake --build build_win_arm64 --config Distribution - name: Configure win-arm64 double - run: cmake -S "." -B "build_win_arm64_double" -G "Visual Studio 17 2022" -A ARM64 -DCMAKE_BUILD_TYPE:String=Distribution -DDOUBLE_PRECISION=ON + run: cmake -S "." -B "build_win_arm64_double" -G "Visual Studio 17 2022" -A ARM64 -DCMAKE_BUILD_TYPE:String=Distribution -DDOUBLE_PRECISION=ON -DGENERATE_DEBUG_SYMBOLS=OFF -DCMAKE_INSTALL_PREFIX:String="SDK" - name: Build win-arm64 double run: cmake --build build_win_arm64_double --config Distribution @@ -69,12 +69,12 @@ jobs: # Linux - name: CMake Configure (linux-x64) - run: cmake -S "." -B "build_linux_x64" -G Ninja -DCMAKE_BUILD_TYPE=Distribution + run: cmake -S "." -B "build_linux_x64" -G Ninja -DCMAKE_BUILD_TYPE=Distribution -DGENERATE_DEBUG_SYMBOLS=OFF -DCMAKE_INSTALL_PREFIX:String="SDK" - name: Build linux-x64 run: cmake --build build_linux_x64 --config Distribution --verbose --parallel - name: CMake Configure (linux-arm64) - run: cmake -S "." -B "build_linux_arm64" -G Ninja -DCMAKE_BUILD_TYPE=Distribution -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_SYSTEM_PROCESSOR=aarch64 -DCMAKE_SYSTEM_NAME=Linux + run: cmake -S "." -B "build_linux_arm64" -G Ninja -DCMAKE_BUILD_TYPE=Distribution -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_SYSTEM_PROCESSOR=aarch64 -DCMAKE_SYSTEM_NAME=Linux -DGENERATE_DEBUG_SYMBOLS=OFF -DCMAKE_INSTALL_PREFIX:String="SDK" - name: Build linux-arm64 run: cmake --build build_linux_arm64 --config Distribution --verbose --parallel @@ -95,6 +95,8 @@ jobs: -DCMAKE_BUILD_TYPE=Distribution -DANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }} -DCMAKE_TOOLCHAIN_FILE="${{ steps.setup-ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake" + -DGENERATE_DEBUG_SYMBOLS=OFF + -DCMAKE_INSTALL_PREFIX:String="SDK" - name: Build (android-arm64-v8a) run: cmake --build build_android_arm64_v8a --config Distribution --verbose --parallel @@ -105,6 +107,8 @@ jobs: -DCMAKE_BUILD_TYPE=Distribution -DANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }} -DCMAKE_TOOLCHAIN_FILE="${{ steps.setup-ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake" + -DGENERATE_DEBUG_SYMBOLS=OFF + -DCMAKE_INSTALL_PREFIX:String="SDK" - name: Build (android-armeabi-v7a) run: cmake --build build_android_armeabi_v7a --config Distribution --verbose --parallel @@ -115,6 +119,8 @@ jobs: -DCMAKE_BUILD_TYPE=Distribution -DANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }} -DCMAKE_TOOLCHAIN_FILE="${{ steps.setup-ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake" + -DGENERATE_DEBUG_SYMBOLS=OFF + -DCMAKE_INSTALL_PREFIX:String="SDK" - name: Build (android-armeabi-v7a) run: cmake --build build_android_x86_64 --config Distribution --verbose --parallel @@ -145,7 +151,7 @@ jobs: uses: lukka/get-cmake@v3.29.4 - name: Configure osx-universal - run: cmake -S "." -B "build_osx" -G Ninja -DCMAKE_BUILD_TYPE=Distribution -D"CMAKE_OSX_ARCHITECTURES=x86_64;arm64" + run: cmake -S "." -B "build_osx" -G Ninja -DCMAKE_BUILD_TYPE=Distribution -D"CMAKE_OSX_ARCHITECTURES=x86_64;arm64" -DGENERATE_DEBUG_SYMBOLS=OFF -DCMAKE_INSTALL_PREFIX:String="SDK" - name: Build osx-universal run: cmake --build build_osx --config Distribution --verbose --parallel diff --git a/CMakeLists.txt b/CMakeLists.txt index 6464c00..f8423c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_INSTALL_MESSAGE LAZY) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_OSX_DEPLOYMENT_TARGET "11" CACHE STRING "Minimum OS X deployment version") set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Build architectures for OS X") @@ -42,7 +43,7 @@ option(USE_ASSERTS "Enable asserts" OFF) option(DOUBLE_PRECISION "Use double precision math" OFF) # When turning this option on, the library will be compiled with debug symbols -option(GENERATE_DEBUG_SYMBOLS "Generate debug symbols" OFF) +option(GENERATE_DEBUG_SYMBOLS "Generate debug symbols" ON) # When turning this option on, the library will override the default CMAKE_CXX_FLAGS_DEBUG/RELEASE values, otherwise they will use the platform defaults option(OVERRIDE_CXX_FLAGS "Override CMAKE_CXX_FLAGS_DEBUG/RELEASE" ON) @@ -53,11 +54,6 @@ option(CROSS_PLATFORM_DETERMINISTIC "Cross platform deterministic" OFF) # When turning this option on, the library will be compiled for ARM (aarch64-linux-gnu), requires compiling with clang option(CROSS_COMPILE_ARM "Cross compile to aarch64-linux-gnu" OFF) -# When turning this option on, the library will be compiled with interprocedural optimizations enabled, also known as link-time optimizations or link-time code generation. -# Note that if you turn this on you need to use SET_INTERPROCEDURAL_OPTIMIZATION() or set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) to enable LTO specifically for your own project as well. -# If you don't do this you may get an error: /usr/bin/ld: libJolt.a: error adding symbols: file format not recognized -option(INTERPROCEDURAL_OPTIMIZATION "Enable interprocedural optimizations" ON) - # When turning this on, in Debug and Release mode, the library will emit extra code to ensure that the 4th component of a 3-vector is kept the same as the 3rd component # and will enable floating point exceptions during simulation to detect divisions by zero. # Note that this currently only works using MSVC. Clang turns Float2 into a SIMD vector sometimes causing floating point exceptions (the option is ignored). @@ -127,10 +123,16 @@ cmake_dependent_option(USE_STATIC_MSVC_RUNTIME_LIBRARY "Use the static MSVC runt option(JPH_SAMPLES "Build samples" ${JPH_MASTER_PROJECT}) -# Determine which configurations exist -if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) # Only do this when we're at the top level, see: https://gitlab.kitware.com/cmake/cmake/-/issues/24181 - set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Distribution") -endif() +# Define standard configurations (Debug, Release, Distribution) +set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Distribution") + +# Set the default CMAKE_BUILD_TYPE to Release. +# This should be done before the project command since the latter can set +# CMAKE_BUILD_TYPE itself (it does so for nmake). +if (JPH_MASTER_PROJECT AND NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Distribution" CACHE STRING "The default build type" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES}) +endif () FetchContent_Declare( JoltPhysics @@ -180,11 +182,6 @@ if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR") endif() - # Set compiler flag for disabling RTTI - if (NOT CPP_RTTI_ENABLED) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-") - endif() - if (NOT CPP_EXCEPTIONS_ENABLED) # Remove any existing compiler flag that enables exceptions string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) @@ -200,9 +197,7 @@ if (MSVC) if (OVERRIDE_CXX_FLAGS) set(CMAKE_CXX_FLAGS_DEBUG "/GS /Od /Ob0 /RTC1") set(CMAKE_CXX_FLAGS_RELEASE "/GS- /Gy /O2 /Oi /Ot") - set(CMAKE_CXX_FLAGS_DISTRIBUTION "/GS- /Gy /O2 /Oi /Ot") endif() - set(CMAKE_CXX_FLAGS_DISTRIBUTION "${CMAKE_CXX_FLAGS_RELEASE}") # Set linker flags @@ -290,8 +285,6 @@ endif() set(CMAKE_EXE_LINKER_FLAGS_DISTRIBUTION "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_DISTRIBUTION "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") -SET_INTERPROCEDURAL_OPTIMIZATION() - set(PHYSICS_REPO_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src/joltc) set(BUILD_SHARED_LIBS OFF CACHE BOOL "Disable shared library when building Jolt" FORCE) @@ -327,15 +320,7 @@ target_include_directories(${TARGET_NAME} PUBLIC $ ${JoltPhysics_SOURCE_DIR}/.. ) -target_link_libraries(${TARGET_NAME} PUBLIC Jolt) - -if(JPH_BUILD_SHARED) - set_property(TARGET Jolt PROPERTY POSITION_INDEPENDENT_CODE ON) - set_property(TARGET ${TARGET_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) - - target_compile_definitions(${TARGET_NAME} PRIVATE JPH_SHARED_LIBRARY_BUILD=1) - set_property(TARGET ${TARGET_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) -endif() +target_link_libraries(${TARGET_NAME} PRIVATE Jolt) install(TARGETS ${TARGET_NAME} EXPORT ${TARGET_NAME} diff --git a/README.md b/README.md index 0918904..71c1820 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # joltc -JoltPhysics C interface + +[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/amerkoleci/joltc/blob/main/LICENSE) +[![Build status](https://github.com/amerkoleci/joltc/workflows/Build/badge.svg)](https://github.com/amerkoleci/joltc/actions) + +[JoltPhysics](https://github.com/jrouwe/JoltPhysics) C interface. + +## Sponsors +Please consider [SPONSOR](https://github.com/sponsors/amerkoleci) me to further help development and to allow faster issue triaging and new features to be implemented. +**_NOTE:_** **any feature request** would require a [sponsor](https://github.com/sponsors/amerkoleci) in order to allow faster implementation and allow this project to continue. diff --git a/build/cmake_vs2022_x64.bat b/build/cmake_vs2022_x64.bat index 0f36a47..a924952 100644 --- a/build/cmake_vs2022_x64.bat +++ b/build/cmake_vs2022_x64.bat @@ -1,3 +1,3 @@ @echo off -cmake -S "./../" -B "vs2022_x64" -G "Visual Studio 17 2022" -A x64 -DCMAKE_INSTALL_PREFIX:String="SDK" %* +cmake -S "./../" -B "vs2022_x64" -G "Visual Studio 17 2022" -A x64 -DCMAKE_INSTALL_PREFIX:String="SDK" -DCMAKE_BUILD_TYPE:String=Distribution %* echo Open vs2022_x64\JoltC.sln to build the project. \ No newline at end of file diff --git a/samples/01_HelloWorld/main.c b/samples/01_HelloWorld/main.c index 4e58540..3fc9d60 100644 --- a/samples/01_HelloWorld/main.c +++ b/samples/01_HelloWorld/main.c @@ -6,12 +6,7 @@ #include // malloc, free #include // memset -#if defined(_WIN32) -#include -int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) -#else -int main() -#endif +int main(int argc, char** argv) { if (!JPH_Init()) return 1; diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index ebdc997..a5286a4 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -19,7 +19,10 @@ function(add_sample SAMPLE_NAME) target_link_options(${SAMPLE_NAME} PUBLIC "/SUBSYSTEM:CONSOLE") endif() - set_target_properties(${SAMPLE_NAME} PROPERTIES FOLDER "samples") + set_target_properties(${SAMPLE_NAME} PROPERTIES + LINKER_LANGUAGE C + FOLDER "samples" + ) endfunction() # Add samples