Browse Source

Ability to make XCode project for iOS and MacOS (#92)

Jorrit Rouwe 3 years ago
parent
commit
5a50dc65ff

+ 14 - 0
.github/workflows/build.yml

@@ -109,3 +109,17 @@ jobs:
     - name: Gradle Build
       working-directory: ${{github.workspace}}/Build/Android
       run: ./gradlew build
+
+  ios:
+    runs-on: macos-latest
+    name: iOS
+    strategy:
+        fail-fast: false
+
+    steps:
+    - name: Checkout Code
+      uses: actions/checkout@v2
+    - name: Configure CMake
+      run: cmake -B ${{github.workspace}}/Build/XCode_iOS -DTARGET_HELLO_WORLD=OFF -DTARGET_PERFORMANCE_TEST=OFF -DCMAKE_SYSTEM_NAME=iOS -GXcode Build
+    - name: Build
+      run: cmake --build ${{github.workspace}}/Build/XCode_iOS -- -sdk iphonesimulator -arch x86_64

+ 1 - 0
.gitignore

@@ -1,4 +1,5 @@
 .vs
+.DS_Store
 /profile_list_*.html
 /profile_chart_*.html
 /stats*.html

+ 2 - 1
Build/.gitignore

@@ -1,4 +1,5 @@
 /Linux*
 /VS20*
+/XCode*
 /Doxygen
-/CoverageReport
+/CoverageReport

+ 52 - 29
Build/CMakeLists.txt

@@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
 
 project(JoltPhysics CXX)
 
+# Ability to turn ON/OFF individual applications
+option(TARGET_UNIT_TESTS "Build Unit Tests" ON)
+option(TARGET_HELLO_WORLD "Build Hello World" ON)
+option(TARGET_PERFORMANCE_TEST "Build Performance Test" ON)
+
 # Select X86 processor features to use (if everything is off it will be SSE4.1 compatible)
 option(USE_SSE4_2 "Enable SSE4.2" ON)
 option(USE_AVX "Enable AVX" ON)
@@ -13,7 +18,7 @@ option(USE_FMADD "Enable FMADD" ON)
 
 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
 	set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Distribution")
-elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
 	set(CMAKE_CONFIGURATION_TYPES "Debug;Release;ReleaseASAN;ReleaseUBSAN;ReleaseCoverage;Distribution")
 endif()
 
@@ -93,7 +98,7 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
 		set(CMAKE_EXE_LINKER_FLAGS_RELEASEUBSAN "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LIBPATH:${CLANG_LIB_PATH}")
 		set(CMAKE_EXE_LINKER_FLAGS_RELEASECOVERAGE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LIBPATH:${CLANG_LIB_PATH}")
 	endif()
-elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
+elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
 	# Set general compiler flags (do not use -ffast-math since it cannot be turned off in a single compilation unit)
 	set(CMAKE_CXX_FLAGS "-g -std=c++17 -I. -Wall -Werror")
 
@@ -152,39 +157,57 @@ set(PHYSICS_REPO_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../)
 
 # Make Jolt Library
 include(${PHYSICS_REPO_ROOT}/Jolt/Jolt.cmake)
-
-# Create UnitTests executable
-include(${PHYSICS_REPO_ROOT}/UnitTests/UnitTests.cmake)
-add_executable(UnitTests ${UNIT_TESTS_SRC_FILES})
-target_include_directories(UnitTests PUBLIC ${JOLT_PHYSICS_ROOT} ${UNIT_TESTS_ROOT})
-target_link_libraries (UnitTests LINK_PUBLIC Jolt)
-if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
-	target_link_options(UnitTests PUBLIC "/SUBSYSTEM:CONSOLE")
+if (IOS)
+	# Ensure that we enable SSE4.2 for the x86_64 build, CMAKE_SYSTEM_PROCESSOR is not set for iOS
+	set_property(TARGET Jolt PROPERTY XCODE_ATTRIBUTE_OTHER_CPLUSPLUSFLAGS[arch=x86_64] "$(inherited) -msse4.2 -mpopcnt") 
 endif()
 
-# Register unit tests as a test so that it can be run with: 
-# ctest --output-on-failure
-enable_testing()
-add_test(UnitTests UnitTests)
+if (TARGET_UNIT_TESTS)
+    # Create UnitTests executable
+    include(${PHYSICS_REPO_ROOT}/UnitTests/UnitTests.cmake)
+    add_executable(UnitTests ${UNIT_TESTS_SRC_FILES})
+    target_include_directories(UnitTests PUBLIC ${JOLT_PHYSICS_ROOT} ${UNIT_TESTS_ROOT})
+    target_link_libraries (UnitTests LINK_PUBLIC Jolt)
+    if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
+        target_link_options(UnitTests PUBLIC "/SUBSYSTEM:CONSOLE")
+    endif()
+    if (IOS)
+	# Set the bundle information
+        set_property(TARGET UnitTests PROPERTY MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/iOS/UnitTestsInfo.plist")
+        set_property(TARGET UnitTests PROPERTY XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.joltphysics.unittests")
+
+	# Ensure that we enable SSE4.2 for the x86_64 build, CMAKE_SYSTEM_PROCESSOR is not set for iOS
+	set_property(TARGET UnitTests PROPERTY XCODE_ATTRIBUTE_OTHER_CPLUSPLUSFLAGS[arch=x86_64] "$(inherited) -msse4.2 -mpopcnt")
+    endif()
+
+    # Register unit tests as a test so that it can be run with:
+    # ctest --output-on-failure
+    enable_testing()
+    add_test(UnitTests UnitTests)
+endif()
 
-# Example 'Hello World' application
-include(${PHYSICS_REPO_ROOT}/HelloWorld/HelloWorld.cmake)
-add_executable(HelloWorld ${HELLO_WORLD_SRC_FILES})
-target_include_directories(HelloWorld PUBLIC ${JOLT_PHYSICS_ROOT} ${HELLO_WORLD_ROOT})
-target_link_libraries (HelloWorld LINK_PUBLIC Jolt)
-if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
-	target_link_options(HelloWorld PUBLIC "/SUBSYSTEM:CONSOLE")
+if (TARGET_HELLO_WORLD)
+	# Example 'Hello World' application
+	include(${PHYSICS_REPO_ROOT}/HelloWorld/HelloWorld.cmake)
+	add_executable(HelloWorld ${HELLO_WORLD_SRC_FILES})
+	target_include_directories(HelloWorld PUBLIC ${JOLT_PHYSICS_ROOT} ${HELLO_WORLD_ROOT})
+	target_link_libraries (HelloWorld LINK_PUBLIC Jolt)
+	if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
+		target_link_options(HelloWorld PUBLIC "/SUBSYSTEM:CONSOLE")
+	endif()
 endif()
 
-# Performance Test application
-include(${PHYSICS_REPO_ROOT}/PerformanceTest/PerformanceTest.cmake)
-add_executable(PerformanceTest ${PERFORMANCE_TEST_SRC_FILES})
-target_include_directories(PerformanceTest PUBLIC ${JOLT_PHYSICS_ROOT} ${PERFORMANCE_TEST_ROOT})
-target_link_libraries (PerformanceTest LINK_PUBLIC Jolt)
-if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
-	target_link_options(PerformanceTest PUBLIC "/SUBSYSTEM:CONSOLE")
+if (TARGET_PERFORMANCE_TEST)
+	# Performance Test application
+	include(${PHYSICS_REPO_ROOT}/PerformanceTest/PerformanceTest.cmake)
+	add_executable(PerformanceTest ${PERFORMANCE_TEST_SRC_FILES})
+	target_include_directories(PerformanceTest PUBLIC ${JOLT_PHYSICS_ROOT} ${PERFORMANCE_TEST_ROOT})
+	target_link_libraries (PerformanceTest LINK_PUBLIC Jolt)
+	if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
+		target_link_options(PerformanceTest PUBLIC "/SUBSYSTEM:CONSOLE")
+	endif()
+	set_property(TARGET PerformanceTest PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${PHYSICS_REPO_ROOT}")
 endif()
-set_property(TARGET PerformanceTest PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${PHYSICS_REPO_ROOT}")
 
 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
 	# Windows only targets

+ 19 - 1
Build/README.md

@@ -71,6 +71,24 @@ To override the default trace and assert mechanism install your own custom handl
 - Select 'Run' / 'Run...' and 'UnitTests'
 - If the screen turns green after a while the unit tests succeeded, when red they failed (see the android log for details)
 
+### MacOS
+
+- Install XCode
+- Download CMake 3.23+ (https://cmake.org/download/)
+- Run: ./cmake_xcode_macos.sh
+- This will open XCode with a newly generated project
+- Build and run the project
+
+Note that you can also follow the steps in the 'Linux' section if you wish to build without XCode.
+
+### iOS
+
+- Install XCode
+- Download CMake 3.23+ (https://cmake.org/download/)
+- Run: ./cmake_xcode.ios.sh
+- This will open XCode with a newly generated project
+- Build and run the project (note that this will only work in the simulator as the code signing information is not set up)
+
 ## Unit Test Coverage Report on Windows
 
 To test unit test coverage run the following:
@@ -79,7 +97,7 @@ To test unit test coverage run the following:
 - Run: unit_tests_coverage.bat
 - This will build and run the unit tests and open a browser with the results
 
-## Doxygen
+## Doxygen on Windows
 
 Documentation can be generated through doxygen:
 

+ 4 - 0
Build/cmake_xcode_ios.sh

@@ -0,0 +1,4 @@
+#!/bin/sh
+
+cmake -S . -B XCode_iOS -DTARGET_HELLO_WORLD=OFF -DTARGET_PERFORMANCE_TEST=OFF -DCMAKE_SYSTEM_NAME=iOS -GXcode
+open XCode_iOS/JoltPhysics.xcodeproj

+ 4 - 0
Build/cmake_xcode_macos.sh

@@ -0,0 +1,4 @@
+#!/bin/sh
+
+cmake -S . -B XCode_MacOS -GXcode
+open XCode_MacOS/JoltPhysics.xcodeproj

+ 34 - 0
Build/iOS/UnitTestsInfo.plist

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleDevelopmentRegion</key>
+	<string>English</string>
+	<key>CFBundleExecutable</key>
+	<string>$(EXECUTABLE_NAME)</string>
+	<key>CFBundleGetInfoString</key>
+	<string></string>
+	<key>CFBundleIconFile</key>
+	<string></string>
+	<key>CFBundleIdentifier</key>
+	<string>com.joltphysics.unittests</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundleLongVersionString</key>
+	<string>1.0</string>
+	<key>CFBundleName</key>
+	<string>UnitTests</string>
+	<key>CFBundlePackageType</key>
+	<string>APPL</string>
+	<key>CFBundleShortVersionString</key>
+	<string>1.0</string>
+	<key>CFBundleSignature</key>
+	<string>????</string>
+	<key>CFBundleVersion</key>
+	<string>1.0</string>
+	<key>CSResourcesFileMapped</key>
+	<true/>
+	<key>NSHumanReadableCopyright</key>
+	<string></string>
+</dict>
+</plist>