]> git.mxchange.org Git - flightgear.git/blob - CMakeLists.txt
Fix un-inited vars found by valgrind.
[flightgear.git] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.6.4)
2
3 include (CheckFunctionExists)
4 include (CheckCSourceCompiles)
5 include (CheckCXXSourceCompiles)
6 include (CheckIncludeFile)
7
8 project(FlightGear)
9
10 # We have some custom .cmake scripts not in the official distribution.
11 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
12
13 if(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
14     # use official include provided by latest CMake
15     include(GNUInstallDirs)
16 else(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
17     # backward compatibility: use our own module for older cmake versions
18     include(OldGNUInstallDirs)
19 endif(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
20
21 # Warning when build is not an out-of-source build.
22 string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" InSourceBuild)
23 if(InSourceBuild)
24     message(WARNING  "Avoid building inside the source tree!")
25     message(WARNING  "Create a separate build directory instead (i.e. 'fgbuild') and call CMake from there: ")
26     message(WARNING  "  mkdir ../fgbuild && cd ../fgbuild && cmake ${CMAKE_SOURCE_DIR}")
27 endif(InSourceBuild)
28
29 # System detection/default settings
30 include( DetectDistro )
31 include( DetectBrowser )
32
33 set(CMAKE_DEBUG_POSTFIX          "d" CACHE STRING "add a postfix, usually d on windows")
34 set(CMAKE_RELEASE_POSTFIX        ""  CACHE STRING "add a postfix, usually empty on windows")
35 set(CMAKE_RELWITHDEBINFO_POSTFIX ""  CACHE STRING "add a postfix, usually empty on windows")
36 set(CMAKE_MINSIZEREL_POSTFIX     ""  CACHE STRING "add a postfix, usually empty on windows")
37
38 # read 'version' file into a variable (stripping any newlines or spaces)
39 file(READ version versionFile)
40 if (NOT versionFile)
41     message(FATAL_ERROR "Unable to determine FlightGear version. Version file is missing.")
42 endif()
43 string(STRIP "${versionFile}" FLIGHTGEAR_VERSION)
44
45 # FlightGear packaging (to build a source tarball)
46 include( ConfigureCPack )
47
48 # FlightGear base package path
49 if (FG_DATA_DIR)
50     message(STATUS "Using explicit data directory for base package: ${FG_DATA_DIR}")
51 else()
52     set(FG_DATA_DIR "${CMAKE_INSTALL_PREFIX}/lib/FlightGear" CACHE PATH "Default location where data files are located")
53     message(STATUS "Using default data directory for base package:  ${FG_DATA_DIR}")
54 endif()
55
56 # Change the default build type to something fast
57 if(NOT CMAKE_BUILD_TYPE)
58     set(CMAKE_BUILD_TYPE Release CACHE STRING
59         "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
60         FORCE)
61 endif(NOT CMAKE_BUILD_TYPE)
62
63 if(NOT "$ENV{BUILD_ID}" STREQUAL "")
64     set(HUDSON_BUILD_ID $ENV{BUILD_ID})
65     set(HUDSON_BUILD_NUMBER $ENV{BUILD_NUMBER})
66     message(STATUS "running under Hudson/Jenkins, build-number is ${HUDSON_BUILD_NUMBER}")
67 else()
68     set(HUDSON_BUILD_NUMBER 0)
69     set(HUDSON_BUILD_ID "none")
70 endif()
71
72 #####################################################################################
73 # Configure library search paths
74 #####################################################################################
75
76 if(APPLE)
77     # Custom library directories for Mac, which should have precedence over any other
78     list(APPEND ADDITIONAL_LIBRARY_PATHS
79          ~/Library/Frameworks
80          /Library/Frameworks)
81 endif(APPLE)
82
83 if(NOT "${CMAKE_LIBRARY_ARCHITECTURE}" STREQUAL "")
84     # Workaround for Ubuntu/Debian which introduced the "multiarch" library
85     # directory structure, which is unsupported by CMake < 2.8.10, so we need to
86     # add paths manually
87     # see http://www.cmake.org/Bug/view.php?id=12049 and
88     # http://www.cmake.org/Bug/view.php?id=12037
89     list(APPEND ADDITIONAL_LIBRARY_PATHS
90          /usr/local/lib/${CMAKE_LIBRARY_ARCHITECTURE}
91          /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}
92          /lib/${CMAKE_LIBRARY_ARCHITECTURE})
93     message(STATUS "additional library directories: ${ADDITIONAL_LIBRARY_PATHS}")
94 endif()
95
96 if(NOT MSVC)
97     # TBD: are these really necessary? Aren't they considered by cmake automatically?
98     list(APPEND ADDITIONAL_LIBRARY_PATHS
99          /opt/local
100          /usr/local
101          /usr)
102 endif()
103 #####################################################################################
104
105 IF(APPLE)
106     set(EVENT_INPUT_DEFAULT 1)
107
108     find_library(CORESERVICES_LIBRARY CoreServices)
109     find_library(COCOA_LIBRARY Cocoa)
110     list(APPEND PLATFORM_LIBS ${COCOA_LIBRARY} ${CORESERVICES_LIBRARY})
111
112 elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
113     find_package(UDev)
114
115     if(UDEV_FOUND)
116         set(EVENT_INPUT_DEFAULT 1)
117     endif(UDEV_FOUND)
118 endif()
119
120 find_package(Git)
121 if (GIT_FOUND)
122     execute_process(COMMAND git --git-dir ${PROJECT_SOURCE_DIR}/.git rev-parse  HEAD
123         OUTPUT_VARIABLE REVISION
124         OUTPUT_STRIP_TRAILING_WHITESPACE)
125     message(STATUS "Git revision is ${REVISION}")
126 else()
127     set(REVISION "none")
128 endif()
129
130 # FlightGear build options
131 option(SIMGEAR_SHARED    "Set to ON when SimGear was built as a shared library" OFF)
132 option(LOGGING           "Set to ON to build FlightGear with logging support (default)" ON)
133 option(SP_FDMS           "Set to ON to build FlightGear with special-purpose FDMs" OFF)
134 option(ENABLE_UIUC_MODEL "Set to ON to build FlightGear with UIUCModel FDM" OFF)
135 option(ENABLE_LARCSIM    "Set to ON to build FlightGear with LaRCsim FDM" OFF)
136 option(ENABLE_YASIM      "Set to ON to build FlightGear with YASIM FDM (default)" ON)
137 option(ENABLE_JSBSIM     "Set to ON to build FlightGear with JSBSim FDM (default)" ON)
138 option(EVENT_INPUT       "Set to ON to build FlightGear with event-based Input support" ${EVENT_INPUT_DEFAULT})
139 option(ENABLE_LIBSVN     "Set to ON to build FlightGear/terrasync with libsvnclient support (default)" ON)
140 option(ENABLE_RTI        "Set to ON to build FlightGear with RTI support" OFF)
141 option(ENABLE_PROFILE    "Set to ON to build FlightGear with gperftools profiling support" OFF)
142 option(JPEG_FACTORY      "Set to ON to build FlightGear with JPEG-factory support" OFF)
143 option(SYSTEM_SQLITE     "Set to ON to build FlightGear with the system's SQLite3 library" OFF)
144
145 # additional utilities
146 option(ENABLE_FGADMIN    "Set to ON to build the FGADMIN application (default)" ON)
147 option(ENABLE_FGELEV     "Set to ON to build the fgelev application (default)" ON)
148 option(WITH_FGPANEL      "Set to ON to build the fgpanel application (default)" ON)
149 option(ENABLE_FGVIEWER   "Set to ON to build the fgviewer application (default)" ON)
150 option(ENABLE_GPSSMOOTH  "Set to ON to build the GPSsmooth application (default)" ON)
151 option(ENABLE_TERRASYNC  "Set to ON to build the terrasync application (default)" ON)
152
153 option(ENABLE_FGJS       "Set to ON to build the fgjs application (default)" ON)
154 option(ENABLE_JS_DEMO    "Set to ON to build the js_demo application (default)" ON)
155
156 option(ENABLE_METAR      "Set to ON to build the metar application (default)" ON)
157
158 option(ENABLE_TESTS      "Set to ON to build test applications (default)" ON)
159
160 if(LOGGING)
161     # nothing
162 else()
163     set(FG_NDEBUG 1)
164 endif()
165
166 if(SP_FDMS)
167     set(ENABLE_SP_FDM 1)
168 endif()
169
170 # Setup MSVC 3rd party directories
171 include( ConfigureMsvc3rdParty )
172
173 if(EVENT_INPUT)
174     if(APPLE)
175     elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
176         if(NOT UDEV_FOUND)
177             message(WARNING "UDev not found, event input is disabled!")
178             set(EVENT_INPUT 0)
179         else()
180             add_definitions(-DWITH_EVENTINPUT)
181             set(EVENT_INPUT_LIBRARIES ${UDEV_LIBRARIES})
182             message(STATUS "event-based input enabled. Using ${UDEV_LIBRARIES}")
183         endif()
184     else()
185         message(WARNING "event-based input is not supported on this platform yet")
186     endif()
187
188     # Keep PLIB INPUT enabled as long as EventInput does not replace current joystick configurations.
189     set(ENABLE_PLIB_JOYSTICK 1)
190 else(EVENT_INPUT)
191     set(ENABLE_PLIB_JOYSTICK 1)
192 endif(EVENT_INPUT)
193
194 # check required dependencies
195 find_package(Boost   REQUIRED)
196 find_package(ZLIB    REQUIRED)
197 find_package(Threads REQUIRED)
198 find_package(OpenGL  REQUIRED)
199 find_package(OpenAL  REQUIRED)
200 find_package(OpenSceneGraph 3.0.0 REQUIRED osgText osgSim osgDB osgParticle osgFX osgUtil osgViewer osgGA)
201
202 if(ENABLE_FGADMIN)
203     find_package(FLTK)
204
205     if ( FLTK_FOUND )
206         if ( X11_Xinerama_FOUND )
207             message(STATUS "Found X11_Xinerama...")
208             list(APPEND FLTK_LIBRARIES ${X11_Xinerama_LIB})
209         endif()
210
211         if ( X11_Xft_FOUND )
212             message(STATUS "Found X11_Xft...")
213             list(APPEND FLTK_LIBRARIES ${X11_Xft_LIB})
214         endif()
215
216         message(STATUS "Using FLTK_LIBRARIES for fgadmin: ${FLTK_LIBRARIES}")
217     endif ( FLTK_FOUND )
218 endif(ENABLE_FGADMIN)
219
220 if(ENABLE_LIBSVN)
221     find_package(SvnClient)
222
223     if(LIBSVN_FOUND)
224         message(STATUS "libsvn found, enabling in terrasync")
225         set(HAVE_SVN_CLIENT_H 1)
226         set(HAVE_LIBSVN_CLIENT_1 1)
227     else()
228         message(STATUS "libsvn missing. Disabling...")
229     endif(LIBSVN_FOUND)
230 endif(ENABLE_LIBSVN)
231
232 if (SYSTEM_SQLITE)
233     find_package(SQLite3 REQUIRED)
234     set(CMAKE_REQUIRED_INCLUDES ${SQLITE3_INCLUDED_DIR})
235     message(STATUS "Using system SQLite3 library")
236 endif (SYSTEM_SQLITE)
237
238 # Sqlite always depends on the threading lib
239 list(APPEND SQLITE3_LIBRARY ${CMAKE_THREAD_LIBS_INIT})
240
241 find_package(PLIB REQUIRED puaux pu js fnt)
242
243 if (EMBEDDED_SIMGEAR)
244     message(STATUS "Using embedded SimGear")
245     # create the same variables that FindSimGear would define
246     set(SIMGEAR_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/simgear)
247     set(SIMGEAR_CORE_LIBRARIES SimGearCore)
248     set(SIMGEAR_LIBRARIES SimGearScene)
249
250     if (NOT SIMGEAR_SHARED)
251         set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES
252             ${CMAKE_THREAD_LIBS_INIT}
253             ${ZLIB_LIBRARY}
254             ${LIBSVN_LIBRARIES}
255             ${WINMM_LIBRARY})
256
257         set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES 
258             ${OPENAL_LIBRARY})
259     endif()
260 else(EMBEDDED_SIMGEAR)
261     # FlightGear and SimGear versions need to match
262     find_package(SimGear ${FLIGHTGEAR_VERSION} REQUIRED)
263 endif (EMBEDDED_SIMGEAR)
264
265 if (JPEG_FACTORY)
266     # check simgear was built with JPEG-factory support
267     find_package(JPEG REQUIRED)
268     include_directories(${JPEG_INCLUDE_DIR})
269
270     set(CMAKE_REQUIRED_INCLUDES
271         ${SIMGEAR_INCLUDE_DIR}
272         ${JPEG_INCLUDE_DIR}
273         ${OPENSCENEGRAPH_INCLUDE_DIRS})
274
275     check_cxx_source_compiles(
276         "#include <simgear/screen/jpgfactory.hxx>
277         int main()    { return 0; } "
278         FG_JPEG_SERVER)
279
280     if (NOT FG_JPEG_SERVER)
281         message(STATUS "JPEG server support requested, but SimGear was built without JPEG support")
282     endif()
283 endif()
284
285 check_include_file(unistd.h   HAVE_UNISTD_H)
286 check_include_file(sys/time.h HAVE_SYS_TIME_H)
287 check_include_file(windows.h  HAVE_WINDOWS_H)
288
289 if(ENABLE_PROFILE)
290     find_package(GooglePerfTools REQUIRED)
291     set(FG_HAVE_GPERFTOOLS 1)
292     message(STATUS "Built-in profiler using gperftools available")
293 endif()
294
295 if(ENABLE_RTI)
296     message(STATUS "RTI: ENABLED")
297     find_package(RTI)
298     if(RTI_FOUND)
299         set(FG_HAVE_HLA 1)
300     endif(RTI_FOUND)
301 else()
302     message(STATUS "RTI: DISABLED")
303 endif(ENABLE_RTI)
304
305 if(CMAKE_COMPILER_IS_GNUCXX)
306     set(WARNING_FLAGS_CXX "-Wall")
307     set(WARNING_FLAGS_C   "-Wall")
308 endif(CMAKE_COMPILER_IS_GNUCXX)
309
310 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 
311    set (WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual")
312    set (WARNING_FLAGS_C   "-Wall")
313 endif() 
314
315 if(WIN32)
316
317     if(MSVC)
318         # turn off various warnings
319         # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
320         #     SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
321         # endforeach(warning)
322
323         set(MSVC_FLAGS "-DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS -Dstrdup=_strdup")
324         if (${MSVC_VERSION} GREATER 1599)
325             set( MSVC_LD_FLAGS "/FORCE:MULTIPLE" )
326         endif (${MSVC_VERSION} GREATER 1599)
327     endif(MSVC)
328
329     set(NOMINMAX 1)
330 endif(WIN32)
331
332 set (BOOST_CXX_FLAGS "-DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_BIMAP_DISABLE_SERIALIZATION")
333
334 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS_C} ${MSVC_FLAGS} -D_REENTRANT")
335 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_CXX} ${MSVC_FLAGS} -D_REENTRANT ${BOOST_CXX_FLAGS}")
336 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}")
337
338 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS}
339     ${Boost_INCLUDE_DIRS}
340     ${ZLIB_INCLUDE_DIR}
341     ${OPENGL_INCLUDE_DIR}
342     ${OPENAL_INCLUDE_DIR}
343     ${SIMGEAR_INCLUDE_DIR}
344     ${PLIB_INCLUDE_DIR} )
345
346 include_directories(${PROJECT_SOURCE_DIR}/src)
347
348 # following is needed, because config.h is include 'bare', whereas
349 # version.h is included as <Include/version.h> - this should be cleaned up
350 include_directories(${PROJECT_BINARY_DIR}/src)
351 include_directories(${PROJECT_BINARY_DIR}/src/Include)
352
353 add_definitions(-DHAVE_CONFIG_H)
354
355 check_function_exists(mkfifo HAVE_MKFIFO)
356
357 # configure a header file to pass some of the CMake settings
358 # to the source code
359 configure_file (
360     "${PROJECT_SOURCE_DIR}/src/Include/config_cmake.h.in"
361     "${PROJECT_BINARY_DIR}/src/Include/config.h"
362 )
363
364 #and the same for the version header
365 configure_file (
366     "${PROJECT_SOURCE_DIR}/src/Include/version.h.cmake-in"
367     "${PROJECT_BINARY_DIR}/src/Include/version.h"
368 )
369
370 if (EMBEDDED_SIMGEAR)
371     add_subdirectory(simgear)
372     # since we build without SimGear installed, we need to
373     # search this path directly to find the generated
374     # simgear_config.h
375     include_directories(${PROJECT_BINARY_DIR}/simgear)
376 endif(EMBEDDED_SIMGEAR)
377
378 add_subdirectory(src)
379 add_subdirectory(utils)
380 add_subdirectory(man)
381
382 #-----------------------------------------------------------------------------
383 ### uninstall target
384 #-----------------------------------------------------------------------------
385 CONFIGURE_FILE(
386     "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
387     "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
388     IMMEDIATE @ONLY)
389 ADD_CUSTOM_TARGET(uninstall
390     "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")