]> git.mxchange.org Git - flightgear.git/blob - README.cmake
Make environment-manager closest airport updating quieter, and use an event instead...
[flightgear.git] / README.cmake
1 Getting started with CMake
2
3 (These instructions apply to Unix-like systems, including Cygwin and Mac. To
4 build using Visual Studio or some other IDE supported by CMake, most of the
5 information below still applies)
6
7 Always compile in a separate directory to the code. For example, if the
8 code (eg, from Git) is at /home/curt/projects/flightgear, you might create
9 /home/curt/projects/fgbuild. Change into the new directory, and run
10
11     cmake ../flightger
12     
13 To generate standard Unix Makefiles in fgbuild.
14
15 Probably you want to specify an install prefix:
16
17     cmake ../flightgear -DCMAKE_INSTALL_PREFIX=/usr
18
19 Note the install prefix is automatically searched for required libraries
20 and header files, so if you install PLIB, OpenSceneGraph and SimGear to the
21 same prefix, most configuration options are unnecessary.
22
23 If for some reason you have a dependency (or several) at a different prefix,
24 you can specify one or more via CMAKE_PREFIX_PATH:
25
26     cmake ../flightgear -DCMAKE_PREFIX_PATH="/opt/local;/opt/fgfs"
27
28 (note the use of semi-colons to specify multiple prefix paths)
29
30 Standard prefixes are searched automatically (/usr, /usr/local, /opt/local)
31
32 Most dependencies also expose an environment variable to specify their
33 installation directory explicitly eg OSG_DIR or PLIBDIR. Any of the methods
34 described above will work, but specifying an INSTALL_PREFIX or PREFIX_PATH is
35 usually simpler.
36
37 By default, we select a release build. To create a debug build, use
38
39     cmake ../flightgear -DCMAKE_BUILD_TYPE=Debug
40     
41 (or MinSizeRel, or RelWithDbg)
42
43 Debug builds will automatically use corresponding debug builds of required
44 libraries, if they are available. For example you can install debug builds of
45 SimGear and OpenSceneGraph, and a debug FlightGear build will use them.
46
47 (Debug builds of libraries have the 'd' suffix by default - Release builds
48 have no additional suffix)
49
50 Note most IDE projects (eg Xcode and Visual Studio) support building all the
51 build types from the same project, so you can omit the CMAKE_BUILD_TYPE option
52 when running cmake, and simply pick the build configuration as normal in the
53 IDE.
54
55 It's common to have several build directories with different build
56 configurations, eg
57
58     /home/curt/projects/flightgear (the git clone)
59     /home/curt/projects/fgdebug
60     /home/curt/projects/fgrelease
61     /home/curt/projects/fg-with-svn-osg
62
63 To set an optional feature, do
64
65     cmake ../flightgear -DFEATURE_NAME=ON 
66
67 (or 'OFF' to disable )
68
69 To see the variables that can be configured / are currently defined, you can
70 run one of the GUI front ends, or the following command:
71
72     cmake ../flighgear -L
73
74 Add 'A' to see all the options (including advanced options), or 'H' to see
75 the help for each option (similar to running configure --help under autoconf):
76
77     cmake ../flightgear -LH
78
79 Build Targets
80
81 For a Unix makefile build, 'make dist', 'make uninstall' and 'make test' are
82 all available and should work as expected. 'make clean' is also as normal,
83 but there is *no* 'make distclean' target. The equivalent is to completely
84 remove your build directory, and start with a fresh one.
85
86 Adding new files to the build
87
88 Add source files to the SOURCES list, and headers to the HEADERS list. Note
89 technically you only need to add source files, but omitting headers confuses
90 project generation and distribution / packaging targets.
91
92 For target conditional files, you can append to the SOURCES or HEADERS lists
93 inside an if() test, for example:
94
95     if(APPLE)
96         list(APPEND SOURCES extraFile1.cxx extraFile2.cxx)
97     endif()
98
99 Setting include directories
100
101 In any CMakeList.txt, you can do the following:
102
103     include_directories(${PROJECT_SOURCE_DIR}/some/path)
104
105 For example, this can be done in particular subdirectory, or at the project
106 root, or an intermediate level.
107
108 Setting target specific compile flags, includes or defines
109
110 Use set_target_property(), for example
111
112     set_target_property(fgfs PROPERTIES
113             COMPILE_DEFINITIONS FOO BAR=1)
114             
115 You can set a property on an individual source file:
116
117     set_property(SOURCE myfile.cxx PROPERTY COMPILE_FLAGS "-Wno-unsigned-compare")
118             
119 Detecting Features / Libraries
120
121 For most standard libraries (Gtk, wxWidget, Python, GDAL, Qt, libXml, Boost),
122 cmake provides a standard helper. To see the available modules, run:
123
124      cmake --help-module-list
125
126 In the root CMakeLists file, use a statement like:
127
128     find_package(OpenGL REQUIRED)
129     
130 Each package helper sets various variables such aaa_FOUND, aaa_INCLUDE_DIR,
131 and aaa_LIBRARY. Depending on the complexity of the package, these variables
132 might have different names (eg, OPENSCENEGRAPH_LIBRARIES).
133
134 If there's no standard helper for a library you need, find a similar one, copy
135 it to CMakeModules/FindABC.cmake, and modify the code to fit. Generally this
136 is pretty straightforward. The built-in modules reside in the Cmake 'share'
137 directory, eg /usr/share/cmake/modules on Unix systems.
138
139 Note libraries support by pkg-config can be handled directly, with no need
140 to create a custom FindABC helper.
141             
142 Adding a new executable target
143
144     add_executable(myexecutable ${SOURCES} ${HEADERS})
145     target_link_libraries(myexecutable .... libraries ... )
146     install(TARGETS myexecutable RUNTIME DESTINATION bin)
147     
148 (If the executable should not be installed, omit the final line above)
149
150 If you add an additional line
151
152     add_test(testname ${EXECUTABLE_OUTPUT_PATH}/myexecutable)
153     
154 Then running 'make test' will run your executable as a unit test. The
155 executable should return either a success or failure result code.