]> git.mxchange.org Git - flightgear.git/blob - CMakeLists.txt
Reset: delete mat-lib, re-create on reset
[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_RTI        "Set to ON to build FlightGear with RTI support" OFF)
140 option(ENABLE_PROFILE    "Set to ON to build FlightGear with gperftools profiling support" OFF)
141 option(JPEG_FACTORY      "Set to ON to build FlightGear with JPEG-factory support" OFF)
142 option(SYSTEM_SQLITE     "Set to ON to build FlightGear with the system's SQLite3 library" OFF)
143 option(ENABLE_IAX        "Set to ON to build FlightGear with IAXClient/fgcom built-in (default)" ON)
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 option(ENABLE_FGJS       "Set to ON to build the fgjs application (default)" ON)
153 option(ENABLE_JS_DEMO    "Set to ON to build the js_demo application (default)" ON)
154 option(ENABLE_METAR      "Set to ON to build the metar application (default)" ON)
155 option(ENABLE_TESTS      "Set to ON to build test applications (default)" ON)
156 option(ENABLE_FGCOM      "Set to ON to build the FGCom application (default)" ON)
157
158 if(LOGGING)
159     # nothing
160 else()
161     set(FG_NDEBUG 1)
162 endif()
163
164 if(SP_FDMS)
165     set(ENABLE_SP_FDM 1)
166 endif()
167
168 if(ENABLE_FGCOM)
169   set(ENABLE_IAX 1)
170 endif()
171
172 # Setup MSVC 3rd party directories
173 include( ConfigureMsvc3rdParty )
174
175 if(EVENT_INPUT)
176     if(APPLE)
177     elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
178         if(NOT UDEV_FOUND)
179             message(WARNING "UDev not found, event input is disabled!")
180             set(EVENT_INPUT 0)
181         else()
182             add_definitions(-DWITH_EVENTINPUT)
183             set(EVENT_INPUT_LIBRARIES ${UDEV_LIBRARIES})
184             message(STATUS "event-based input enabled. Using ${UDEV_LIBRARIES}")
185         endif()
186     else()
187         message(WARNING "event-based input is not supported on this platform yet")
188     endif()
189
190     # Keep PLIB INPUT enabled as long as EventInput does not replace current joystick configurations.
191     set(ENABLE_PLIB_JOYSTICK 1)
192 else(EVENT_INPUT)
193     set(ENABLE_PLIB_JOYSTICK 1)
194 endif(EVENT_INPUT)
195
196 # check required dependencies
197 find_package(Boost   REQUIRED)
198 find_package(ZLIB    REQUIRED)
199 find_package(Threads REQUIRED)
200 find_package(OpenGL  REQUIRED)
201 find_package(OpenAL  REQUIRED)
202 find_package(OpenSceneGraph 3.0.0 REQUIRED osgText osgSim osgDB osgParticle osgFX osgUtil osgViewer osgGA)
203
204 if(ENABLE_FGADMIN)
205     find_package(FLTK)
206
207     if ( FLTK_FOUND )
208         if ( X11_Xinerama_FOUND )
209             message(STATUS "Found X11_Xinerama...")
210             list(APPEND FLTK_LIBRARIES ${X11_Xinerama_LIB})
211         endif()
212
213         if ( X11_Xft_FOUND )
214             message(STATUS "Found X11_Xft...")
215             list(APPEND FLTK_LIBRARIES ${X11_Xft_LIB})
216         endif()
217
218         if ( CMAKE_DL_LIBS )
219             list(APPEND FLTK_LIBRARIES ${CMAKE_DL_LIBS})
220         endif()
221
222         message(STATUS "Using FLTK_LIBRARIES for fgadmin: ${FLTK_LIBRARIES}")
223     endif ( FLTK_FOUND )
224 endif(ENABLE_FGADMIN)
225
226 ##############################################################################
227 ## Sqlite3 setup
228
229 if (SYSTEM_SQLITE)
230     find_package(SQLite3 REQUIRED)
231     
232     message(STATUS "Using system SQLite3 library")
233 else()
234     set(SQLITE3_INCLUDED_DIR "${CMAKE_SOURCE_DIR}/3rdparty/sqlite3")
235     # this target is defined in src/Navaids/CMakeLists.txt
236     list(APPEND SQLITE3_LIBRARY fgsqlite3)
237 endif (SYSTEM_SQLITE)
238
239 # Sqlite always depends on the threading lib
240 list(APPEND SQLITE3_LIBRARY ${CMAKE_THREAD_LIBS_INIT})
241
242 ##############################################################################
243
244 find_package(PLIB REQUIRED puaux pu js fnt)
245
246 # FlightGear and SimGear versions need to match
247 find_package(SimGear ${FLIGHTGEAR_VERSION} REQUIRED)
248
249 ##############################################################################
250
251 if (JPEG_FACTORY)
252     # check simgear was built with JPEG-factory support
253     find_package(JPEG REQUIRED)
254     include_directories(${JPEG_INCLUDE_DIR})
255
256     set(CMAKE_REQUIRED_INCLUDES
257         ${SIMGEAR_INCLUDE_DIR}
258         ${JPEG_INCLUDE_DIR}
259         ${OPENSCENEGRAPH_INCLUDE_DIRS})
260
261     check_cxx_source_compiles(
262         "#include <simgear/screen/jpgfactory.hxx>
263         int main()    { return 0; } "
264         FG_JPEG_SERVER)
265
266     if (NOT FG_JPEG_SERVER)
267         message(STATUS "JPEG server support requested, but SimGear was built without JPEG support")
268     endif()
269 endif()
270
271 check_include_file(unistd.h   HAVE_UNISTD_H)
272 check_include_file(sys/time.h HAVE_SYS_TIME_H)
273 check_include_file(windows.h  HAVE_WINDOWS_H)
274
275 if(ENABLE_PROFILE)
276     find_package(GooglePerfTools REQUIRED)
277     set(FG_HAVE_GPERFTOOLS 1)
278     message(STATUS "Built-in profiler using gperftools available")
279 endif()
280
281 if(ENABLE_RTI)
282     message(STATUS "RTI: ENABLED")
283     find_package(RTI)
284     if(RTI_FOUND)
285         set(FG_HAVE_HLA 1)
286     endif(RTI_FOUND)
287 else()
288     message(STATUS "RTI: DISABLED")
289 endif(ENABLE_RTI)
290
291 if(CMAKE_COMPILER_IS_GNUCXX)
292     set(WARNING_FLAGS_CXX "-Wall")
293     set(WARNING_FLAGS_C   "-Wall")
294 endif(CMAKE_COMPILER_IS_GNUCXX)
295
296 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 
297    set (WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual")
298    set (WARNING_FLAGS_C   "-Wall")
299 endif() 
300
301 if(WIN32)
302
303     if(MSVC)
304         # turn off various warnings
305         # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
306         #     SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
307         # endforeach(warning)
308
309         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")
310         if (${MSVC_VERSION} GREATER 1599)
311             set( MSVC_LD_FLAGS "/FORCE:MULTIPLE" )
312         endif (${MSVC_VERSION} GREATER 1599)
313     endif(MSVC)
314
315     set(NOMINMAX 1)
316 endif(WIN32)
317
318 set (BOOST_CXX_FLAGS "-DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_BIMAP_DISABLE_SERIALIZATION")
319
320 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS_C} ${MSVC_FLAGS} -D_REENTRANT")
321 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_CXX} ${MSVC_FLAGS} -D_REENTRANT ${BOOST_CXX_FLAGS}")
322 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}")
323
324 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS}
325     ${Boost_INCLUDE_DIRS}
326     ${ZLIB_INCLUDE_DIR}
327     ${OPENGL_INCLUDE_DIR}
328     ${OPENAL_INCLUDE_DIR}
329     ${SIMGEAR_INCLUDE_DIR}
330     ${PLIB_INCLUDE_DIR}
331     ${SQLITE3_INCLUDED_DIR} )
332
333 include_directories(${PROJECT_SOURCE_DIR})
334 include_directories(${PROJECT_SOURCE_DIR}/src)
335 include_directories(${PROJECT_SOURCE_DIR}/3rdparty/iaxclient/lib ) # for iaxclient.h
336 # following is needed, because config.h is include 'bare', whereas
337 # version.h is included as <Include/version.h> - this should be cleaned up
338 include_directories(${PROJECT_BINARY_DIR}/src)
339 include_directories(${PROJECT_BINARY_DIR}/src/Include)
340
341 add_definitions(-DHAVE_CONFIG_H)
342
343 check_function_exists(mkfifo HAVE_MKFIFO)
344
345 # configure a header file to pass some of the CMake settings
346 # to the source code
347 configure_file (
348     "${PROJECT_SOURCE_DIR}/src/Include/config_cmake.h.in"
349     "${PROJECT_BINARY_DIR}/src/Include/config.h"
350 )
351
352 #and the same for the version header
353 configure_file (
354     "${PROJECT_SOURCE_DIR}/src/Include/version.h.cmake-in"
355     "${PROJECT_BINARY_DIR}/src/Include/version.h"
356 )
357
358 add_subdirectory(3rdparty)
359 add_subdirectory(utils)
360 add_subdirectory(src)
361 add_subdirectory(man)
362
363 #-----------------------------------------------------------------------------
364 ### uninstall target
365 #-----------------------------------------------------------------------------
366 CONFIGURE_FILE(
367     "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
368     "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
369     IMMEDIATE @ONLY)
370 ADD_CUSTOM_TARGET(uninstall
371     "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")