Building using CMake - Windows: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(Change to windows-3rd-party otherwise it won`t compilate)
(14 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Main article|Building Flightgear}}
{{Main article|Building Flightgear}}
This article is intended to give an overview of building FlightGear on modern Windows systems. It was created using Windows 10 and VS 2019. It ought to be transferrable to earlier versions of the Windows OS and software.
As FlightGear is now 64-bit only, the guide only describes building on a 64-bit system.


== Required software ==
== Required software ==
* [http://www.cmake.org CMake GUI]
* [https://cmake.org/download/ CMake for Windows]. Download and install the Windows Win64-x64 Installer.
* [https://www.visualstudio.com/vs/visual-studio-express/ Microsoft Visual Studio 2015 Express] (MSVC)
* [https://visualstudio.microsoft.com/downloads/ Microsoft Visual Studio 2019] (MSVC). The Community version is free. There is no need for the premium versions; none of their features are required to build FlightGear. The C++ compiler will not be installed by default. You either choose this component during installation or after installation by starting MSVC and trying to create a new C++ project. The one to download is "Desktop Development with C++". Make sure to have the last version of the Windows SDK and C++ Compiler checked. As of 08/10/2020, the latest version of the compiler is "MSVC 142 - VS 2019 C++ x64/86 build tools (v14.27)".
* [http://www.microsoft.com/en-us/download/details.aspx?id=8279 Microsoft Windows SDK] (only required for 64-bit builds)
* [https://www.qt.io/download-open-source/ Qt5] for the [[Integrated Qt5 Launcher]]. Download the online installer, and choose the version matching your toolchain of Visual Studio e.g. "Qt 5.15.1 --> MSVC 2019 64 bit". Any version past 5.9 will be fine; 5.15 recommended. Leave the default Developer and Designer Tools selection - these are needed for coding and compiling.
: If you get an error during the installation of the SDK, try uninstalling MSVC redist packages first, then installing the SDK without compilers and then finally re-installing MSVC.
* [https://git-scm.com/download/win Git] to keep your build up to date. It also simplifies downloads of components. Optional, but can't recommend it enough!
* Qt5 for the [[Integrated Qt5 Launcher]] (optional as of 03/2015)


== Obtaining source ==
== Obtaining source ==
{{Main article|FlightGear and Git}}
{{Main article|FlightGear and Git}}
Throughout this article it is assumed that you've already set up git clones of the various source repositories (FlightGear, SimGear, data...).
Throughout this article it is assumed that you have set up git clones of the various source repositories (FlightGear, SimGear, data...).
Using an organized directory (see below) will help significantly.


== Directory tree ==
The commands to run are:
On Windows, assumptions on the directory structure are made to automate the discovery of dependencies. This recommended directory structure is described below. Clicking the links allows you to download pre-built parts. If you do not use the recommended structure you will need to enter paths by hand. Source and build directories can be located anywhere.


=== 32-bits ===
{{code|git clone https://git.code.sf.net/p/flightgear/simgear simgear}}
<tt>
: ${MSVC_3RDPARTY_ROOT} /
:: {{build link|path=view/Windows/job/3rdParty-Win/lastSuccessfulBuild/artifact/3rdParty/*zip*/3rdParty.zip|text=3rdParty}} / </tt> ( includes plib, fltk, zlib, libpng, libjpeg, libtiff, freetype, libsvn, gdal, ... ) <tt>
::: bin /
::: include /
::: lib /
:: {{build link|path=view/Windows/job/Boost-Win/lastSuccessfulBuild/artifact/*zip*/archive.zip|text=Boost}} / </tt> (latest version can be downloaded from http://www.boost.org/) <tt>
::: boost /
::: lib /
:: install /
::: msvc140 / </tt> ( for VS2015 32 bits, or msvc100 for VS2010 32 bits, or msvc90 for VS2008 32-bits or newer versions of Visual Studio) <tt>
:::: {{build link|path=view/Windows/job/OSG-Win/lastSuccessfulBuild/artifact/install/msvc100/OpenSceneGraph/*zip*/OpenSceneGraph.zip|text=OpenSceneGraph}} / </tt> ( OSG CMake install ) <tt>
::::: bin /
::::: include /
::::: lib /
:::: SimGear / </tt> (create this empty for now, subfolders will be created by build process) <tt>
::::: include /
::::: lib /
:::: FlightGear / </tt> (create this empty for now) <tt>
::::: include /
::::: lib /</tt>


=== 64-bits ===
{{code|git clone https://git.code.sf.net/p/flightgear/flightgear flightgear}}
<tt>
: ${MSVC_3RDPARTY_ROOT} /
:: {{build link|path=view/Windows/job/3rdParty-Win/lastSuccessfulBuild/artifact/3rdParty.x64/*zip*/3rdParty.x64.zip|text=3rdParty.x64}} /
::: bin /
::: include /
::: lib /
:: {{build link|path=view/Windows/job/Boost-Win/lastSuccessfulBuild/artifact/*zip*/archive.zip|text=Boost}} /
::: boost /
::: lib64 /
:: install /
::: msvc140-64 / </tt> ( for VS2015 64-bits, or msvc100-64 for VS2010 64-bits, or msvc90-64 for VS2008 64-bits ) <tt>
:::: {{build link|path=view/Windows/job/OSG-Win/lastSuccessfulBuild/artifact/*zip*/archive.zip|text=OpenSceneGraph}} / </tt> ( OSG CMake install ) <tt>
::::: bin /
::::: include /
::::: lib /
:::: SimGear / </tt> (create this empty for now, subfolders will be created by build process) <tt>
::::: include /
::::: lib /
:::: FlightGear / </tt> (create this empty for now) <tt>
::::: include /
::::: lib /</tt>


NdT: glut is missing for the 64bits build, you can use [http://www.transmissionzero.co.uk/software/freeglut-devel/ freeglut].
{{code|git clone https://git.code.sf.net/p/flightgear/fgdata fgdata}}


== Building ==
{{code|git clone https://git.code.sf.net/p/flightgear/windows-3rd-party windows-3rd-party}}


=== GUI compilation ===
{{code|git clone -b fgfs-342-1 https://github.com/zakalawe/osg.git osg}}
# Set up a work directory as described above.
# '''Building SimGear'''
## Open the CMake gui.
## Set <tt>"Where is the source code"</tt> to wherever you put the SimGear sources (from the released tarball or the git repository).
## Set <tt>"Where to build the binaries"</tt> to a new empty directory (could be anywhere and any name, for example naming it simgear-build, at the same folder location as your unzipped SimGear source folder was put).
## Press [[File:CMake GUI Configure.png]]. The first time that the project is configured, CMake will bring up a window asking you to "Specify the generator for this project" i.e. which compiler you wish to use. Select Visual Studio 10 (or Visual Studio 10 Win64 for 64-bit), and press Finish. CMake will now do a check on your system and will produce a preliminary build configuration.
## CMake adds new configuration variables in red. Some have a value ending with <tt>-NOTFOUND</tt>. These variables should receive your attention. Some errors will prevent SimGear from building and others will simply invalidate some options without causing build errors.
### First check the <tt>MSVC_3RDPARTY_ROOT</tt> variable. If it is not set, chances are that there will be a lot of <tt>-NOTFOUND</tt> errors. Instead of trying to fix every error individually, set that variable to the location of the directory structure that is presented above. Then press [[File:CMake GUI Configure.png]] again.
### Set the  <tt>CMAKE_INSTALL_PREFIX</tt> variable to <tt>${MSVC_3RDPARTY_ROOT}/install/msvc140/SimGear</tt>.
### Also check the lines with a checkbox. These are build options and may impact the feature set of the built program.
## Repeat the process from step 5, until [[File:CMake GUI Generate.png]] is enabled.
## Press [[File:CMake GUI Generate.png]].
## Start Visual Studio 2015 and open the SimGear solution (SimGear.sln) located in <tt>"Where to build the binaries"</tt>.
## Choose the <tt>"Release"</tt> build in the toolbar. The right menu should read Win32 for 32-bits or x64 for 64-bits. [[File:MVSC 2010 solution.png|right]]
## Generate the solution with F7 key or right-click the top level "Solution SimGear" in the Solution Explorer and choose Build.
## If there are build errors, return to CMake, clear remaining errors, [[File:CMake GUI Configure.png]] and [[File:CMake GUI Generate.png]].
## When Visual Studio is able to build everything without errors, right-click on the <tt>INSTALL</tt> project (further down within the "Solution Simgear" solution) and choose Build, which will put the include and lib files in <tt>${CMAKE_INSTALL_PREFIX}</tt>
# '''Building FlightGear'''
#: Repeat the steps under Building Simgear, but change the <tt>SimGear</tt> paths to <tt>FlightGear</tt>.
# Enjoy!


=== Script compilation ===


Firstly set up the directory structure as above.  For the following scripts, the Windows environmental variable <code>MSVC_3RDPARTY_ROOT</code> must be set to the full path where this is located.
After downloading these, I would suggest assembling a folder structure as below:


==== SimGear ====
== Directory Tree ==
On Windows, assumptions on the directory structure are made to automate the discovery of dependencies. This recommended directory structure is described below. Clicking the links allows you to download pre-built parts. If you do not use the recommended structure you will need to enter paths by hand and some parts may not input correctly.


For building SimGear with MSVC 2015 as 64-bit:
<tt>
: FlightGearBuild / </tt> (Main root directory) <tt>
:: fgdata / </tt> (FlightGear data files) <tt>
:: flightgear / </tt> (FlightGear sources) <tt>
:: install / </tt> (Directory where you will install the built binaries to)
::: launch.bat / </tt> (launch script if desired, see below)
:: osg / </tt> (OSG sources) <tt>
:: simgear / </tt> (SimGear sources) <tt>
:: windows-3rd-party /
:: build.bat / </tt> (build script, see below)
:: update.bat / </tt> (update script, see below)


== Building ==
=== Scripted Compilation ===
This script will allow you to build OpenSceneGraph, SimGear and FlightGear automatically.
{{collapsible script
{{collapsible script
| type  = Windows batch file
| type  = Windows batch file
| title  = The <code>.cmake.bat</code> script for configuring and compiling SimGear
| title  = The <code>build.bat</code> script for configuring and compiling OSG, SG, and FG
| lang  = batch
| lang  = batch
| script = REM Configure.
| script =
cmake .. ^
SET PATH=%PATH%;%ProgramFiles%\CMake\bin
-DMSVC_3RDPARTY_ROOT=%MSVC_3RDPARTY_ROOT% ^
SET QT5SDK64=C:\Qt\5.15.0\msvc2019_64
-DCMAKE_INSTALL_PREFIX=%MSVC_3RDPARTY_ROOT%\install\msvc140-64\SimGear ^
SET CMAKE_TOOLCHAIN="Visual Studio 16 2019"
-G"Visual Studio 14 Win64"
SET ROOT_DIR=C:\path\to\FlightGearBuild


REM Compile.
md osg-build
cmake --build . --target install
md simgear-build
| show  = 1
md flightgear-build
}}


{{collapsible script
cd %ROOT_DIR%\osg-build
| type  = Windows batch file
| title  = The <code>.cmake.bat</code> script for configuring and compiling SimGear (with debugging symbols)
| lang  = batch
| script = REM Configure.
cmake .. ^
-DMSVC_3RDPARTY_ROOT=%MSVC_3RDPARTY_ROOT% ^
-DCMAKE_INSTALL_PREFIX=%MSVC_3RDPARTY_ROOT%\install\msvc140-64\SimGear ^
-G"Visual Studio 14 Win64"


REM Compile.
cmake  %ROOT_DIR%\osg -G  %CMAKE_TOOLCHAIN% -A x64 ^
cmake --build . --config RelWithDebInfo --target install
                -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


Place the script in a new directory within the SimGear sources such as <code>build</code>. To clean up the build files, another batch file can be used:
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


{{collapsible script
cd %ROOT_DIR%\flightgear-build
| type  = Windows batch file
cmake  %ROOT_DIR%\flightgear -G  %CMAKE_TOOLCHAIN% -A x64 ^
| title  = The <code>.clean.bat</code> script for cleaning up the build
                  -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install ^
| lang  = batch
                  -DCMAKE_PREFIX_PATH=%QT5SDK64% ^
| script = @echo off
                  -DOSG_FSTREAM_EXPORT_FIXED:BOOL=ON ^
rm -rf [0-9A-Za-z]* .vs
                  -DENABLE_COMPOSITOR:BOOL=OFF
}}
                   
cmake --build . --config RelWithDebInfo --target INSTALL


==== FlightGear ====
pause
 
| show = 1
For building FlightGear with MSVC 2015 as 64-bit:
 
{{collapsible script
| type  = Windows batch file
| title = The <code>.cmake.bat</code> script for configuring and compiling FlightGear
| lang  = batch
| script = REM Configure.
cmake .. ^
-DMSVC_3RDPARTY_ROOT=%MSVC_3RDPARTY_ROOT% ^
-DCMAKE_INSTALL_PREFIX=%MSVC_3RDPARTY_ROOT%\install\msvc140-64\FlightGear ^
-DCMAKE_PREFIX_PATH=D:\Qt\Qt5.6.2\5.6\msvc2015_64\ ^
-G"Visual Studio 14 Win64"
 
REM Compile.
cmake --build . --target install
| conc = Note: change the <code>CMAKE_PREFIX_PATH</code> variable to your Qt installation directory.
}}
 
{{collapsible script
| type  = Windows batch file
| title  = The <code>.cmake.bat</code> script for configuring and compiling FlightGear (with debugging symbols)
| lang  = batch
| script = REM Configure.
cmake .. ^
-DMSVC_3RDPARTY_ROOT=%MSVC_3RDPARTY_ROOT% ^
-DCMAKE_INSTALL_PREFIX=%MSVC_3RDPARTY_ROOT%\install\msvc140-64\FlightGear ^
-DCMAKE_PREFIX_PATH=D:\Qt\Qt5.6.2\5.6\msvc2015_64\ ^
-G"Visual Studio 14 Win64"
 
REM Compile.
cmake --build . --config RelWithDebInfo --target install
| conc = Note: change the <code>CMAKE_PREFIX_PATH</code> variable to your Qt installation directory.
}}
 
Place the script in a new directory within the FlightGear sources such as <code>build</code>.  To clean up the build files, another batch file can be used:
 
{{collapsible script
| type  = Windows batch file
| title  = The <code>.clean.bat</code> script for cleaning up the build
| lang  = batch
| script = @echo off
rm -rf [0-9A-Za-z]* .vs
}}
}}


=== Updating ===
Before starting to use the script, you need to edit the top few lines of the script. You will have to:
When updating the source from [[git]], it is usually unnecessary to restart CMake as the solution is able to reconfigure itself when CMake files are changed. Simply rebuild the solution from Visual Studio and accept the reload of updated projects. When the Simgear/FlightGear version numbers change, you do have to re-run CMake.
 
It is also possible to edit CMakeList.txt files directly in Visual Studio as they also appear in the solution, and projects will be reconfigured on the next generation. To change build options or directory path, it is mandatory to use the CMake Gui. In case of problems, locate the <tt>CMakeCache.txt</tt> file in <tt>"Where to build the binaries”</tt> directory and delete it to reconfigure from scratch or use the menu item <tt>File > Delete Cache</tt>.


=== TerraGear ===
1. Set the path to your CMake installation.
TerraGear can be built the same way as FlightGear, just change the paths to your TerraGear source and directories.


== Jenkins Windows configurations ==
2. Ensure that the path to your QT SDK is correct for your version of MSVC.
When using CMake GUI, you can add those entries by clicking the Add entry button. Note that you should omit the -D prefix.


=== OSG-Win ===
3. Ensure your toolchain version matches, e.g. "Visual Studio 16 2019" for MSVC 2019 or "Visual Studio 15 2017" for MSVC 2017.
{{collapsible script
| type  = Windows batch file
| title  = Reconstructed Jenkins build script (32-bit).
| lang  = batch
| intro  = This script has been rebuilt from the output of http://build.flightgear.org:8080/job/OSG-Win/lastBuild/consoleText, with comments added.
| script = REM Set up.
cd %WORKSPACE%
md build32
cd build32
del CMakeCache.txt


REM Configure.
4. Set ROOT_DIR to the FlightgearBuild folder you created (the above directory structure)
cmake ..\source ^
-G "Visual Studio 14 2015" ^
-DOSG_USE_QT:BOOL=OFF ^
-DBUILD_OSG_APPLICATIONS:BOOL=ON ^
-DOSG_USE_UTF8_FILENAME:BOOL=ON ^
-DACTUAL_3RDPARTY_DIR:PATH=%WORKSPACE%\3rdParty ^
-DCURL_INCLUDE_DIR:PATH=%WORKSPACE%\3rdParty\include ^
-DTIFF_INCLUDE_DIR:PATH=%WORKSPACE%\3rdParty\include ^
-DTIFF_LIBRARY:FILEPATH=%WORKSPACE%\3rdParty\lib\libtiff.lib ^
-DOSG_PLUGIN_SEARCH_INSTALL_DIR_FOR_PLUGINS:BOOL=OFF ^
-DCURL_LIBRARY:FILEPATH=%WORKSPACE%\3rdParty\lib\libcurl.lib ^
-DFREETYPE_LIBRARY:FILEPATH=%WORKSPACE%\3rdParty\lib\freetype.lib ^
-DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%\install\msvc140\OpenSceneGraph ^
-DFREETYPE_INCLUDE_DIR:PATH=%WORKSPACE%\3rdParty\include;%WORKSPACE%\3rdParty\include\freetype


REM Compile.
==== Post-compilation: Launching FlightGear ====
cmake --build . --config Release --target INSTALL
'''In the debugger:'''
| conc  = The <code>WORKSPACE</code> variable is a Windows environmental variable.
Open flightgear-build/FlightGear.sln. You can then perform all your development / debugging directly in VS. You normally only need to run build.bat again, if you update SimGear or OSG.  
}}


{{collapsible script
To launch FlightGear from Visual Studio, you can follow the following steps:
| type  = Windows batch file
The first time only:
| title  = Reconstructed Jenkins build script (64-bit).
# Make sure you set your build type to RelWithDebInfo in the top bar.
| lang  = batch
# To start with the launcher, click on the small black arrow beside Local Windows Debugger to open 'fgfs debug properties'. Switch to debugging; add {{code|--launcher}} to the 'Command Arguments'. Click Apply and then OK.
| intro  = This script has been rebuilt from the output of http://build.flightgear.org:8080/job/OSG-Win/lastBuild/consoleText, with comments added.
# Press the green arrow (Local Windows Debugger) to start up FlightGear.  
| script = REM Set up.
# The first time you'll have to choose where FGDATA is -- to do this, select the 'fgdata' directory you cloned at the start.
cd %WORKSPACE%
md build64
cd build64
del CMakeCache.txt


REM Configure.
Therafter, simply press the green arrow directly each time you want to start. If there are any local changes, it will recompile; alternatively it will start up directly. It will take a little longer to start as it loads symbols; however you also have the benefit that any segfaults will be caught allowing you to report them!
cmake ..\source ^
-G "Visual Studio 14 2015 Win64" ^
-DOSG_USE_QT:BOOL=OFF ^
-DBUILD_OSG_APPLICATIONS:BOOL=ON ^
-DACTUAL_3RDPARTY_DIR:PATH=%WORKSPACE%\3rdParty.x64 ^
-DCURL_INCLUDE_DIR:PATH=%WORKSPACE%\3rdParty.x64/include ^
-DTIFF_INCLUDE_DIR:PATH=%WORKSPACE%\3rdParty.x64/include ^
-DTIFF_LIBRARY:FILEPATH=%WORKSPACE%\3rdParty.x64/lib/libtiff.lib ^
-DOSG_PLUGIN_SEARCH_INSTALL_DIR_FOR_PLUGINS:BOOL=OFF ^
-DCURL_LIBRARY:FILEPATH=%WORKSPACE%\3rdParty.x64/lib/libcurl.lib ^
-DFREETYPE_LIBRARY:FILEPATH=%WORKSPACE%\3rdParty.x64/lib/freetype.lib ^
-DFREETYPE_INCLUDE_DIR:PATH=%WORKSPACE%\3rdParty.x64/include;%WORKSPACE%\3rdParty.x64/include/freetype ^
-DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%/install/msvc140-64/OpenSceneGraph


REM Compile.
'''As a standard .exe:'''
cmake --build . --config Release --target INSTALL
NB these instructions overall are intended for setting up for development; there's a slightly more convoluted process for setting up for just plain flying (e.g. taking advantage of new features for aircraft development).
| conc  = The <code>WORKSPACE</code> variable is a Windows environmental variable.
}}


=== SimGear-Win ===
Essentially, Visual Studio doesn't copy in the DLLs into the /bin/ folder. It's also not ideal to manually copy in the DLLS as it can cause all sorts of issues. However, without the DLLs FlightGear won't work; therefore, you need to set the PATH so it knows where to look for them.
This launch script should work, put into your /install/bin/ folder:
{{collapsible script
{{collapsible script
| type  = Windows batch file
| type  = Windows batch file
| title  = Reconstructed Jenkins build script (32-bit).
| title  = The <code>launch.bat</code> script for launching flightgear
| lang  = batch
| lang  = batch
| intro  = This script has been rebuilt from the output of http://build.flightgear.org:8080/job/SimGear-Win/lastBuild/consoleText, with comments added.
| script =
| script = REM Set up.
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%
cd %WORKSPACE%
fgfs.exe --launcher
md build32
| show  = 1
cd build32
del CMakeCache.txt
 
REM Configure.
cmake ..\source ^
-DENABLE_RTI=ON ^
-G "Visual Studio 14 2015" ^
-DMSVC_3RDPARTY_ROOT=%WORKSPACE% ^
-DBOOST_ROOT=%WORKSPACE% ^
-DENABLE_DNS=1 ^
-DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%/install/msvc140/SimGear
 
REM Compile.
cmake --build . --config RelWithDebInfo --target INSTALL
| conc  = The <code>WORKSPACE</code> variable is a Windows environmental variable.
}}
}}


{{collapsible script
Adjust the "path\to" references to suit your own personal installation, as well as the QT5 path.
| type  = Windows batch file
| title  = Reconstructed Jenkins build script (64-bit).
| lang  = batch
| intro  = This script has been rebuilt from the output of http://build.flightgear.org:8080/job/SimGear-Win/lastBuild/consoleText, with comments added.
| script = REM Set up.
cd %WORKSPACE%
md build64
cd build64
del CMakeCache.txt


REM Configure.
=== Updating ===
cmake ..\source ^
To update FlightGear, in general, just run ''git pull'' on the source directories and then re-run the build.bat script -- it will update what it needs to, relatively quickly.
-DENABLE_RTI=ON ^
-G "Visual Studio 14 2015 Win64" ^
-DMSVC_3RDPARTY_ROOT=%WORKSPACE% ^
-DBOOST_ROOT=%WORKSPACE% ^
-DENABLE_DNS=1 ^
-DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%/install/msvc140-64/SimGear
 
REM Compile.
cmake --build . --config RelWithDebInfo --target INSTALL
| conc  = The <code>WORKSPACE</code> variable is a Windows environmental variable.
}}
 
=== FlightGear-Win ===
 
{{collapsible script
| type  = Windows batch file
| title  = Reconstructed Jenkins build script (32-bit).
| lang  = batch
| intro  = This script has been rebuilt from the output of http://build.flightgear.org:8080/job/FlightGear-Win/lastBuild/consoleText, with comments added.
| script = REM Set up.
cd %WORKSPACE%
md build32
cd build32
del CMakeCache.txt
 
REM Configure.
cmake ..\source ^
-G "Visual Studio 14 2015" ^
-DENABLE_PROFILE=OFF ^
-DBOOST_ROOT:PATH=%WORKSPACE%/Boost ^
-DMSVC_3RDPARTY_ROOT:PATH=%WORKSPACE% ^
-DCMAKE_PREFIX_PATH:PATH="D:\Qt\5.6\msvc2015" ^
-DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%/install/msvc140/FlightGear
 
REM Compile.
cmake --build . --config RelWithDebInfo --target INSTALL
| conc  = The <code>WORKSPACE</code> variable is a Windows environmental variable.
}}
 
{{collapsible script
| type  = Windows batch file
| title  = Reconstructed Jenkins build script (64-bit).
| lang  = batch
| intro  = This script has been rebuilt from the output of http://build.flightgear.org:8080/job/FlightGear-Win/lastBuild/consoleText, with comments added.
| script = REM Set up.
cd %WORKSPACE%
md build64
cd build64
del CMakeCache.txt
 
REM Configure.
cmake ..\source ^
-G "Visual Studio 14 2015 Win64" ^
-DENABLE_PROFILE=OFF ^
-DWITH_FGPANEL:BOOL=OFF ^
-DBOOST_ROOT:PATH=%WORKSPACE%/Boost ^
-DMSVC_3RDPARTY_ROOT:PATH=%WORKSPACE% ^
-DCMAKE_PREFIX_PATH:PATH="D:\Qt\5.6\msvc2015_64" ^
-DFLTK_FLUID_EXECUTABLE:FILEPATH=%WORKSPACE%/3rdParty/bin/fluid.exe ^
-DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%/install/msvc140-64/FlightGear
 
REM Compile.
cmake --build . --config RelWithDebInfo --target INSTALL
| conc  = The <code>WORKSPACE</code> variable is a Windows environmental variable.
}}


=== FGRun-Win-CMake ===
=== Changing the Configuration ===
cmake ..\svn -G "Visual Studio 10"
When the Simgear/FlightGear version numbers change, or you change configuration options (e.g. toggling Compositor, changing OSG versions, changing QT versions) you do have to re-configure in CMake. To do this, it's usually safest to delete the simgear-build and flightgear-build folders and re-run the build.bat script, to ensure the build is clean. There is no need to delete osg-build unless changing OSG version.
      -DMSVC_3RDPARTY_ROOT:PATH=%WORKSPACE%
      -DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%/install/msvc100/FGRun
      -DFLTK_FLUID_EXECUTABLE:FILEPATH=%WORKSPACE%/3rdParty/bin/fluid.exe
      -DGETTEXT_MSGFMT_EXECUTABLE:FILEPATH=%WORKSPACE%/3rdParty/bin/msgfmt.exe
      -DGETTEXT_MSGMERGE_EXECUTABLE:FILEPATH=%WORKSPACE%/3rdParty/bin/msgmerge.exe
=== TerraGear-Win-CMake ===
  cmake ..\TerraGear -G "Visual Studio 10"
      -DMSVC_3RDPARTY_ROOT=%WORKSPACE%
      -DCMAKE_INSTALL_PREFIX:PATH=%WORKSPACE%/install/msvc100/TerraGear
      -DGPC_LIBRARY=%WORKSPACE%/3rdParty/lib/gpc232.lib
      -DNEWMAT_LIBRARY=%WORKSPACE%/3rdParty/lib/newmat11.lib


== External link ==
In case of problems, most of the time deleting the simgear-build and flightgear-build folders and re-running the build.bat script will be sufficient.
* {{flightgear file|docs-mini/README.MSVC}}


{{building}}
{{building}}
[[fr:compiler flightear avec CMake - Windows]]
[[fr:compiler flightear avec CMake - Windows]]
[[Category:Windows specific]]
[[Category:Windows specific]]
[[Category:Hackathon Materials]]

Revision as of 11:48, 13 December 2020

1rightarrow.png See Building Flightgear for the main article about this subject.

This article is intended to give an overview of building FlightGear on modern Windows systems. It was created using Windows 10 and VS 2019. It ought to be transferrable to earlier versions of the Windows OS and software.

As FlightGear is now 64-bit only, the guide only describes building on a 64-bit system.

Required software

  • CMake for Windows. Download and install the Windows Win64-x64 Installer.
  • Microsoft Visual Studio 2019 (MSVC). The Community version is free. There is no need for the premium versions; none of their features are required to build FlightGear. The C++ compiler will not be installed by default. You either choose this component during installation or after installation by starting MSVC and trying to create a new C++ project. The one to download is "Desktop Development with C++". Make sure to have the last version of the Windows SDK and C++ Compiler checked. As of 08/10/2020, the latest version of the compiler is "MSVC 142 - VS 2019 C++ x64/86 build tools (v14.27)".
  • Qt5 for the Integrated Qt5 Launcher. Download the online installer, and choose the version matching your toolchain of Visual Studio e.g. "Qt 5.15.1 --> MSVC 2019 64 bit". Any version past 5.9 will be fine; 5.15 recommended. Leave the default Developer and Designer Tools selection - these are needed for coding and compiling.
  • Git to keep your build up to date. It also simplifies downloads of components. Optional, but can't recommend it enough!

Obtaining source

1rightarrow.png See FlightGear and Git for the main article about this subject.

Throughout this article it is assumed that you have set up git clones of the various source repositories (FlightGear, SimGear, data...). Using an organized directory (see below) will help significantly.

The commands to run are:

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


After downloading these, I would suggest assembling a folder structure as below:

Directory Tree

On Windows, assumptions on the directory structure are made to automate the discovery of dependencies. This recommended directory structure is described below. Clicking the links allows you to download pre-built parts. If you do not use the recommended structure you will need to enter paths by hand and some parts may not input correctly.

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)

Building

Scripted Compilation

This script will allow you to build OpenSceneGraph, SimGear and FlightGear automatically.

Before starting to use the script, you need to edit the top few lines of the script. You will have to:

1. Set the path to your CMake installation.

2. Ensure that the path to your QT SDK is correct for your version of MSVC.

3. Ensure your toolchain version matches, e.g. "Visual Studio 16 2019" for MSVC 2019 or "Visual Studio 15 2017" for MSVC 2017.

4. Set ROOT_DIR to the FlightgearBuild folder you created (the above directory structure)

Post-compilation: Launching FlightGear

In the debugger: Open flightgear-build/FlightGear.sln. You can then perform all your development / debugging directly in VS. You normally only need to run build.bat again, if you update SimGear or OSG.

To launch FlightGear from Visual Studio, you can follow the following steps: The first time only:

  1. Make sure you set your build type to RelWithDebInfo in the top bar.
  2. To start with the launcher, click on the small black arrow beside Local Windows Debugger to open 'fgfs debug properties'. Switch to debugging; add --launcher to the 'Command Arguments'. Click Apply and then OK.
  3. Press the green arrow (Local Windows Debugger) to start up FlightGear.
  4. The first time you'll have to choose where FGDATA is -- to do this, select the 'fgdata' directory you cloned at the start.

Therafter, simply press the green arrow directly each time you want to start. If there are any local changes, it will recompile; alternatively it will start up directly. It will take a little longer to start as it loads symbols; however you also have the benefit that any segfaults will be caught allowing you to report them!

As a standard .exe: NB these instructions overall are intended for setting up for development; there's a slightly more convoluted process for setting up for just plain flying (e.g. taking advantage of new features for aircraft development).

Essentially, Visual Studio doesn't copy in the DLLs into the /bin/ folder. It's also not ideal to manually copy in the DLLS as it can cause all sorts of issues. However, without the DLLs FlightGear won't work; therefore, you need to set the PATH so it knows where to look for them. This launch script should work, put into your /install/bin/ folder:

Adjust the "path\to" references to suit your own personal installation, as well as the QT5 path.

Updating

To update FlightGear, in general, just run git pull on the source directories and then re-run the build.bat script -- it will update what it needs to, relatively quickly.

Changing the Configuration

When the Simgear/FlightGear version numbers change, or you change configuration options (e.g. toggling Compositor, changing OSG versions, changing QT versions) you do have to re-configure in CMake. To do this, it's usually safest to delete the simgear-build and flightgear-build folders and re-run the build.bat script, to ensure the build is clean. There is no need to delete osg-build unless changing OSG version.

In case of problems, most of the time deleting the simgear-build and flightgear-build folders and re-running the build.bat script will be sufficient.