User:Legoboyvdlp/Building using CMake - Windows
See Building Flightgear for the main article about this subject. |
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
- Git to keep your build up to date. It also simplifies downloads of components. Optional, but can't recommend it enough!
Obtaining source
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
git clone https://git.code.sf.net/p/flightgear/flightgear flightgear-git
git clone https://git.code.sf.net/p/flightgear/fgdata data
The FGMETA scripts are optional but will help.
git clone https://git.code.sf.net/p/flightgear/fgmeta fgmeta
I would encourage people to access third party dependencies and OSG from Jenkins: you can build them if you wish, but it really is not needed.
prebuilt dependencies for 64 bit Windows (.zip)
Building OSG is so unreliable at building and linking properly that I would very strongly recommend you to use the pre-built version:
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. Source and build directories can be located anywhere.
32-bits
- ${MSVC_3RDPARTY_ROOT} /
- 3rdParty / ( includes plib, fltk, zlib, libpng, libjpeg, libtiff, freetype, libsvn, gdal, ... )
- bin /
- include /
- lib /
- Boost / (latest version can be downloaded from http://www.boost.org/)
- boost /
- lib /
- install /
- msvc140 / ( for VS2015 32 bits, or msvc100 for VS2010 32 bits, or msvc90 for VS2008 32-bits or newer versions of Visual Studio)
- OpenSceneGraph / ( OSG CMake install )
- bin /
- include /
- lib /
- SimGear / (create this empty for now, subfolders will be created by build process)
- include /
- lib /
- FlightGear / (create this empty for now)
- include /
- lib /
- OpenSceneGraph / ( OSG CMake install )
- msvc140 / ( for VS2015 32 bits, or msvc100 for VS2010 32 bits, or msvc90 for VS2008 32-bits or newer versions of Visual Studio)
- 3rdParty / ( includes plib, fltk, zlib, libpng, libjpeg, libtiff, freetype, libsvn, gdal, ... )
64-bits
- ${MSVC_3RDPARTY_ROOT} /
- 3rdParty.x64 /
- bin /
- include /
- lib /
- Boost / (latest version can be downloaded from http://www.boost.org/)
- boost /
- lib64 /
- install /
- msvc140-64 / ( for VS2015 64-bits, or msvc100-64 for VS2010 64-bits, or msvc90-64 for VS2008 64-bits )
- OpenSceneGraph / ( OSG CMake install )
- bin /
- include /
- lib /
- SimGear / (create this empty for now, subfolders will be created by build process)
- include /
- lib /
- FlightGear / (create this empty for now)
- include /
- lib /
- OpenSceneGraph / ( OSG CMake install )
- msvc140-64 / ( for VS2015 64-bits, or msvc100-64 for VS2010 64-bits, or msvc90-64 for VS2008 64-bits )
- 3rdParty.x64 /
Building
GUI compilation
- Set up a work directory as described above.
- Building SimGear
- Open the CMake gui.
- Set "Where is the source code" to wherever you put the SimGear sources (from the released tarball or the git repository).
- Set "Where to build the binaries" 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 . 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 14 2015 (or Visual Studio 14 2015 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 -NOTFOUND. 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 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 directory structure that is presented above. Then press again.
- Set the CMAKE_INSTALL_PREFIX variable to ${MSVC_3RDPARTY_ROOT}/install/msvc140/SimGear (msvc140-64 for 64-bit).
- 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 is enabled.
- Press .
- Start Visual Studio 2015 and open the SimGear solution (SimGear.sln) located in "Where to build the binaries".
- Choose the "Release" build in the toolbar. The right menu should read Win32 for 32-bits or x64 for 64-bits.
- 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, and .
- 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}
- Building FlightGear
- Repeat the steps under Building Simgear, but change the SimGear paths to FlightGear.
- Enjoy!
Script compilation
Firstly set up the directory structure as above. For the following scripts, the Windows environmental variable MSVC_3RDPARTY_ROOT
must be set to the full path where this is located.
SimGear
For building SimGear with MSVC 2015 as 64-bit:
.cmake.bat
script for configuring and compiling SimGearREM Configure.
cmake .. ^
-DMSVC_3RDPARTY_ROOT=%MSVC_3RDPARTY_ROOT% ^
-DCMAKE_INSTALL_PREFIX=%MSVC_3RDPARTY_ROOT%\install\msvc140-64\SimGear ^
-G "Visual Studio 14 2015 Win64"
REM Compile.
cmake --build . --target install
.cmake.bat
script for configuring and compiling SimGear (with debugging symbols)Place the script in a new directory within the SimGear sources such as build
. To clean up the build files, another batch file can be used:
.clean.bat
script for cleaning up the buildFlightGear
For building FlightGear with MSVC 2015 as 64-bit:
.cmake.bat
script for configuring and compiling FlightGearREM 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 2015 Win64"
REM Compile.
cmake --build . --target install
Note: change the CMAKE_PREFIX_PATH
variable to your Qt installation directory.
.cmake.bat
script for configuring and compiling FlightGear (with debugging symbols)Place the script in a new directory within the FlightGear sources such as build
. To clean up the build files, another batch file can be used:
.clean.bat
script for cleaning up the buildUpdating
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 CMakeCache.txt file in "Where to build the binaries” directory and delete it to reconfigure from scratch or use the menu item File > Delete Cache.
TerraGear
TerraGear can be built the same way as FlightGear, just change the paths to your TerraGear source and directories.
Jenkins Windows configurations
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
SimGear-Win
FlightGear-Win
External link
|