Skip to content

Commit

Permalink
Merge native Apple M1 build #1298
Browse files Browse the repository at this point in the history
  • Loading branch information
poco0317 committed Mar 12, 2024
2 parents e339070 + 9ec41de commit a75c40a
Show file tree
Hide file tree
Showing 11 changed files with 9,606 additions and 10 deletions.
22 changes: 20 additions & 2 deletions CMake/Helpers/CMakeMacOS.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
# TODO: Remove CPU_X86_64, CPU_X86, and CRASH_HANDLER
# CRASH_HANDLER is unnecessary as the game should have that as an option component
# CPU_X86_64, CPU_X86 already exists as compiler predefined macros. Use those instead.
list(APPEND cdefs _XOPEN_SOURCE CPU_X86_64 GL_SILENCE_DEPRECATION)

list(APPEND cdefs _XOPEN_SOURCE GL_SILENCE_DEPRECATION)
if(NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
list(APPEND cdefs CPU_X86_64)
endif()
set_target_properties(Etterna PROPERTIES COMPILE_DEFINITIONS "${cdefs}")

set_target_properties(Etterna PROPERTIES MACOSX_BUNDLE TRUE)
set(CMAKE_EXE_LINKER_FLAGS "-pagezero_size 10000 -image_base 100000000")

if(NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
#TODO: Do we even need these on x86_64?
# For the ARM build, it breaks if they're present, and seems to work just fine without them...
# Seems to have made its way into this file eventually after 2d03a8163f5d10c6b569eb3c92543677c910e82e
# That commit appears to be copying part of luajit's CMakeLists, originating at f31f6eea7bf52400929fcfb303637741bb645818
# (https://github.com/LuaJIT/LuaJIT/commit/f31f6eea7bf52400929fcfb303637741bb645818)
# *That* appears to have originated from https://github.com/LuaJIT/LuaJIT/commit/f76e5a311ba543ae174acd3b585fb672fde8a3b5 which states
### /* OSX mmap() uses a naive first-fit linear search. That's perfect for us.
### ** But -pagezero_size must be set, otherwise the lower 4GB are blocked.
### */
set(CMAKE_EXE_LINKER_FLAGS "-pagezero_size 10000 -image_base 100000000")
endif()

set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")

# Set AppBundle icon
Expand Down
15 changes: 11 additions & 4 deletions CMake/Helpers/SetupFFMPEG.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ if (UNIX)
endif()

if(APPLE)
list(APPEND FFMPEG_CONFIGURE
"--arch=x86_64"
"--cc=clang -arch x86_64"
"--enable-sse")
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
list(APPEND FFMPEG_CONFIGURE
"--arch=arm64"
"--cc=clang -arch arm64"
"--enable-neon")
else()
list(APPEND FFMPEG_CONFIGURE
"--arch=x86_64"
"--cc=clang -arch x86_64"
"--enable-sse")
endif()
endif()
list(APPEND FFMPEG_CONFIGURE "--enable-gpl")
list(APPEND FFMPEG_CONFIGURE "--extra-cflags=-mmacosx-version-min=10.8 -w")
Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ project(Etterna
set(CMAKE_CXX_STANDARD 20) # Minimum C++ Version
set(CMAKE_CXX_EXTENSIONS OFF) # True if compiler extensions are necessary. (Changes -std flag)
set(CMAKE_CXX_STANDARD_REQUIRED ON) # True to require minimum C++ version to compile
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10) # Tell xcodebuild to target an older osx platform
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.11) # First macOS version supporting M1 chips
else()
# Host is x86_64
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10) # Oldest platform we still support
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Export compile commands for clang-tidy
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/CMake/Modules) # Tell CMake where to access FindXXX.cmake files
set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Enable folders/filters within IDEs
Expand Down Expand Up @@ -107,6 +112,10 @@ target_link_libraries(Etterna PRIVATE plog::plog)
target_link_libraries(Etterna PRIVATE nowide::nowide)
target_link_libraries(Etterna PRIVATE ghc_filesystem)

if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
target_link_libraries(Etterna PRIVATE sse2neon)
endif()

# If the user wants crashpad, and the target exists (in-case
# the user wants it, but crashpad couldn't find python)
if(WITH_CRASHPAD AND TARGET crashpad)
Expand Down
6 changes: 6 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ set(RAPIDJSON_BUILD_EXAMPLES OFF)
add_subdirectory(rapidjson)
add_subdirectory(stb)

if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
# Used for providing ARM's NEON equivalents of x86_64 SSE SIMD instructions
add_subdirectory(sse2neon)
endif()


set(JWT_SSL_LIBRARY OpenSSL)
add_subdirectory(jwt-cpp-0.6.0)

Expand Down
2 changes: 2 additions & 0 deletions extern/sse2neon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_library(sse2neon INTERFACE)
target_include_directories(sse2neon INTERFACE sse2neon)
11 changes: 11 additions & 0 deletions extern/sse2neon/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SSE2Neon is used by us to allow the calc to use x86_64 vector intrinsic
instructions on ARM64.

x86_64's SSE SIMD instrinsics are transparently replaced with equivalent
ARM Neon instructions by this header-only library.

The project is available at https://github.com/DLTcollab/sse2neon and is
MIT licensed.

This particular file was copied from the v1.7.0 release, available at
https://github.com/DLTcollab/sse2neon/releases/tag/v1.7.0
21 changes: 21 additions & 0 deletions extern/sse2neon/sse2neon/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2015-2023 SSE2NEON Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit a75c40a

Please sign in to comment.