Skip to content

Commit

Permalink
Improved build scripts for macOS and iOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBanana committed Aug 23, 2023
1 parent 528a052 commit 3d3b4d7
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 137 deletions.
98 changes: 75 additions & 23 deletions BuildIOS.command
Original file line number Diff line number Diff line change
@@ -1,7 +1,58 @@
#!/bin/sh

SOURCE_DIR="$(dirname $0)"
BUILD_DIR="$SOURCE_DIR/build_ios"
OUTPUT_DIR="$SOURCE_DIR/build_ios"
CLEAR_CACHE=0
ENABLE_EXAMPLES="OFF"
ENABLE_TESTS="ON"
#BUILD_TYPE="Release"
DEPLOYMENT_TARGET="11.0"
PROJECT_ONLY=0

print_help()
{
echo "USAGE:"
echo " BuildIOS.command OPTIONS* [OUTPUT_DIR]"
echo "OPTIONS:"
echo " -h, --help .............. Print this help documentation and exit"
echo " -c, --clear-cache ....... Clear CMake cache and rebuild"
# echo " -d, --debug ............. Configure Debug build (default is Release)"
echo " -t, --target T .......... Sets deployment target to T (default is 11.0)"
echo " -p, --project-only ...... Build project solution only (no compilation)"
# echo " -no-examples ............ Exclude example projects"
echo " -no-tests ............... Exclude test projects"
echo "NOTES:"
echo " Default output directory is 'build_ios'"
}

# Parse arguments
READ_TARGET=0
for ARG in "$@"; do
if [ $READ_TARGET = 1 ]; then
DEPLOYMENT_TARGET="$ARG"
echo "Deployment target set to $DEPLOYMENT_TARGET"
READ_TARGET=0
else
if [ $ARG = "-h" ] || [ $ARG = "--help" ]; then
print_help
exit 0
elif [ $ARG = "-c" ] || [ $ARG = "--clear-cache" ]; then
CLEAR_CACHE=1
# elif [ $ARG = "-d" ] || [ $ARG = "--debug" ]; then
# BUILD_TYPE="Debug"
elif [ $ARG = "-t" ] || [ $ARG = "--target" ]; then
READ_TARGET=1
elif [ $ARG = "-p" ] || [ $ARG = "--project-only" ]; then
PROJECT_ONLY=1
# elif [ $ARG = "-no-examples" ]; then
# ENABLE_EXAMPLES="OFF"
elif [ $ARG = "-no-tests" ]; then
ENABLE_TESTS="OFF"
else
OUTPUT_DIR=$ARG
fi
fi
done

# Ensure we are inside the repository folder
if [ ! -f "$SOURCE_DIR/CMakeLists.txt" ]; then
Expand All @@ -10,41 +61,42 @@ if [ ! -f "$SOURCE_DIR/CMakeLists.txt" ]; then
fi

# Make output build folder
if [ "$#" -eq 1 ]; then
BUILD_DIR=$1
else
if [ ! "$#" -eq 0 ]; then
echo "error: too many arguemnts"
echo "usage: BuildIOS.command [BUILD_DIR]"
exit 1
fi
if [ $CLEAR_CACHE = 1 ] && [ -d "$OUTPUT_DIR" ]; then
rm -rf "$OUTPUT_DIR"
fi

if [ ! -d "$BUILD_DIR" ]; then
mkdir "$BUILD_DIR"
if [ ! -d "$OUTPUT_DIR" ]; then
mkdir "$OUTPUT_DIR"
fi

# Checkout external depenencies
GAUSSIAN_LIB_DIR="$BUILD_DIR/GaussianLib/include"
GAUSSIAN_LIB_DIR="GaussianLib/include"

