Difference between revisions of "User:Legoboyvdlp/Building using CMake - Windows"

From FlightGear wiki
Jump to: navigation, search
(Directory Tree)
(Scripted Compilation)
 
(2 intermediate revisions by the same user not shown)
Line 92: Line 92:
 
}}
 
}}
  
Before starting to use the script, you need to:
+
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 CMAKE
+
1. Set the path to your CMake installation.
  
2. Set the path to the QT5 SDK
+
2. Ensure that the path to your QT SDK is correct for your version of MSVC.
  
3. Set your toolchain, e.g. "Visual Studio 16 2019"
+
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)
 
4. Set ROOT_DIR to the FlightgearBuild folder you created (the above directory structure)
  
==== Post-compilation ====
+
==== 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.  
 
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  
+
To launch FlightGear from Visual Studio, you can follow the following steps:
The first time you do this follow the following steps:
+
The first time only:
 
# Make sure you set your build type to RelWithDebInfo in the top bar.
 
# Make sure you set your build type to RelWithDebInfo in the top bar.
 
# 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.
 
# 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.
# Press the green arrow (Local Windows Debugger) to start up FlightGear. 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!
+
# Press the green arrow (Local Windows Debugger) to start up FlightGear.  
 
# The first time you'll have to choose where FGDATA is -- to do this, select the 'fgdata' directory you cloned at the start.
 
# The first time you'll have to choose where FGDATA is -- to do this, select the 'fgdata' directory you cloned at the start.
  
NB these instructions 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).
+
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.
 
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.
Line 130: Line 133:
  
 
=== Updating ===
 
=== Updating ===
When updating the source from [[git]], it is usually unnecessary to reconfigure in cmake as the solution is able to reconfigure itself when CMake files are changed. You can either simply open the .sln file in Visual Studio and accept the reload of updated projeccts, and rebuild the project in Visual Studio directly without needing to reconfigure, or alternatively use this script:
+
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.
{{collapsible script
+
| type  = Windows batch file
+
| title  = The <code>update.bat</code> script for updating OSG, SG, and FG all at once.
+
| lang  = batch
+
| script =
+
 
+
SET PATH=%PATH%;%ProgramFiles%\CMake\bin
+
SET ROOT_DIR=C:\path\to\FlightGearBuild
+
 
+
cd %ROOT_DIR%\osg-build
+
cmake --build . --config RelWithDebInfo --target INSTALL
+
 
+
cd %ROOT_DIR%\simgear-build
+
cmake --build . --config RelWithDebInfo --target INSTALL
+
 
+
cd %ROOT_DIR%\flightgear-build
+
cmake --build . --config RelWithDebInfo --target INSTALL
+
 
+
pause
+
| show  = 1
+
}}
+
 
+
Modify the \path\to refer to your own FlightGearBuild directory.
+
 
+
You could even modify the above script to automatically run ''git pull'' on the source folders.
+
  
When the Simgear/FlightGear version numbers change, you do have to re-configure in CMake.
+
=== 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.
  
To change build options or directory path, it is mandatory to reconfigure in CMake. In case of problems, locate the <tt>CMakeCache.txt</tt> file in build directory and delete it to reconfigure from scratch or use the menu item in the CMake GUI <tt>File > Delete Cache</tt>.
+
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.
  
 
{{building}}
 
{{building}}
 
[[fr:compiler flightear avec CMake - Windows]]
 
[[fr:compiler flightear avec CMake - Windows]]
 
[[Category:Windows specific]]
 
[[Category:Windows specific]]

Latest revision as of 08:42, 22 October 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-deps /
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.