Correctly handle the scenario where multiple architectures are specified

Each target will produce a single binary having multiple architectures, instead of having a binary per architecture. The suffix for each binary will be `multiarch`. This makes it easier for the end-user to install and use. This also helps the transition between Intel and Apple Silicon hardware
This commit is contained in:
smallmodel 2024-12-05 19:38:47 +01:00
parent d7c0ee47fe
commit 115b7b82aa
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
4 changed files with 36 additions and 22 deletions

View file

@ -345,8 +345,12 @@ jobs:
strategy:
matrix:
architecture: [
{name: 'x86_64', triple: 'x86_64-apple-macos10.8'},
{name: 'arm64', triple: 'arm64-apple-macos11'}
#{name: 'x86_64', triple: 'x86_64-apple-macos10.8'},
#{name: 'arm64', triple: 'arm64-apple-macos11'}
#{name: 'x86_64', build_name: 'x86_64'},
#{name: 'arm64', build_name: 'arm64'},
# Compile into an universal binary
{name: 'multiarch(arm64-x86_64)', build_name: 'arm64;x86_64' }
]
name: "Building for platform macos-${{matrix.architecture.name}}"
@ -383,7 +387,7 @@ jobs:
with:
version: 2-latest
build-type: Release
cmake-arguments: "-DCMAKE_OSX_ARCHITECTURES=${{ matrix.architecture.name }}
cmake-arguments: "-DCMAKE_OSX_ARCHITECTURES='${{ matrix.architecture.build_name }}'
-DCMAKE_VERBOSE_MAKEFILE=on"
###
# OpenAL
@ -404,7 +408,7 @@ jobs:
run: |
cmake -B ./build \
-DCMAKE_INSTALL_PREFIX='${{github.workspace}}/thirdparties/soft-oal/install' \
-DCMAKE_OSX_ARCHITECTURES=${{ matrix.architecture.name }} \
-DCMAKE_OSX_ARCHITECTURES='${{ matrix.architecture.build_name }}' \
-DCMAKE_VERBOSE_MAKEFILE=on
cmake --build ./build --config Release --parallel
cmake --install ./build --config Release
@ -422,7 +426,7 @@ jobs:
echo "CMAKE_PARAM=--log-level=VERBOSE \
-DCMAKE_INSTALL_PREFIX='${{github.workspace}}/install' \
-DCMAKE_VERBOSE_MAKEFILE=on \
-DCMAKE_OSX_ARCHITECTURES=${{ matrix.architecture.name }} \
-DCMAKE_OSX_ARCHITECTURES='${{ matrix.architecture.build_name }}' \
-DOPENAL_LIBRARY='${{github.workspace}}/thirdparties/soft-oal/install' \
-DOPENAL_INCLUDE_DIR='${{github.workspace}}/thirdparties/soft-oal/install/include/AL' \
-DGIT_REVISION_BUILD_NUMBER=${{ github.run_number }} \

View file

@ -38,8 +38,9 @@ jobs:
'windows-x86-pdb',
'windows-arm64',
'windows-arm64-pdb',
'macos-x86_64',
'macos-arm64'
#'macos-x86_64',
#'macos-arm64',
'macos-multiarch(arm64-x86_64)',
]
runs-on: ubuntu-24.04

View file

@ -4,6 +4,7 @@ project(openmohaa)
include(TargetArch.cmake)
target_architecture(TARGET_ARCH)
list(LENGTH TARGET_ARCH TARGET_ARCH_COUNT)
set(USE_INTERNAL_LIBS ON)
if(USE_SYSTEM_LIBS)
@ -62,11 +63,11 @@ if(DEBUG_MEMORY)
add_definitions(-D_DEBUG_MEM)
endif()
IF("${TARGET_ARCH}" STREQUAL "i386")
if("${TARGET_ARCH}" STREQUAL "i386")
set(TARGET_ARCH_SUFFIX "x86")
ELSE()
else()
set(TARGET_ARCH_SUFFIX ${TARGET_ARCH})
ENDIF()
endif()
message(STATUS "Architecture detected: ${TARGET_ARCH}")
@ -74,23 +75,27 @@ if(TARGET_LOCAL_SYSTEM)
add_definitions(-DTARGET_LOCAL_SYSTEM)
# As it targets the local system, no need to know about the architecture used
set(TARGET_BIN_SUFFIX "")
message(STATUS "Suffix will not be used as the local system is the target")
message(STATUS "Binary suffix will not be used as the local system is the target")
elseif(${TARGET_ARCH_COUNT} GREATER 1)
add_definitions(-DTARGET_MULTIPLE_ARCHITECTURES)
set(TARGET_BIN_SUFFIX ".multiarch")
message(STATUS "Multiple architectures were specified, suffix set to 'multiarch'.")
else()
set(TARGET_BIN_SUFFIX ".${TARGET_ARCH}")
message(STATUS "Suffix set to ${TARGET_ARCH_SUFFIX}.")
message(STATUS "Binary suffix set to '${TARGET_ARCH_SUFFIX}'.")
endif()
IF(WIN32)
if(WIN32)
set(TARGET_PLATFORM_PREFIX "")
message(STATUS "Using Win32 naming convention")
ELSEIF(UNIX)
elseif(UNIX)
set(TARGET_PLATFORM_PREFIX "")
message(STATUS "Using Unix naming convention")
ELSE()
else()
set(TARGET_PLATFORM_PREFIX "")
ENDIF()
endif()
IF(CMAKE_BUILD_TYPE MATCHES Debug)
if(CMAKE_BUILD_TYPE MATCHES Debug)
add_compile_definitions(_DEBUG)
# NOTE: The following may mess up function importation
@ -99,10 +104,10 @@ IF(CMAKE_BUILD_TYPE MATCHES Debug)
# set(CMAKE_ENABLE_EXPORTS ON)
# message(STATUS "Enabling exports on Unix for backtrace")
#endif()
ELSE()
else()
# Non-debug builds
add_compile_definitions(NDEBUG)
ENDIF()
endif()
if(APPLE)
# macOS doesn't search the executable path by default

View file

@ -86,10 +86,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define DLL_SUFFIX
#endif
#if !defined(TARGET_LOCAL_SYSTEM)
# define ARCH_SUFFIX "." ARCH_STRING
#else
#if defined(TARGET_LOCAL_SYSTEM)
# define ARCH_SUFFIX
#elif defined(TARGET_MULTIPLE_ARCHITECTURES)
// Targeting multiple architecture in a single binary.
// For example, OSX supports compiling multiple architectures in a single binary
# define ARCH_SUFFIX ".multiarch"
#else
# define ARCH_SUFFIX "." ARCH_STRING
#endif
// alloca