FlightGear在Windows的编译安装教程

本文记录在Windows10平台上编译安装FlightGear的过程。

前提条件

按顺序安装如下软件:

  1. CMake for Windows。
  2. Microsoft Visual Studio 2017。
  3. QT5.9.8。QT安装步骤请参考QT5.11下载与安装教程注意需选择安装MSVC 2017 64-bit编译器
  4. Git。

获取源代码

1
2
3
4
5
6
7
8
9
git clone https://git.code.sf.net/p/flightgear/simgear simgear

git clone https://git.code.sf.net/p/flightgear/flightgear flightgear

git clone https://git.code.sf.net/p/flightgear/fgdata fgdata

git clone https://git.code.sf.net/p/flightgear/windows-3rd-party windows-3rd-party

git clone -b fgfs-342-1 https://github.com/zakalawe/osg.git osg

目录结构

采用如下目录结构组织源代码:

1
2
3
4
5
6
7
8
9
10
FlightGearBuild / (Main root directory)
fgdata / (FlightGear data files)
flightgear / (FlightGear sources)
install / (Directory where you will install the built binaries to)
launch.bat / (launch script if desired, see below)
osg / (OSG sources)
simgear / (SimGear sources)
windows-3rd-party /
build.bat / (build script, see below)
update.bat / (update script, see below)

编译链接

使用build.bat批处理脚本配置编译OSG, SG 和 FG。其内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
SET PATH=%PATH%;%ProgramFiles%\CMake\bin
SET QT5SDK64=C:\Qt\5.15.0\msvc2019_64
SET CMAKE_TOOLCHAIN="Visual Studio 16 2019"
SET ROOT_DIR=C:\path\to\FlightGearBuild

md osg-build
md simgear-build
md flightgear-build

cd %ROOT_DIR%\osg-build

cmake %ROOT_DIR%\osg -G %CMAKE_TOOLCHAIN% -A x64 ^
-DACTUAL_3RDPARTY_DIR=%ROOT_DIR%\windows-3rd-party/msvc140/3rdParty.x64 ^
-DCMAKE_RELWITHDEBINFO_POSTFIX:STRING= ^
-DOSG_USE_UTF8_FILENAME:BOOL=ON ^
-DWIN32_USE_MP:BOOL=ON ^
-DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
cmake --build . --config RelWithDebInfo --target INSTALL

cd %ROOT_DIR%\simgear-build
cmake %ROOT_DIR%\simgear -G %CMAKE_TOOLCHAIN% -A x64 ^
-DOSG_FSTREAM_EXPORT_FIXED:BOOL=ON ^
-DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
cmake --build . --config RelWithDebInfo --target INSTALL

cd %ROOT_DIR%\flightgear-build
cmake %ROOT_DIR%\flightgear -G %CMAKE_TOOLCHAIN% -A x64 ^
-DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install ^
-DCMAKE_PREFIX_PATH=%QT5SDK64% ^
-DOSG_FSTREAM_EXPORT_FIXED:BOOL=ON ^
-DENABLE_COMPOSITOR:BOOL=OFF

cmake --build . --config RelWithDebInfo --target INSTALL

pause

启动FlightGear

构建launch.bat批处理文件,启动FlightGear,其内容如下:

1
2
SET PATH=C:\path\to\FlightGearBuild\install\bin;C:\path\to\FlightGearBuild\windows-3rd-party\msvc140\3rdParty.x64\bin;C:\Qt\5.15.0\msvc2019_64\bin;%PATH%
fgfs.exe --launcher

参考链接

  1. Building using CMake - Windows,by flightgear.
  2. Visual Studio之RelWithDebInfo模式,“被忽视”的编译模式,by inter_peng.
  3. QT5.11下载与安装教程,by 杨书航.
  4. VS2017+Qt5.12环境搭建完美教程分享,by 小豆君的干货铺.