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

From FlightGear wiki
Jump to navigation Jump to search
Line 156: Line 156:


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>.
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>.
=== TerraGear ===
TerraGear can be built the same way as FlightGear, just change the paths to your TerraGear source and directories.


== External link ==
== External link ==

Revision as of 16:22, 20 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)
osg / (OSG sources)
simgear / (SimGear sources)
windows-3rd-party-deps /
build.bat / (build script, see below)

Building

GUI compilation

  1. Set up a work directory as described above or to your own personal preference.
  2. Having downloaded the sources into the Source directory, and all the prebuilt dependencies, continue below:
  3. Building SimGear
    1. Open the CMake gui.
    2. Set "Where is the source code" to the Source/simgear-git directory.
    3. Set "Where to build the binaries" to the empty directory simgear-build in the BuildDirs directory.
    4. Press 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 16 2019 (or the respective version for your own copy of Visual Studio), and press Finish. CMake will now do a check on your system and will produce a preliminary build configuration.
      Shows how to select compiler
    5. CMake adds new configuration variables in red. Some have a value ending with -NOTFOUND. These variables do not necessarily need a value. Some errors will prevent SimGear from building and others will simply invalidate some options without causing build errors and thus can be ignored.
      1. First check the MSVC_3RDPARTY_ROOT variable. If it is not set, chances are that there will be a lot of -NOTFOUND errors. Instead of trying to fix every error individually, set that variable to the location of the \Dependencies folder in the directory structure that is presented above. Then press CMake GUI Configure.png again.
        Demonstrates how to set 3d party root in CMAKE gui
      2. Set the CMAKE_INSTALL_PREFIX variable to \install\Simgear
      3. Set the Boost_INCLUDE_DIR variable to \Dependencies
      4. To pick up Boost correctly, you must add a new Cache entry, using CMake GUI AddButton.png with name BOOST_ROOT, type PATH, and value \Dependencies. It is not required to set Boost_DIR to any value.
        Demonstrates how to add Boost in CMAKE GUI
      5. Create a second cache entry, called CMAKE_PREFIX_PATH, type PATH and value \Dependencies\install\msvc140-64\OpenSceneGraph. This will allow OSG to be picked up automatically.
      6. Also verify the lines with a checkbox. These are build options and may impact the feature set of the built program.
      7. Default options, for anything else, should more or less be suitable. One exception is to ensure OSG_FSTREAM_EXPORT_FIXED is set to true for faster linking.
    6. Repeat the process from step 5, until CMake GUI Generate.png is enabled.
    7. Press CMake GUI Generate.png.
    8. Press CMake GUI OpenProject.png.
    9. Choose the "RelWithDebInfo" build in the toolbar. The right menu should read x64 for 64-bits.
      MVSC 2019 solution.PNG
    10. Generate the solution with F7 key or right-click the top level "Solution SimGear" in the Solution Explorer and choose Build. It should take ~20 minutes on average hardware.
    11. If there are build errors, return to CMake, clear remaining errors, CMake GUI Configure.png and CMake GUI Generate.png.
    12. When Visual Studio is able to build everything without errors, right-click on the INSTALL project (further down within the "Solution Simgear" solution) and choose Build, which will put the include and lib files in ${CMAKE_INSTALL_PREFIX}. This should only take a few seconds as you have already compiled everything.
      Demonstrates building INSTALL project in MSVC
  4. Building FlightGear
    Repeat the steps under Building Simgear, but change the SimGear paths to FlightGear.
    1. Set CMAKE_INSTALL_PREFIX to \install\FlightGear
    2. Link Simgear to FlightGear using Simgear_DIR, pointing to \install\Simgear\lib\cmake\SimGear
      Demonstrates how to link Simgear to FlightGear
    3. Notably, you will have to link QT5 to CMAKE_PREFIX_PATH in addition to OSG (as with Simgear). To do this, insert the directory values with a semi-colon to separate them. for instance QT5PATH;OSGPATH.
      1. QT5: C:/Qt/5.15.0/msvc2019_64 (adjust to match your QT installation).
      2. My personal final path was: C:/Users/redpa/Documents/FlightGear/fg-from-scratch/fresh-build/Dependencies/install/msvc140 64/OpenSceneGraph;C:/Qt/5.15.0/msvc2019_64
  5. Post-compilation steps:
    1. Install QT5 using WinDeployQT: this program is contained within the QT installation. For me, I found it inside C:\Qt\5.15.0\msvc2019_64\bin. Run it in a cmd window, with the console options as required. This pulls in all the necessary QT files.
    2. Install .dlls:
      1. either manually copy in to the install/FlightGear/bin/ folder
      2. or, preferrably, add the directories containing them to %PATH% environment variable.
        1. Dependencies\3rdParty.x64\bin
        2. Dependencies\install\msvc140-64\OpenSceneGraph\bin
    3. Enjoy!

Scripted Compilation

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

Before starting to use the script, you need to:

1. Set the path to CMAKE

2. Set the path to the QT5 SDK

3. Set your toolchain, e.g. "Visual Studio 16 2019"

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

Post-compilation

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 The first time you do this follow the following steps:

  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. 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!
  4. 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).

Updating

When updating the source from git, it is usually unnecessary to rerun 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-configure in CMake.

To change build options or directory path, it is mandatory to reconfigure in CMake. In case of problems, locate the CMakeCache.txt file in build directory and delete it to reconfigure from scratch or use the menu item in the CMake GUIFile > Delete Cache.

External link