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

Jump to navigation Jump to search
No edit summary
(37 intermediate revisions by the same user not shown)
Line 23: Line 23:
{{code|git clone https://git.code.sf.net/p/flightgear/fgdata data}}
{{code|git clone https://git.code.sf.net/p/flightgear/fgdata data}}


The FGMETA scripts are optional but will help.
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. There is no advantage to doing that -- it only takes longer.
 
{{code|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.


[http://build.flightgear.org:8080/job/3rdParty-Win/lastSuccessfulBuild/artifact/3rdParty.x64/*zip*/3rdParty.x64.zip prebuilt dependencies for 64 bit Windows (.zip)]
[http://build.flightgear.org:8080/job/3rdParty-Win/lastSuccessfulBuild/artifact/3rdParty.x64/*zip*/3rdParty.x64.zip prebuilt dependencies for 64 bit Windows (.zip)]
Line 34: Line 29:
[http://build.flightgear.org:8080/job/3rdParty-Win/lastSuccessfulBuild/artifact/boost/*zip*/boost.zip prebuilt Boost library (.zip)]
[http://build.flightgear.org:8080/job/3rdParty-Win/lastSuccessfulBuild/artifact/boost/*zip*/boost.zip prebuilt Boost library (.zip)]


Building OSG is so unreliable at building and linking properly that I would very strongly recommend you to use the pre-built version:  
OSG is so unreliable at building and linking properly that I would very strongly recommend you to use the pre-built version: download this folder, and copy the <tt>archive/install/msvc140-64/OpenSceneGraph</tt> folder into the directory structure shown below.


[http://build.flightgear.org:8080/job/OSG-Win/lastSuccessfulBuild/artifact/*zip*/archive.zip prebuilt OSG for Windows x64]
[http://build.flightgear.org:8080/job/OSG-Win/lastSuccessfulBuild/artifact/*zip*/archive.zip prebuilt OSG for Windows x64]
Line 44: Line 39:


<tt>
<tt>
: ${MSVC_3RDPARTY_ROOT} /
: Dependencies / </tt> (Set <tt>${MSVC_3RDPARTY_ROOT}</tt> to this directory) <tt>
:: {{build link|path=view/Windows/job/3rdParty-Win/lastSuccessfulBuild/artifact/3rdParty.x64/*zip*/3rdParty.x64.zip|text=3rdParty.x64}} /
:: 3rdParty.x64 / </tt> (link above) <tt>
::: bin /
::: bin /
::: include /
::: include /
::: lib /
::: lib /
:: Boost / </tt> (latest version can be downloaded from http://www.boost.org/) <tt>
:: Boost / </tt> (link above) <tt>
::: boost /
::: {boost libs} /
::: lib64 /
:: install /
:: install /
::: msvc140-64 / </tt> ( for VS2015 64-bits, or msvc100-64 for VS2010 64-bits, or msvc90-64 for VS2008 64-bits ) <tt>
::: msvc140-64 / </tt> (i.e. MSVC version 14.0 or later for 64 bit) <tt>
:::: {{build link|path=view/Windows/job/OSG-Win/lastSuccessfulBuild/artifact/*zip*/archive.zip|text=OpenSceneGraph}} / </tt> ( OSG CMake install ) <tt>
:::: OpenSceneGraph / </tt> (link above) <tt>
::::: bin /
::::: bin /
::::: include /
::::: include /
::::: lib /
::::: lib /
:::: SimGear / </tt> (create this empty for now, subfolders will be created by build process) <tt>
:::: SimGear / </tt> (create this empty for now, subfolders will be created by build process) <tt>
::::: include /
:::: FlightGear / </tt> <tt>
::::: lib /
::::: data / (FGDATA, link above)
:::: FlightGear / </tt> (create this empty for now) <tt>
: Source /
::::: include /
:: flightgear-git / </tt> (FlightGear sources, link above) <tt>
::::: lib /</tt>
:: simgear-git / </tt> (Simgear sources, link above) <tt>
: BuildDirs /
:: flightgear-build / </tt> (Create empty) <tt>
:: simgear-build /</tt> (Create empty)


== Building ==
== Building ==


=== GUI compilation ===
=== GUI compilation ===
# Set up a work directory as described above.
# Set up a work directory as described above or to your own personal preference.
# Having downloaded the sources into the Source directory, and all the prebuilt dependencies, continue below:
# '''Building SimGear'''
# '''Building SimGear'''
## Open the CMake gui.
## 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 is the source code"</tt> to the Source/simgear-git directory.
## 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).
## Set <tt>"Where to build the binaries"</tt> to the empty directory <tt>simgear-build</tt> in the BuildDirs directory.
## 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 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.
## 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 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.
## 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.  
## CMake adds new configuration variables in red. Some have a value ending with <tt>-NOTFOUND</tt>. 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.
### 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.
### 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 <tt>\Dependencies</tt> folder in 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> (<tt>msvc140-64</tt> for 64-bit).
### Set the  <tt>CMAKE_INSTALL_PREFIX</tt> variable to <tt>\Dependencies\install\msvc140-64\Simgear</tt>
### Also check the lines with a checkbox. These are build options and may impact the feature set of the built program.
### Set the <tt>Boost_INCLUDE_DIR</tt> variable to <tt>\Dependencies</tt>
### To pick up Boost correctly, you must add a new Cache entry with name <tt>BOOST_ROOT</tt>, type <tt>PATH</tt>, and value <tt>\Dependencies</tt>. It is '''not''' required to set Boost_DIR to any value.
### Create a second cache entry, called <tt>CMAKE_PREFIX_PATH</tt>, type <tt>PATH</tt> and value <tt>\Dependencies\install\msvc140-64\OpenSceneGraph</tt>. This will allow OSG to be picked up automatically.
### Also verify the lines with a checkbox. These are build options and may impact the feature set of the built program.
### 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.
## Repeat the process from step 5, until [[File:CMake GUI Generate.png]] is enabled.
## Repeat the process from step 5, until [[File:CMake GUI Generate.png]] is enabled.
## Press [[File:CMake GUI Generate.png]].
## 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>.
## Press [[File:CMake GUI Open Project.png]].
## 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]]
## Choose the <tt>"RelWithDebInfo"</tt> build in the toolbar. The right menu should read x64 for 64-bits. [[File:MVSC 2019 solution.png|right]]
## Generate the solution with F7 key or right-click the top level "Solution SimGear" in the Solution Explorer and choose Build.
## 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.
## If there are build errors, return to CMake, clear remaining errors, [[File:CMake GUI Configure.png]] and [[File:CMake GUI Generate.png]].
## 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>
## 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>. This should only take a few seconds as you have already compiled everything.
# '''Building FlightGear'''
# '''Building FlightGear'''
#: Repeat the steps under Building Simgear, but change the <tt>SimGear</tt> paths to <tt>FlightGear</tt>.
#: Repeat the steps under Building Simgear, but change the <tt>SimGear</tt> paths to <tt>FlightGear</tt>.
## Notably, you will have to link Simgear and 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 <tt>SGPATH;QT5PATH;OSGPATH</tt>.
### Simgear: <tt>\Dependencies\install\msvc140-64\Simgear</tt>
### QT5: <tt>C:/Qt/5.15.0/msvc2019_64</tt> (adjust to match your QT installation).
### My personal final path was: <tt>C:\Users\redpa\Documents\FlightGear\fg-from-scratch\fresh-build\Dependencies\install\msvc140-64\Simgear;C:/Users/redpa/Documents/FlightGear/fg-from-scratch/fresh-build/Dependencies/install/msvc140-64/OpenSceneGraph;C:/Qt/5.15.0/msvc2019_64</tt>
# Enjoy!
# 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.
==== SimGear ====
For building SimGear with MSVC 2015 as 64-bit:
{{collapsible script
| type  = Windows batch file
| title  = The <code>.cmake.bat</code> script for configuring and compiling SimGear
| 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 2015 Win64"
REM Compile.
cmake --build . --target install
| show  = 1
}}
{{collapsible script
| 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 2015 Win64"
REM Compile.
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:
{{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
}}
==== FlightGear ====
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 2015 Win64"
REM Compile.
cmake --build . --target install
| conc  = Note: change the <code>CMAKE_PREFIX_PATH</code> variable to your Qt installation directory.
| show  = 1
}}
{{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 2015 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 ===
=== Updating ===
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.
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-configure in 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>.
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 ===
=== TerraGear ===
TerraGear can be built the same way as FlightGear, just change the paths to your TerraGear source and directories.
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 ===
{{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.
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.
cmake --build . --config Release --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/OSG-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" ^
-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.
cmake --build . --config Release --target INSTALL
| conc  = The <code>WORKSPACE</code> variable is a Windows environmental variable.
}}
=== SimGear-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/SimGear-Win/lastBuild/consoleText, with comments added.
| script = REM Set up.
cd %WORKSPACE%
md build32
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
| 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.
cmake ..\source ^
-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.
}}


== External link ==
== External link ==
842

edits

Navigation menu