Skip to content

Commit

Permalink
More build improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
amerkoleci committed Sep 9, 2024
1 parent 2cf6c88 commit 7e4b4a1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 44 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down
41 changes: 13 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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).
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -327,15 +320,7 @@ target_include_directories(${TARGET_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
${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}
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion build/cmake_vs2022_x64.bat
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 1 addition & 6 deletions samples/01_HelloWorld/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
#include <stdlib.h> // malloc, free
#include <string.h> // memset

#if defined(_WIN32)
#include <Windows.h>
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;
Expand Down
5 changes: 4 additions & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e4b4a1

Please sign in to comment.