Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,38 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(BUILD_SHARED_LIBS OFF)

# Support for macOS Universal Binary (x86_64 + arm64)
if(APPLE)
# Option to build universal binary
option(BUILD_UNIVERSAL_BINARY "Build universal binary for macOS (x86_64 + arm64)" OFF)

if(BUILD_UNIVERSAL_BINARY)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Build architectures for macOS" FORCE)
message(STATUS "Building Universal Binary for macOS (x86_64 + arm64)")
else()
# Auto-detect architecture if not building universal binary
if(NOT CMAKE_OSX_ARCHITECTURES)
execute_process(
COMMAND uname -m
OUTPUT_VARIABLE NATIVE_ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NATIVE_ARCH STREQUAL "arm64")
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "Build architectures for macOS" FORCE)
message(STATUS "Building for Apple Silicon (arm64)")
else()
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for macOS" FORCE)
message(STATUS "Building for Intel (x86_64)")
endif()
endif()
endif()

# Set minimum macOS version
if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum macOS deployment version" FORCE)
endif()
endif()

include(CMakeDependentOption)

# ---- Include guards ----
Expand Down
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ To build Piccolo, you must first install the following tools.
- CMake 3.19 (or more recent)
- Git 2.1 (or more recent)

### macOS >= 10.15 (x86_64)
### macOS >= 10.15 (x86_64 and Apple Silicon/ARM64)
- Xcode 12.3 (or more recent)
- CMake 3.19 (or more recent)
- Git 2.1 (or more recent)
Expand Down Expand Up @@ -62,20 +62,38 @@ cmake -S . -B build

### Build on macOS

> The following build instructions only tested on specific hardware of x86_64, and do not support M1 chips. For M1 compatible, we will release later.

To compile Piccolo, you must have the most recent version of Xcode installed.
Then run 'cmake' from the project's root directory, to generate a project of Xcode.

#### Option 1: Using the build script (Recommended)

**For native architecture (automatic detection):**
```bash
./build_macos.sh release
```
cmake -S . -B build -G "Xcode"

**For universal binary (x86_64 + arm64):**
```bash
./build_macos.sh release --universal
```
and you can build the project with

**For debug build:**
```bash
./build_macos.sh debug
```

#### Option 2: Using CMake directly

**For native architecture:**
```bash
cmake -S . -B build -G "Xcode"
cmake --build build --config Release
```

Or you can execute the **build_macos.sh** to build the binaries.
**For universal binary:**
```bash
cmake -S . -B build -G "Xcode" -DBUILD_UNIVERSAL_BINARY=ON
cmake --build build --config Release
```

### Build on Ubuntu 20.04
You can execute the **build_linux.sh** to build the binaries.
Expand Down
80 changes: 64 additions & 16 deletions build_macos.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,79 @@
#!/bin/bash

if test \( $# -ne 1 \);
then
echo "Usage: ./build_macos.sh config"
# Default to native architecture
BUILD_UNIVERSAL=0

# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
debug|release)
if [ -z "$CONFIG" ]; then
if [ "$1" = "debug" ]; then
CONFIG="Debug"
else
CONFIG="Release"
fi
fi
shift
;;
--universal)
BUILD_UNIVERSAL=1
shift
;;
*)
echo "Unknown option: $1"
echo ""
echo "Usage: ./build_macos.sh [config] [options]"
echo ""
echo "config:"
echo " debug - build with the debug configuration"
echo " release - build with the release configuration"
echo ""
echo "options:"
echo " --universal - build universal binary (x86_64 + arm64)"
echo ""
echo "Examples:"
echo " ./build_macos.sh release # Build for native architecture"
echo " ./build_macos.sh release --universal # Build universal binary"
echo ""
exit 1
;;
esac
done

# Check if config is set
if [ -z "$CONFIG" ]; then
echo "Error: Configuration not specified!"
echo ""
echo "Usage: ./build_macos.sh [config] [options]"
echo ""
echo "config:"
echo " debug - build with the debug configuration"
echo " release - build with the release configuration"
echo ""
echo "options:"
echo " --universal - build universal binary (x86_64 + arm64)"
echo ""
exit 1
fi

# Detect current architecture
ARCH=$(uname -m)
echo "Detected architecture: $ARCH"

if test \( \( -n "$1" \) -a \( "$1" = "debug" \) \);then
CONFIG=" Debug"
elif test \( \( -n "$1" \) -a \( "$1" = "release" \) \);then
CONFIG=" Release"
# Configure CMake
if [ $BUILD_UNIVERSAL -eq 1 ]; then
echo "Building Universal Binary (x86_64 + arm64)..."
cmake -S . -B build -G "Xcode" -DBUILD_UNIVERSAL_BINARY=ON
else
echo "The config \"$1\" is not supported!"
echo ""
echo "Configs:"
echo " debug - build with the debug configuration"
echo " release - build with the release configuration"
echo ""
exit 1
echo "Building for native architecture ($ARCH)..."
cmake -S . -B build -G "Xcode"
fi

cmake -S . -B build -G "Xcode"

# Build
echo "Building with $CONFIG configuration..."
cmake --build build --config "${CONFIG}"

echo ""
echo "Build completed successfully!"
echo "Binary location: bin/"
7 changes: 7 additions & 0 deletions engine/source/editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ if(ENABLE_PHYSICS_DEBUG_RENDERER)
)
endif()

# Code signing for macOS (required for Apple Silicon)
if(APPLE)
set(POST_BUILD_COMMANDS ${POST_BUILD_COMMANDS}
COMMAND codesign --force --deep --sign - "${BINARY_ROOT_DIR}/PiccoloEditor" || true
)
endif()

add_custom_command(TARGET ${TARGET_NAME} ${POST_BUILD_COMMANDS})

#precompile
Expand Down