User:Fahim Dalvi/Compiling on Apple Silicon

From FlightGear wiki
Jump to navigation Jump to search

Dump of initial commands, to be improved...

Prerequisites:

Building FlightGear:

Move to your directory of choice.

Setup the build directory

mkdir build
PREFIX=`pwd`/build

Clone and compile `openscenegraph`

brew install cmake freetype

git clone --branch fgfs-osg-36-1 https://github.com/zakalawe/osg.git osg-custom-36
cd osg-custom-36
mkdir build.osg
cd build.osg
cmake \
 -D CMAKE_BUILD_TYPE="Release"\
 -D CMAKE_CXX_FLAGS_RELEASE="-O3 -pipe"\
 -D CMAKE_C_FLAGS_RELEASE="-O3 -pipe"\
 -D CMAKE_INSTALL_PREFIX:PATH="${PREFIX}"\
 -D CMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOLEAN="true" -G "Unix Makefiles" ..
make -j 8
make install
cd ../..

Clone and compile `simgear`

brew install boost

git clone --branch next https://git.code.sf.net/p/flightgear/simgear simgear
cd simgear
mkdir build.simgear
cd build.simgear 
cmake \
 -DCMAKE_CXX_STANDARD=17 \
 -DCMAKE_CXX_STANDARD_REQUIRED=ON \
 -DCMAKE_CXX_EXTENSIONS=OFF \
 -DCMAKE_OSX_ARCHITECTURES="arm64" \
 -DCMAKE_OSX_DEPLOYMENT_TARGET=13.1 \
 -DCMAKE_INSTALL_PREFIX=${PREFIX} \
 -DCMAKE_BUILD_TYPE=Release \
 -G "Unix Makefiles" ..
make -j 8
make install
cd ../..
cp simgear/simgear/math/simd.hxx build/include/simgear/math/
cp simgear/simgear/math/simd_neon.hxx build/include/simgear/math/
cp simgear/simgear/math/simd4x4_neon.hxx build/include/simgear/math/

Clone and compile `plib`

brew install svn automake
svn checkout https://svn.code.sf.net/p/plib/code/trunk plib
cd plib
./autogen.sh
./configure --disable-pw --disable-sl --disable-psl --disable-ssg --disable-ssgaux --prefix=${PREFIX} CXXFLAGS="-arch arm64 -mmacosx-version-min=13.1" CFLAGS="-arch arm64 -mmacosx-version-min=13.1"
# use of undeclared identifier 'finite'; did you mean 'isfinite'
# Add `#define finite isfinite` to src/sg/sg.cxx
make install
cd ..

Clone and compile `flightgear`

brew install qt@5
brew install speex speexdsp
brew install dbus libevent # not working for swift yet
git clone --branch next https://git.code.sf.net/p/flightgear/fgdata fgdata
git clone --branch next https://git.code.sf.net/p/flightgear/flightgear flightgear
cd flightgear
Changes to compile on Apple silicon
CMakeLists.txt
@@ -438,7 +438,13 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "Ap
     set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
     set(CMAKE_C_FLAGS_RELWITHDEBINFO  "-O3 -g -DNDEBUG")
 
-    set(SIMD_COMPILER_FLAGS "-msse2 -mfpmath=sse -ftree-vectorize -ftree-slp-vectorize")
+    if (X86 OR X86_64)
+        set(SIMD_COMPILER_FLAGS "-msse2 -mfpmath=sse")
+    endif()
+    set(SIMD_COMPILER_FLAGS "${SIMD_COMPILER_FLAGS} -ftree-vectorize -ftree-slp-vectorize")
+
+    # set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
+    # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
     set(WARNING_FLAGS_C "-Wall")
 endif()

src/GUI/CocoaHelpers.mm
@@ -35,6 +35,10 @@
 #include <Foundation/NSLocale.h>
 #include <AppKit/NSAlert.h>
 
+#if defined(HAVE_QT)
+#  include <GUI/QtLauncher.hxx>
+#endif
+
 // simgear
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/debug/logstream.hxx>
@@ -46,10 +50,6 @@
 #include <Main/locale.hxx>
 #include <Main/globals.hxx>
 
-#if defined(HAVE_QT)
-#  include <GUI/QtLauncher.hxx>
-#endif
-
Continue with compilation
mkdir build.flightgear
cd build.flightgear
cmake \
 -E env CFLAGS="-Wno-deprecated-declarations -Wno-inconsistent-missing-override" CXXFLAGS="-Wno-deprecated-declarations -Wno-inconsistent-missing-override" \
 cmake \
  -DFG_DATA_DIR=../../fgdata \
  -DSYSTEM_SPEEX=ON \
  -DCMAKE_OSX_ARCHITECTURES="arm64" \
  -DCMAKE_OSX_DEPLOYMENT_TARGET=13.1 \
  -DCMAKE_INSTALL_PREFIX=${PREFIX} \
  -DCMAKE_BUILD_TYPE="Release" \
  -DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5 \
  -DWITH_FGPANEL=false \
  -DCMAKE_CXX_STANDARD=17 \
  -DCMAKE_CXX_STANDARD_REQUIRED=ON \
  -DCMAKE_CXX_EXTENSIONS=OFF \
  -G "Unix Makefiles" ..
make -j 4 install
cd ../..

Running compiled FG

# Make sure you are in the top level directory (with subdirectories like `build`, `flightgear`, `simgear` etc)

DYLD_LIBRARY_PATH=`pwd`/build/lib:$DYLD_LIBRARY_PATH FG_HOME=`pwd`/fghome build/fgfs.app/Contents/MacOS/fgfs --fg-root=`pwd`/fgdata/ --launcher