]> git.mxchange.org Git - flightgear.git/blob - CMakeLists.txt
Precipitation updates from ThorstenR
[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
77 if(NOT "${CMAKE_LIBRARY_ARCHITECTURE}" STREQUAL "")
78     # Workaround for Ubuntu/Debian which introduced the "multiarch" library
79     # directory structure, which is unsupported by CMake < 2.8.10, so we need to
80     # add paths manually
81     # see http://www.cmake.org/Bug/view.php?id=12049 and
82     # http://www.cmake.org/Bug/view.php?id=12037
83     list(APPEND ADDITIONAL_LIBRARY_PATHS
84          /usr/local/lib/${CMAKE_LIBRARY_ARCHITECTURE}
85          /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}
86          /lib/${CMAKE_LIBRARY_ARCHITECTURE})
87     message(STATUS "additional library directories: ${ADDITIONAL_LIBRARY_PATHS}")
88 endif()
89
90 #####################################################################################
91
92 IF(APPLE)
93     set(EVENT_INPUT_DEFAULT 1)
94
95     find_library(CORESERVICES_LIBRARY CoreServices)
96     find_library(COCOA_LIBRARY Cocoa)
97     list(APPEND PLATFORM_LIBS ${COCOA_LIBRARY} ${CORESERVICES_LIBRARY})
98
99 elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
100     set(USE_DBUS_DEFAULT 1)
101     find_package(UDev)
102
103     if(UDEV_FOUND)
104         set(EVENT_INPUT_DEFAULT 1)
105     endif(UDEV_FOUND)
106
107     find_package(Speex)
108     find_package(Speexdsp)
109     if(SPEEX_FOUND AND SPEEXDSP_FOUND)
110         set(SYSTEM_SPEEX_DEFAULT 1)
111     endif(SPEEX_FOUND AND SPEEXDSP_FOUND)
112
113     find_package(Gsm)
114     if(GSM_FOUND)
115         set(SYSTEM_GSM_DEFAULT 1)
116     endif(GSM_FOUND)
117
118     find_package(Flite)
119     if(FLITE_FOUND)
120         set(SYSTEM_FLITE_DEFAULT 1)
121     endif()
122
123     find_package(HtsEngine)
124     if(HTS_ENGINE_FOUND)
125         set(SYSTEM_HTS_ENGINE_DEFAULT 1)
126     endif()
127 endif()
128
129 find_package(Git)
130 if (GIT_FOUND)
131     execute_process(COMMAND git --git-dir ${PROJECT_SOURCE_DIR}/.git rev-parse  HEAD
132         OUTPUT_VARIABLE REVISION
133         OUTPUT_STRIP_TRAILING_WHITESPACE)
134     message(STATUS "Git revision is ${REVISION}")
135 else()
136     set(REVISION "none")
137 endif()
138
139 # FlightGear build options
140 option(SIMGEAR_SHARED    "Set to ON when SimGear was built as a shared library" OFF)
141 option(LOGGING           "Set to ON to build FlightGear with logging support (default)" ON)
142 option(JSBSIM_TERRAIN    "Set to ON to build FlightGear with JSBSim terrain handling code" ON)
143 option(SP_FDMS           "Set to ON to build FlightGear with special-purpose FDMs" OFF)
144 option(ENABLE_UIUC_MODEL "Set to ON to build FlightGear with UIUCModel FDM" OFF)
145 option(ENABLE_LARCSIM    "Set to ON to build FlightGear with LaRCsim FDM" OFF)
146 option(ENABLE_YASIM      "Set to ON to build FlightGear with YASIM FDM (default)" ON)
147 option(ENABLE_JSBSIM     "Set to ON to build FlightGear with JSBSim FDM (default)" ON)
148 option(EVENT_INPUT       "Set to ON to build FlightGear with event-based Input support" ${EVENT_INPUT_DEFAULT})
149 option(ENABLE_RTI        "Set to ON to build FlightGear with RTI support" OFF)
150 option(ENABLE_PROFILE    "Set to ON to build FlightGear with gperftools profiling support" OFF)
151 option(SYSTEM_SQLITE     "Set to ON to build FlightGear with the system's SQLite3 library" OFF)
152 option(ENABLE_IAX        "Set to ON to build FlightGear with IAXClient/fgcom built-in (default)" ON)
153 option(USE_DBUS          "Set to ON to build FlightGear with DBus screensaver interaction (default on Linux)" ${USE_DBUS_DEFAULT})
154 option(SYSTEM_SPEEX      "Set to ON to build IAXClient with the system's speex and speexdsp library" ${SYSTEM_SPEEX_DEFAULT})
155 option(SYSTEM_GSM        "Set to ON to build IAXClient with the system's GSM library" ${SYSTEM_GSM_DEFAULT})
156 option(SYSTEM_FLITE      "Set to ON to build Flightgear with the system's Flite library" ${SYSTEM_FLITE_DEFAULT})
157 option(SYSTEM_HTS_ENGINE "Set to ON to build Flightgear with the system's HTS Engine library" ${SYSTEM_HTS_ENGINE_DEFAULT})
158
159 # additional utilities
160 option(ENABLE_FGADMIN    "Set to ON to build the FGADMIN application (default)" ON)
161 option(ENABLE_FGELEV     "Set to ON to build the fgelev application (default)" ON)
162 option(WITH_FGPANEL      "Set to ON to build the fgpanel application (default)" ON)
163 option(ENABLE_FGVIEWER   "Set to ON to build the fgviewer application (default)" ON)
164 option(ENABLE_GPSSMOOTH  "Set to ON to build the GPSsmooth application (default)" ON)
165 option(ENABLE_TERRASYNC  "Set to ON to build the terrasync application (default)" ON)
166 option(ENABLE_FGJS       "Set to ON to build the fgjs application (default)" ON)
167 option(ENABLE_JS_DEMO    "Set to ON to build the js_demo application (default)" ON)
168 option(ENABLE_METAR      "Set to ON to build the metar application (default)" ON)
169 option(ENABLE_TESTS      "Set to ON to build test applications (default)" ON)
170 option(ENABLE_FGCOM      "Set to ON to build the FGCom application (default)" ON)
171 option(ENABLE_FLITE      "Set to ON to build the Flite text-to-speech module" ON)
172
173 if(LOGGING)
174     # nothing
175 else()
176     set(FG_NDEBUG 1)
177 endif()
178
179 if(JSBSIM_TERRAIN)
180    set(JSBSIM_USE_GROUNDREACTIONS 1)
181 endif()
182
183 if(SP_FDMS)
184     set(ENABLE_SP_FDM 1)
185 endif()
186
187 if(ENABLE_FGCOM)
188   set(ENABLE_IAX 1)
189   include_directories(${PROJECT_SOURCE_DIR}/3rdparty/iaxclient/lib ) # for iaxclient.h
190 endif()
191
192 # Setup MSVC 3rd party directories
193 include( ConfigureMsvc3rdParty )
194
195 if(EVENT_INPUT)
196     if(APPLE)
197     elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
198         if(NOT UDEV_FOUND)
199             message(WARNING "UDev not found, event input is disabled!")
200             set(EVENT_INPUT 0)
201         else()
202             add_definitions(-DWITH_EVENTINPUT)
203             set(EVENT_INPUT_LIBRARIES ${UDEV_LIBRARIES})
204             message(STATUS "event-based input enabled. Using ${UDEV_LIBRARIES}")
205         endif()
206     else()
207         message(WARNING "event-based input is not supported on this platform yet")
208     endif()
209
210     # Keep PLIB INPUT enabled as long as EventInput does not replace current joystick configurations.
211     set(ENABLE_PLIB_JOYSTICK 1)
212 else(EVENT_INPUT)
213     set(ENABLE_PLIB_JOYSTICK 1)
214 endif(EVENT_INPUT)
215
216 # check required dependencies
217 find_package(Boost   REQUIRED)
218 find_package(ZLIB    REQUIRED)
219 find_package(Threads REQUIRED)
220 find_package(OpenGL  REQUIRED)
221 find_package(OpenAL  REQUIRED)
222 find_package(OpenSceneGraph 3.2.0 REQUIRED
223   osgText
224   osgSim
225   osgDB
226   osgParticle
227   osgFX
228   osgUtil
229   osgViewer
230   osgGA
231 )
232
233 if (MSVC)
234         find_package(CrashRpt)
235         if (CRASHRPT_FOUND)
236                 set(HAVE_CRASHRPT 1)
237                 message(STATUS "Using CrashRpt")
238         include_directories( ${CRASHRPT_INCLUDE_DIR})
239         endif()
240 endif()
241
242 ##############################################################################
243 ## Sqlite3 setup
244
245 if (SYSTEM_SQLITE)
246     find_package(SQLite3 REQUIRED)
247     
248     message(STATUS "Using system SQLite3 library")
249 else()
250     set(SQLITE3_INCLUDED_DIR "${CMAKE_SOURCE_DIR}/3rdparty/sqlite3")
251     # this target is defined in src/Navaids/CMakeLists.txt
252     list(APPEND SQLITE3_LIBRARY fgsqlite3)
253 endif (SYSTEM_SQLITE)
254
255 # Sqlite always depends on the threading lib
256 list(APPEND SQLITE3_LIBRARY ${CMAKE_THREAD_LIBS_INIT})
257
258 ##############################################################################
259 ## DBus setup
260
261 if (USE_DBUS)
262     include(FindPkgConfig)
263     if (PKG_CONFIG_FOUND)
264         pkg_check_modules(DBUS dbus-1)
265     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
266     if (DBUS_FOUND)
267         set(HAVE_DBUS 1)
268         message(STATUS "Using DBus")
269         include_directories( ${DBUS_INCLUDE_DIRS})
270     else()
271         message(STATUS "DBus not found, screensaver control disabled")
272     endif (DBUS_FOUND)
273 else()
274 endif (USE_DBUS)
275
276 # Sqlite always depends on the threading lib
277 list(APPEND SQLITE3_LIBRARY ${CMAKE_THREAD_LIBS_INIT})
278
279 ##############################################################################
280
281 find_package(PLIB REQUIRED puaux pu js fnt)
282
283 # FlightGear and SimGear versions need to match
284 find_package(SimGear ${FLIGHTGEAR_VERSION} REQUIRED)
285
286 ##############################################################################
287
288 check_include_file(unistd.h   HAVE_UNISTD_H)
289 check_include_file(sys/time.h HAVE_SYS_TIME_H)
290 check_include_file(windows.h  HAVE_WINDOWS_H)
291
292 if(ENABLE_PROFILE)
293     find_package(GooglePerfTools REQUIRED)
294     set(FG_HAVE_GPERFTOOLS 1)
295     message(STATUS "Built-in profiler using gperftools available")
296 endif()
297
298 if(ENABLE_RTI)
299     message(STATUS "RTI: ENABLED")
300     find_package(RTI)
301     if(RTI_FOUND)
302         set(FG_HAVE_HLA 1)
303     endif(RTI_FOUND)
304 else()
305     message(STATUS "RTI: DISABLED")
306 endif(ENABLE_RTI)
307
308 if(CMAKE_COMPILER_IS_GNUCXX)
309     set(WARNING_FLAGS_CXX "-Wall")
310     set(WARNING_FLAGS_C   "-Wall")
311 endif(CMAKE_COMPILER_IS_GNUCXX)
312
313 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 
314    set (WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual")
315    set (WARNING_FLAGS_C   "-Wall")
316 endif() 
317
318 if(WIN32)
319
320     if(MSVC)
321         # turn off various warnings
322         # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
323         #     SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
324         # endforeach(warning)
325
326         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")
327         if (${MSVC_VERSION} GREATER 1599)
328             set( MSVC_LD_FLAGS "/FORCE:MULTIPLE" )
329         endif (${MSVC_VERSION} GREATER 1599)
330     endif(MSVC)
331
332     set(NOMINMAX 1)
333 endif(WIN32)
334
335 set (BOOST_CXX_FLAGS "-DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_BIMAP_DISABLE_SERIALIZATION")
336
337 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS_C} ${MSVC_FLAGS} -D_REENTRANT")
338 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_CXX} ${MSVC_FLAGS} -D_REENTRANT ${BOOST_CXX_FLAGS}")
339 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}")
340
341 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS}
342     ${Boost_INCLUDE_DIRS}
343     ${ZLIB_INCLUDE_DIR}
344     ${OPENGL_INCLUDE_DIR}
345     ${OPENAL_INCLUDE_DIR}
346     ${SIMGEAR_INCLUDE_DIRS}
347     ${PLIB_INCLUDE_DIR}
348     ${SQLITE3_INCLUDED_DIR} )
349
350 include_directories(${PROJECT_SOURCE_DIR})
351 include_directories(${PROJECT_SOURCE_DIR}/src)
352 # following is needed, because config.h is include 'bare', whereas
353 # version.h is included as <Include/version.h> - this should be cleaned up
354 include_directories(${PROJECT_BINARY_DIR}/src)
355 include_directories(${PROJECT_BINARY_DIR}/src/Include)
356
357 if (ENABLE_FLITE)
358     include_directories(${PROJECT_SOURCE_DIR}/3rdparty/hts_engine_API/include )
359     include_directories(${PROJECT_SOURCE_DIR}/3rdparty/flite_hts_engine/include )
360 endif()
361
362 add_definitions(-DHAVE_CONFIG_H)
363
364 check_function_exists(mkfifo HAVE_MKFIFO)
365
366 # configure a header file to pass some of the CMake settings
367 # to the source code
368 configure_file (
369     "${PROJECT_SOURCE_DIR}/src/Include/config_cmake.h.in"
370     "${PROJECT_BINARY_DIR}/src/Include/config.h"
371 )
372
373 #and the same for the version header
374 configure_file (
375     "${PROJECT_SOURCE_DIR}/src/Include/version.h.cmake-in"
376     "${PROJECT_BINARY_DIR}/src/Include/version.h"
377 )
378
379 add_subdirectory(3rdparty)
380 add_subdirectory(utils)
381 add_subdirectory(src)
382 add_subdirectory(man)
383
384 #-----------------------------------------------------------------------------
385 ### uninstall target
386 #-----------------------------------------------------------------------------
387 CONFIGURE_FILE(
388     "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
389     "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
390     IMMEDIATE @ONLY)
391 ADD_CUSTOM_TARGET(uninstall
392     "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")