Преглед на файлове

CMake files and GitHub workflow for MacOS (#79)

Jorrit Rouwe преди 3 години
родител
ревизия
c1e3c7f542
променени са 4 файла, в които са добавени 37 реда и са изтрити 4 реда
  1. 22 1
      .github/workflows/build.yml
  2. 1 1
      Build/CMakeLists.txt
  3. 11 1
      Jolt/Core/TickCounter.cpp
  4. 3 1
      README.md

+ 22 - 1
.github/workflows/build.yml

@@ -22,7 +22,7 @@ jobs:
         fail-fast: false
         matrix:
             build_type: [Debug, Release, Distribution, ReleaseASAN, ReleaseUBSAN]
-            clang_version: [clang++-10, clang++-11, clang++-12]
+            clang_version: [clang++-10, clang++-12]
 
     steps:
     - name: Checkout Code
@@ -76,6 +76,27 @@ jobs:
       working-directory: ${{github.workspace}}/Build/VS2022_CL/${{matrix.build_type}}
       run: ./UnitTests.exe
 
+  macos:
+    runs-on: macos-latest
+    name: MacOS
+    strategy:
+        fail-fast: false
+        matrix:
+            build_type: [Debug, Release, Distribution]
+            clang_version: [clang++]
+
+    steps:
+    - name: Checkout Code
+      uses: actions/checkout@v2
+    - name: Configure CMake
+      run: cmake -B ${{github.workspace}}/Build/MacOS_${{matrix.build_type}}_${{matrix.clang_version}} -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=${{matrix.clang_version}} Build
+    - name: Build
+      run: cmake --build ${{github.workspace}}/Build/MacOS_${{matrix.build_type}}_${{matrix.clang_version}} --config ${{matrix.build_type}}
+# Disabled unit tests, they work on a Mac Mini 2014 but not in a github action for some reason
+#    - name: Test
+#      working-directory: ${{github.workspace}}/Build/MacOS_${{matrix.build_type}}_${{matrix.clang_version}}
+#      run: ctest --output-on-failure
+
   android:
     runs-on: ubuntu-latest
     name: Android

+ 1 - 1
Build/CMakeLists.txt

@@ -93,7 +93,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")
+elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
 	# 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")
 

+ 11 - 1
Jolt/Core/TickCounter.cpp

@@ -13,6 +13,9 @@
 	#pragma warning (pop)
 #elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID)
 	#include <fstream>
+#elif defined(JPH_PLATFORM_MACOS) || defined(JPH_PLATFORM_IOS)
+	#include <sys/types.h>
+	#include <sys/sysctl.h>
 #endif
 
 namespace JPH {
@@ -74,7 +77,14 @@ static const uint64 sProcessorTicksPerSecond = []() {
 	JPH_ASSERT(false);
     return uint64(0);
 #elif defined(JPH_PLATFORM_MACOS) || defined(JPH_PLATFORM_IOS)
-    return 0;
+	// Use sysctl to get the processor frequency
+	int mib[2];
+    mib[0] = CTL_HW;
+    mib[1] = HW_CPU_FREQ;
+    uint64 freq = 1;
+    size_t len = sizeof(freq);
+    sysctl(mib, 2, &freq, &len, nullptr, 0);
+	return freq;
 #else
 	#error Undefined
 #endif

+ 3 - 1
README.md

@@ -79,10 +79,12 @@ For more information see the [Architecture and API documentation](https://jrouwe
 * Linux (tested on Ubuntu 20.04) x64/ARM64
 * Android (tested on Android 10) x64/ARM64
 * Platform Blue (a popular game console) x64
+* MacOS (has had minimal testing)
+* iOS (has had minimal testing)
 
 ## Required CPU features
 
-* On x86 the minimal requirements are SSE4.1 but the library can be compiled using SSE4.2, FP16C, AVX or AVX2.
+* On x86 the minimal requirements are SSE4.1 but the library can be compiled using SSE4.2, AVX or AVX2.
 * On ARM64 the library requires NEON with FP16 support.
 
 ## Compiling