]> git.mxchange.org Git - flightgear.git/blob - CMakeLists.txt
Remove debug console output in FGApproachController
[flightgear.git] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.8.11)
2
3 include (CheckFunctionExists)
4 include (CheckCSourceCompiles)
5 include (CheckCXXSourceCompiles)
6 include (CheckIncludeFile)
7
8 if(COMMAND cmake_policy)
9    if(POLICY CMP0054)
10        cmake_policy(SET CMP0054 NEW)
11    endif()
12    if(POLICY CMP0042)
13        cmake_policy(SET CMP0042 NEW)
14    endif()
15 endif()
16
17 # using 10.7 because boost requires libc++ and 10.6 doesn't include it
18 set(CMAKE_OSX_DEPLOYMENT_TARGET 10.7)
19 set(CMAKE_OSX_SYSROOT /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk)
20
21 project(FlightGear)
22
23 # We have some custom .cmake scripts not in the official distribution.
24 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
25
26 if(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
27     # use official include provided by latest CMake
28     include(GNUInstallDirs)
29 else(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
30     # backward compatibility: use our own module for older cmake versions
31     include(OldGNUInstallDirs)
32 endif(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
33
34 # Warning when build is not an out-of-source build.
35 string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" InSourceBuild)
36 if(InSourceBuild)
37     message(WARNING  "Avoid building inside the source tree!")
38     message(WARNING  "Create a separate build directory instead (i.e. 'fgbuild') and call CMake from there: ")
39     message(WARNING  "  mkdir ../fgbuild && cd ../fgbuild && cmake ${CMAKE_SOURCE_DIR}")
40 endif(InSourceBuild)
41
42 # System detection/default settings
43 include( DetectDistro )
44 include( DetectBrowser )
45
46 set(CMAKE_DEBUG_POSTFIX          "d" CACHE STRING "add a postfix, usually d on windows")
47 set(CMAKE_RELEASE_POSTFIX        ""  CACHE STRING "add a postfix, usually empty on windows")
48 set(CMAKE_RELWITHDEBINFO_POSTFIX ""  CACHE STRING "add a postfix, usually empty on windows")
49 set(CMAKE_MINSIZEREL_POSTFIX     ""  CACHE STRING "add a postfix, usually empty on windows")
50
51 # read 'version' file into a variable (stripping any newlines or spaces)
52 file(READ version versionFile)
53 if (NOT versionFile)
54     message(FATAL_ERROR "Unable to determine FlightGear version. Version file is missing.")
55 endif()
56 string(STRIP "${versionFile}" FLIGHTGEAR_VERSION)
57
58 # FlightGear packaging (to build a source tarball)
59 include( ConfigureCPack )
60
61 # FlightGear base package path
62 if (FG_DATA_DIR)
63     message(STATUS "Using explicit data directory for base package: ${FG_DATA_DIR}")
64 else()
65     set(FG_DATA_DIR "${CMAKE_INSTALL_PREFIX}/lib/FlightGear" CACHE PATH "Default location where data files are located")
66     message(STATUS "Using default data directory for base package:  ${FG_DATA_DIR}")
67 endif()
68
69 # Change the default build type to something fast
70 if(NOT CMAKE_BUILD_TYPE)
71     set(CMAKE_BUILD_TYPE Release CACHE STRING
72         "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
73         FORCE)
74 endif(NOT CMAKE_BUILD_TYPE)
75
76 if(NOT "$ENV{BUILD_ID}" STREQUAL "")
77     set(HUDSON_BUILD_ID $ENV{BUILD_ID})
78     set(HUDSON_BUILD_NUMBER $ENV{BUILD_NUMBER})
79     message(STATUS "running under Hudson/Jenkins, build-number is ${HUDSON_BUILD_NUMBER}")
80 else()
81     set(HUDSON_BUILD_NUMBER 0)
82     set(HUDSON_BUILD_ID "none")
83 endif()
84
85 #####################################################################################
86 # Configure library search paths
87 #####################################################################################
88
89
90 if(NOT "${CMAKE_LIBRARY_ARCHITECTURE}" STREQUAL "")
91     # Workaround for Ubuntu/Debian which introduced the "multiarch" library
92     # directory structure, which is unsupported by CMake < 2.8.10, so we need to
93     # add paths manually
94     # see http://www.cmake.org/Bug/view.php?id=12049 and
95     # http://www.cmake.org/Bug/view.php?id=12037
96     list(APPEND ADDITIONAL_LIBRARY_PATHS
97          /usr/local/lib/${CMAKE_LIBRARY_ARCHITECTURE}
98          /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}
99          /lib/${CMAKE_LIBRARY_ARCHITECTURE})
100     message(STATUS "additional library directories: ${ADDITIONAL_LIBRARY_PATHS}")
101 endif()
102
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 elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR
112         ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
113     find_package(Threads REQUIRED)
114     find_package(X11 REQUIRED)
115
116     set(USE_DBUS_DEFAULT 1)
117
118     find_package(UDev)
119     if(UDEV_FOUND)
120         set(EVENT_INPUT_DEFAULT 1)
121     endif(UDEV_FOUND)
122
123     find_package(Speex)
124     find_package(Speexdsp)
125     if(SPEEX_FOUND AND SPEEXDSP_FOUND)
126         set(SYSTEM_SPEEX_DEFAULT 1)
127     endif(SPEEX_FOUND AND SPEEXDSP_FOUND)
128
129     find_package(Gsm)
130     if(GSM_FOUND)
131         set(SYSTEM_GSM_DEFAULT 1)
132     endif(GSM_FOUND)
133
134     find_package(Flite)
135     if(FLITE_FOUND)
136         set(SYSTEM_FLITE_DEFAULT 1)
137     endif()
138
139     find_package(HtsEngine)
140     if(HTS_ENGINE_FOUND)
141         set(SYSTEM_HTS_ENGINE_DEFAULT 1)
142     endif()
143 endif()
144
145 find_package(Git)
146 if (GIT_FOUND)
147     execute_process(COMMAND git --git-dir ${PROJECT_SOURCE_DIR}/.git rev-parse  HEAD
148         OUTPUT_VARIABLE REVISION
149         OUTPUT_STRIP_TRAILING_WHITESPACE)
150     message(STATUS "Git revision is ${REVISION}")
151 else()
152     set(REVISION "none")
153 endif()
154
155 # FlightGear build options
156 option(SIMGEAR_SHARED    "Set to ON when SimGear was built as a shared library" OFF)
157 option(LOGGING           "Set to ON to build FlightGear with logging support (default)" ON)
158 option(JSBSIM_TERRAIN    "Set to ON to build FlightGear with JSBSim terrain handling code" ON)
159 option(SP_FDMS           "Set to ON to build FlightGear with special-purpose FDMs" OFF)
160 option(ENABLE_UIUC_MODEL "Set to ON to build FlightGear with UIUCModel FDM" OFF)
161 option(ENABLE_LARCSIM    "Set to ON to build FlightGear with LaRCsim FDM" OFF)
162 option(ENABLE_YASIM      "Set to ON to build FlightGear with YASIM FDM (default)" ON)
163 option(ENABLE_JSBSIM     "Set to ON to build FlightGear with JSBSim FDM (default)" ON)
164 option(EVENT_INPUT       "Set to ON to build FlightGear with event-based Input support" ${EVENT_INPUT_DEFAULT})
165 option(ENABLE_RTI        "Set to ON to build FlightGear with RTI support" OFF)
166 option(ENABLE_PROFILE    "Set to ON to build FlightGear with gperftools profiling support" OFF)
167 option(SYSTEM_SQLITE     "Set to ON to build FlightGear with the system's SQLite3 library" OFF)
168 option(ENABLE_IAX        "Set to ON to build FlightGear with IAXClient/fgcom built-in (default)" ON)
169 option(USE_DBUS          "Set to ON to build FlightGear with DBus screensaver interaction (default on Linux)" ${USE_DBUS_DEFAULT})
170 option(SYSTEM_SPEEX      "Set to ON to build IAXClient with the system's speex and speexdsp library" ${SYSTEM_SPEEX_DEFAULT})
171 option(SYSTEM_GSM        "Set to ON to build IAXClient with the system's GSM library" ${SYSTEM_GSM_DEFAULT})
172 option(SYSTEM_FLITE      "Set to ON to build Flightgear with the system's Flite library" ${SYSTEM_FLITE_DEFAULT})
173 option(SYSTEM_HTS_ENGINE "Set to ON to build Flightgear with the system's HTS Engine library" ${SYSTEM_HTS_ENGINE_DEFAULT})
174 option(FG_NIGHTLY        "Set to ON to mark this as a nightly build" OFF)
175
176 # additional utilities
177 option(ENABLE_FGADMIN    "Set to ON to build the FGADMIN application (default)" ON)
178 option(ENABLE_FGELEV     "Set to ON to build the fgelev application (default)" ON)
179 option(WITH_FGPANEL      "Set to ON to build the fgpanel application (default)" ON)
180 option(ENABLE_FGVIEWER   "Set to ON to build the fgviewer application (default)" ON)
181 option(ENABLE_GPSSMOOTH  "Set to ON to build the GPSsmooth application (default)" ON)
182 option(ENABLE_TERRASYNC  "Set to ON to build the terrasync application (default)" ON)
183 option(ENABLE_FGJS       "Set to ON to build the fgjs application (default)" ON)
184 option(ENABLE_JS_DEMO    "Set to ON to build the js_demo application (default)" ON)
185 option(ENABLE_METAR      "Set to ON to build the metar application (default)" ON)
186 option(ENABLE_TESTS      "Set to ON to build test applications (default)" ON)
187 option(ENABLE_FGCOM      "Set to ON to build the FGCom application (default)" ON)
188 option(ENABLE_FLITE      "Set to ON to build the Flite text-to-speech module" ON)
189 option(ENABLE_QT         "Set to ON to build the internal Qt launcher" ON)
190
191 if(LOGGING)
192     # nothing
193 else()
194     set(FG_NDEBUG 1)
195 endif()
196
197 if(JSBSIM_TERRAIN)
198    set(JSBSIM_USE_GROUNDREACTIONS 1)
199 endif()
200
201 if(SP_FDMS)
202     set(ENABLE_SP_FDM 1)
203 endif()
204
205 if(ENABLE_FGCOM)
206   set(ENABLE_IAX 1)
207   include_directories(${PROJECT_SOURCE_DIR}/3rdparty/iaxclient/lib ) # for iaxclient.h
208 endif()
209
210 # Setup MSVC 3rd party directories
211 include( ConfigureMsvc3rdParty )
212
213 if(EVENT_INPUT)
214     if(APPLE)
215     elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
216         if(NOT UDEV_FOUND)
217             message(WARNING "UDev not found, event input is disabled!")
218             set(EVENT_INPUT 0)
219         else()
220             add_definitions(-DWITH_EVENTINPUT)
221             set(EVENT_INPUT_LIBRARIES ${UDEV_LIBRARIES})
222             message(STATUS "event-based input enabled. Using ${UDEV_LIBRARIES}")
223         endif()
224     else()
225         message(WARNING "event-based input is not supported on this platform yet")
226     endif()
227
228     # Keep PLIB INPUT enabled as long as EventInput does not replace current joystick configurations.
229     set(ENABLE_PLIB_JOYSTICK 1)
230 else(EVENT_INPUT)
231     set(ENABLE_PLIB_JOYSTICK 1)
232 endif(EVENT_INPUT)
233
234 # check required dependencies
235 find_package(Boost   REQUIRED)
236 find_package(ZLIB    REQUIRED)
237 find_package(OpenGL  REQUIRED)
238 find_package(OpenAL  REQUIRED)
239 find_package(OpenSceneGraph 3.2.0 REQUIRED
240   osgText
241   osgSim
242   osgDB
243   osgParticle
244   osgFX
245   osgUtil
246   osgViewer
247   osgGA
248 )
249
250 if (MSVC)
251         find_package(CrashRpt)
252         if (CRASHRPT_FOUND)
253                 set(HAVE_CRASHRPT 1)
254                 message(STATUS "Using CrashRpt")
255         include_directories( ${CRASHRPT_INCLUDE_DIR})
256         endif()
257 endif()
258
259 ##############################################################################
260 ## Sqlite3 setup
261
262 if (SYSTEM_SQLITE)
263     find_package(SQLite3 REQUIRED)
264
265     message(STATUS "Using system SQLite3 library")
266 else()
267     set(SQLITE3_INCLUDED_DIR "${CMAKE_SOURCE_DIR}/3rdparty/sqlite3")
268     # this target is defined in src/Navaids/CMakeLists.txt
269     list(APPEND SQLITE3_LIBRARY fgsqlite3)
270 endif (SYSTEM_SQLITE)
271
272 # Sqlite always depends on the threading lib
273 list(APPEND SQLITE3_LIBRARY ${CMAKE_THREAD_LIBS_INIT})
274
275 ##############################################################################
276 ## DBus setup
277
278 if (USE_DBUS)
279     include(FindPkgConfig)
280     if (PKG_CONFIG_FOUND)
281         pkg_check_modules(DBUS dbus-1)
282     endif (PKG_CONFIG_FOUND) #if we don't have pkg-config, assume we don't have libdbus-1-dev either http://packages.debian.org/sid/libdbus-1-dev
283     if (DBUS_FOUND)
284         set(HAVE_DBUS 1)
285         message(STATUS "Using DBus")
286         include_directories( ${DBUS_INCLUDE_DIRS})
287     else()
288         message(STATUS "DBus not found, screensaver control disabled")
289     endif (DBUS_FOUND)
290 else()
291 endif (USE_DBUS)
292
293 ##############################################################################
294 ## Qt5 setup setup
295 if (ENABLE_QT)
296         message(STATUS "Qt launcher enabled, checking for Qt 5.1 / qmake")
297         find_package(Qt5 5.1 COMPONENTS Widgets)
298         if (Qt5Widgets_FOUND)
299                 message(STATUS "Will enable Qt launcher GUI")
300                 message(STATUS "  Qt5Widgets version: ${Qt5Widgets_VERSION_STRING}")
301                 message(STATUS "  Qt5Widgets include dir: ${Qt5Widgets_INCLUDE_DIRS}")
302                 set(HAVE_QT 1)
303         endif()
304 endif (ENABLE_QT)
305 ##############################################################################
306
307 find_package(PLIB REQUIRED puaux pu js fnt)
308
309 # FlightGear and SimGear versions need to match
310 find_package(SimGear ${FLIGHTGEAR_VERSION} REQUIRED)
311
312 ##############################################################################
313
314 check_include_file(unistd.h   HAVE_UNISTD_H)
315 check_include_file(sys/time.h HAVE_SYS_TIME_H)
316 check_include_file(windows.h  HAVE_WINDOWS_H)
317
318 if(ENABLE_PROFILE)
319     find_package(GooglePerfTools REQUIRED)
320     set(FG_HAVE_GPERFTOOLS 1)
321     message(STATUS "Built-in profiler using gperftools available")
322 endif()
323
324 if(ENABLE_RTI)
325     message(STATUS "RTI: ENABLED")
326     find_package(RTI)
327     if(RTI_FOUND)
328         set(FG_HAVE_HLA 1)
329     endif(RTI_FOUND)
330 else()
331     message(STATUS "RTI: DISABLED")
332 endif(ENABLE_RTI)
333
334 if(CMAKE_COMPILER_IS_GNUCXX)
335     set(WARNING_FLAGS_CXX "-Wall")
336     set(WARNING_FLAGS_C   "-Wall")
337 endif(CMAKE_COMPILER_IS_GNUCXX)
338
339 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
340    set (WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual -Wno-redeclared-class-member")
341    set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
342    set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
343    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
344    set (WARNING_FLAGS_C "-Wall")
345 endif()
346
347 if(WIN32)
348
349     if(MSVC)
350         # turn off various warnings
351         # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
352         #     SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
353         # endforeach(warning)
354
355         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")
356         if (${MSVC_VERSION} GREATER 1599)
357             set( MSVC_LD_FLAGS "/FORCE:MULTIPLE" )
358         endif (${MSVC_VERSION} GREATER 1599)
359     endif(MSVC)
360
361     set(NOMINMAX 1)
362 endif(WIN32)
363
364 set (BOOST_CXX_FLAGS "-DBOOST_BIMAP_DISABLE_SERIALIZATION")
365
366 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS_C} ${MSVC_FLAGS} -D_REENTRANT")
367 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_CXX} ${MSVC_FLAGS} -D_REENTRANT ${BOOST_CXX_FLAGS}")
368 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}")
369
370 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS}
371     ${Boost_INCLUDE_DIRS}
372     ${ZLIB_INCLUDE_DIR}
373     ${OPENGL_INCLUDE_DIR}
374     ${OPENAL_INCLUDE_DIR}
375     ${SIMGEAR_INCLUDE_DIRS}
376     ${PLIB_INCLUDE_DIR}
377     ${SQLITE3_INCLUDED_DIR} )
378
379 include_directories(${PROJECT_SOURCE_DIR})
380 include_directories(${PROJECT_SOURCE_DIR}/src)
381 # following is needed, because config.h is include 'bare', whereas
382 # version.h is included as <Include/version.h> - this should be cleaned up
383 include_directories(${PROJECT_BINARY_DIR}/src)
384 include_directories(${PROJECT_BINARY_DIR}/src/Include)
385
386 if (ENABLE_FLITE)
387     include_directories(${PROJECT_SOURCE_DIR}/3rdparty/hts_engine_API/include )
388     include_directories(${PROJECT_SOURCE_DIR}/3rdparty/flite_hts_engine/include )
389 endif()
390
391 add_definitions(-DHAVE_CONFIG_H)
392
393 check_function_exists(mkfifo HAVE_MKFIFO)
394
395 # configure a header file to pass some of the CMake settings
396 # to the source code
397 configure_file (
398     "${PROJECT_SOURCE_DIR}/src/Include/config_cmake.h.in"
399     "${PROJECT_BINARY_DIR}/src/Include/config.h"
400 )
401
402 #and the same for the version header
403 configure_file (
404     "${PROJECT_SOURCE_DIR}/src/Include/version.h.cmake-in"
405     "${PROJECT_BINARY_DIR}/src/Include/version.h"
406 )
407
408 add_subdirectory(3rdparty)
409 add_subdirectory(utils)
410 add_subdirectory(src)
411 add_subdirectory(man)
412
413 #-----------------------------------------------------------------------------
414 ### uninstall target
415 #-----------------------------------------------------------------------------
416 CONFIGURE_FILE(
417     "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
418     "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
419     IMMEDIATE @ONLY)
420 ADD_CUSTOM_TARGET(uninstall
421     "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")