if [ ! -d "$GAUSSIAN_LIB_DIR" ]; then
(cd "$BUILD_DIR" && git clone https://github.com/LukasBanana/GaussianLib.git)
if [ -f "$SOURCE_DIR/external/$GAUSSIAN_LIB_DIR/Gauss/Gauss.h" ]; then
GAUSSIAN_LIB_DIR="$SOURCE_DIR/external/$GAUSSIAN_LIB_DIR"
elif [ ! -d "$OUTPUT_DIR/$GAUSSIAN_LIB_DIR" ]; then
(cd "$OUTPUT_DIR" && git clone https://github.com/LukasBanana/GaussianLib.git)
GAUSSIAN_LIB_DIR="$OUTPUT_DIR/$GAUSSIAN_LIB_DIR"
fi

# Build into output directory
cmake \
-DCMAKE_SYSTEM_NAME=iOS \
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
-DCMAKE_OSX_DEPLOYMENT_TARGET="$DEPLOYMENT_TARGET" \
-DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO \
-DCMAKE_IOS_INSTALL_COMBINED=ON \
-DLLGL_BUILD_RENDERER_NULL=OFF \
-DLLGL_BUILD_RENDERER_OPENGLES3=OFF \
-DLLGL_BUILD_RENDERER_METAL=ON \
-DLLGL_BUILD_TESTS=ON \
-DLLGL_BUILD_STATIC_LIB=ON \
-DLLGL_BUILD_EXAMPLES=ON \
-DLLGL_BUILD_EXAMPLES=$ENABLE_EXAMPLES \
-DLLGL_BUILD_TESTS=$ENABLE_TESTS \
-DGaussLib_INCLUDE_DIR:STRING="$GAUSSIAN_LIB_DIR" \
-DCMAKE_SYSTEM_NAME=iOS \
"-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" \
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
-DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO \
-DCMAKE_IOS_INSTALL_COMBINED=ON \
-S "$SOURCE_DIR" \
-B "$BUILD_DIR" -G Xcode
-B "$OUTPUT_DIR" \
-G Xcode

cmake --build "$BUILD_DIR" -- -sdk iphonesimulator
if [ $PROJECT_ONLY -eq 0 ]; then
cmake --build "$OUTPUT_DIR" -- -sdk iphonesimulator
fi
81 changes: 64 additions & 17 deletions BuildMacOS.command
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
#!/bin/sh

SOURCE_DIR="$(dirname $0)"
BUILD_DIR="$SOURCE_DIR/build_macos"
OUTPUT_DIR="$SOURCE_DIR/build_macos"
CLEAR_CACHE=0
ENABLE_NULL="OFF"
ENABLE_EXAMPLES="ON"
ENABLE_TESTS="ON"
BUILD_TYPE="Release"
PROJECT_ONLY=0

print_help()
{
echo "USAGE:"
echo " BuildMacOS.command OPTIONS* [OUTPUT_DIR]"
echo "OPTIONS:"
echo " -h, --help .............. Print this help documentation and exit"
echo " -c, --clear-cache ....... Clear CMake cache and rebuild"
echo " -d, --debug ............. Configure Debug build (default is Release)"
echo " -p, --project-only ...... Build project solution only (no compilation)"
echo " -null ................... Include Null renderer"
echo " -no-examples ............ Exclude example projects"
echo " -no-tests ............... Exclude test projects"
echo "NOTES:"
echo " Default output directory is 'build_macos'"
}

# Parse arguments
for ARG in "$@"; do
if [ $ARG = "-h" ] || [ $ARG = "--help" ]; then
print_help
exit 0
elif [ $ARG = "-c" ] || [ $ARG = "--clear-cache" ]; then
CLEAR_CACHE=1
elif [ $ARG = "-d" ] || [ $ARG = "--debug" ]; then
BUILD_TYPE="Debug"
elif [ $ARG = "-p" ] || [ $ARG = "--project-only" ]; then
PROJECT_ONLY=1
elif [ $ARG = "-null" ]; then
ENABLE_NULL="ON"
elif [ $ARG = "-no-examples" ]; then
ENABLE_EXAMPLES="OFF"
elif [ $ARG = "-no-tests" ]; then
ENABLE_TESTS="OFF"
else
OUTPUT_DIR=$ARG
fi
done

# Ensure we are inside the repository folder
if [ ! -f "$SOURCE_DIR/CMakeLists.txt" ]; then
Expand All @@ -10,33 +54,36 @@ if [ ! -f "$SOURCE_DIR/CMakeLists.txt" ]; then
fi

# Make output build folder
if [ "$#" -eq 1 ]; then
BUILD_DIR=$1
else
if [ ! "$#" -eq 0 ]; then
echo "error: too many arguemnts"
echo "usage: BuildMacOS.command [BUILD_DIR]"
exit 1
fi
if [ $CLEAR_CACHE = 1 ] && [ -d "$OUTPUT_DIR" ]; then
rm -rf "$OUTPUT_DIR"
fi

if [ ! -d "$BUILD_DIR" ]; then
mkdir "$BUILD_DIR"
if [ ! -d "$OUTPUT_DIR" ]; then
mkdir "$OUTPUT_DIR"
fi

# Checkout external depenencies
GAUSSIAN_LIB_DIR="$BUILD_DIR/GaussianLib/include"
GAUSSIAN_LIB_DIR="GaussianLib/include"

if [ ! -d "$GAUSSIAN_LIB_DIR" ]; then
(cd "$BUILD_DIR" && git clone https://github.com/LukasBanana/GaussianLib.git)
if [ -f "$SOURCE_DIR/external/$GAUSSIAN_LIB_DIR/Gauss/Gauss.h" ]; then
GAUSSIAN_LIB_DIR="$SOURCE_DIR/external/$GAUSSIAN_LIB_DIR"
elif [ ! -d "$OUTPUT_DIR/$GAUSSIAN_LIB_DIR" ]; then
(cd "$OUTPUT_DIR" && git clone https://github.com/LukasBanana/GaussianLib.git)
GAUSSIAN_LIB_DIR="$OUTPUT_DIR/$GAUSSIAN_LIB_DIR"
fi

# Build into output directory
cmake \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DLLGL_BUILD_RENDERER_NULL=$ENABLE_NULL \
-DLLGL_BUILD_RENDERER_OPENGL=ON \
-DLLGL_BUILD_RENDERER_METAL=ON \
-DLLGL_BUILD_EXAMPLES=ON \
-DLLGL_BUILD_EXAMPLES=$ENABLE_EXAMPLES \
-DLLGL_BUILD_TESTS=$ENABLE_TESTS \
-DGaussLib_INCLUDE_DIR:STRING="$GAUSSIAN_LIB_DIR" \
-S "$SOURCE_DIR" \
-B "$BUILD_DIR"
cmake --build "$BUILD_DIR"
-B "$OUTPUT_DIR"

if [ $PROJECT_ONLY -eq 0 ]; then
cmake --build "$OUTPUT_DIR"
fi
24 changes: 0 additions & 24 deletions GenerateProjectIOS.command

This file was deleted.

98 changes: 25 additions & 73 deletions RunExamplesMacOS.command
Original file line number Diff line number Diff line change
Expand Up @@ -14,78 +14,30 @@ else
exit 1
fi

PS3='select example: '
options=(
"Hello Triangle"
"Tessellation"
"Texturing"
"Render Target"
"Buffer Array"
"Instancing"
"Stream Output"
"Post Processing"
"Shadow Mapping"
"Stencil Buffer"
"Volume Rendering"
"Compute Shader"
"Animation"
"Cloth Physics"
"Primitive Restart"
"Resource Binding"
list_examples()
{
EXCLUDED=(MultiRenderer MultiThreading PBR ComputeShader UnorderedAccess)
EXAMPLE_DIRS=($(ls examples/Cpp))
for DIR in "${EXAMPLE_DIRS[@]}"; do
if ! echo "${EXCLUDED[@]}}" | grep -qw "$DIR"; then
if [ -f "examples/Cpp/$DIR/Example.cpp" ]; then
echo "$DIR"
fi
fi
done
}

run_example()
(
EXAMPLE=$1
EXE="../../../$BUILD_DIR/Example_${EXAMPLE}.app/Contents/MacOS/Example_${EXAMPLE}"
cd examples/Cpp/$EXAMPLE
eval $EXE
)
select opt in "${options[@]}"
do
case $opt in
"${options[0]}")
(cd "$SOURCE_DIR/examples/Cpp/HelloTriangle"; ../../../$BUILD_DIR/Example_HelloTriangle.app/Contents/MacOS/Example_HelloTriangle)
;;
"${options[1]}")
(cd "$SOURCE_DIR/examples/Cpp/Tessellation"; ../../../$BUILD_DIR/Example_Tessellation.app/Contents/MacOS/Example_Tessellation)
;;
"${options[2]}")
(cd "$SOURCE_DIR/examples/Cpp/Texturing"; ../../../$BUILD_DIR/Example_Texturing.app/Contents/MacOS/Example_Texturing)
;;
"${options[3]}")
(cd "$SOURCE_DIR/examples/Cpp/RenderTarget"; ../../../$BUILD_DIR/Example_RenderTarget.app/Contents/MacOS/Example_RenderTarget)
;;
"${options[4]}")
(cd "$SOURCE_DIR/examples/Cpp/BufferArray"; ../../../$BUILD_DIR/Example_BufferArray.app/Contents/MacOS/Example_BufferArray)
;;
"${options[5]}")
(cd "$SOURCE_DIR/examples/Cpp/Instancing"; ../../../$BUILD_DIR/Example_Instancing.app/Contents/MacOS/Example_Instancing)
;;
"${options[6]}")
(cd "$SOURCE_DIR/examples/Cpp/StreamOutput"; ../../../$BUILD_DIR/Example_StreamOutput.app/Contents/MacOS/Example_StreamOutput)
;;
"${options[7]}")
(cd "$SOURCE_DIR/examples/Cpp/PostProcessing"; ../../../$BUILD_DIR/Example_PostProcessing.app/Contents/MacOS/Example_PostProcessing)
;;
"${options[8]}")
(cd "$SOURCE_DIR/examples/Cpp/ShadowMapping"; ../../../$BUILD_DIR/Example_ShadowMapping.app/Contents/MacOS/Example_ShadowMapping)
;;
"${options[9]}")
(cd "$SOURCE_DIR/examples/Cpp/StencilBuffer"; ../../../$BUILD_DIR/Example_StencilBuffer.app/Contents/MacOS/Example_StencilBuffer)
;;
"${options[10]}")
(cd "$SOURCE_DIR/examples/Cpp/VolumeRendering"; ../../../$BUILD_DIR/Example_VolumeRendering.app/Contents/MacOS/Example_VolumeRendering)
;;
"${options[11]}")
(cd "$SOURCE_DIR/examples/Cpp/ComputeShader"; ../../../$BUILD_DIR/Example_ComputeShader.app/Contents/MacOS/Example_ComputeShader)
;;
"${options[12]}")
(cd "$SOURCE_DIR/examples/Cpp/Animation"; ../../../$BUILD_DIR/Example_Animation.app/Contents/MacOS/Example_Animation)
;;
"${options[13]}")
(cd "$SOURCE_DIR/examples/Cpp/ClothPhysics"; ../../../$BUILD_DIR/Example_ClothPhysics.app/Contents/MacOS/Example_ClothPhysics)
;;
"${options[14]}")
(cd "$SOURCE_DIR/examples/Cpp/PrimitiveRestart"; ../../../$BUILD_DIR/Example_PrimitiveRestart.app/Contents/MacOS/Example_PrimitiveRestart)
;;
"${options[15]}")
(cd "$SOURCE_DIR/examples/Cpp/ResourceBinding"; ../../../$BUILD_DIR/Example_ResourceBinding.app/Contents/MacOS/Example_ResourceBinding)
;;
*)
echo "invalid selection"
;;
esac

EXAMPLES=($(list_examples))

PS3="Select example: "
select OPT in "${EXAMPLES[@]}"; do
run_example $OPT
done

0 comments on commit 3d3b4d7

Please sign in to comment.