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