1 cmake_minimum_required (VERSION 2.6.4)
3 include (CheckFunctionExists)
4 include (CheckCSourceCompiles)
5 include (CheckCXXSourceCompiles)
6 include (CheckIncludeFile)
10 # We have some custom .cmake scripts not in the official distribution.
11 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
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)
21 # Warning when build is not an out-of-source build.
22 string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" 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}")
29 # System detection/default settings
30 include( DetectDistro )
31 include( DetectBrowser )
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")
38 # read 'version' file into a variable (stripping any newlines or spaces)
39 file(READ version versionFile)
41 message(FATAL_ERROR "Unable to determine FlightGear version. Version file is missing.")
43 string(STRIP "${versionFile}" FLIGHTGEAR_VERSION)
45 # FlightGear packaging (to build a source tarball)
46 include( ConfigureCPack )
48 # FlightGear base package path
50 message(STATUS "Using explicit data directory for base package: ${FG_DATA_DIR}")
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}")
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."
61 endif(NOT CMAKE_BUILD_TYPE)
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}")
68 set(HUDSON_BUILD_NUMBER 0)
69 set(HUDSON_BUILD_ID "none")
72 #####################################################################################
73 # Configure library search paths
74 #####################################################################################
77 # Custom library directories for Mac, which should have precedence over any other
78 list(APPEND ADDITIONAL_LIBRARY_PATHS
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
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}")
97 # TBD: are these really necessary? Aren't they considered by cmake automatically?
98 list(APPEND ADDITIONAL_LIBRARY_PATHS
103 #####################################################################################
106 set(EVENT_INPUT_DEFAULT 1)
108 find_library(CORESERVICES_LIBRARY CoreServices)
109 find_library(COCOA_LIBRARY Cocoa)
110 list(APPEND PLATFORM_LIBS ${COCOA_LIBRARY} ${CORESERVICES_LIBRARY})
112 elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
116 set(EVENT_INPUT_DEFAULT 1)
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}")
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)
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)
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)
156 option(ENABLE_METAR "Set to ON to build the metar application (default)" ON)
158 option(ENABLE_TESTS "Set to ON to build test applications (default)" ON)
170 # Setup MSVC 3rd party directories
171 include( ConfigureMsvc3rdParty )
175 elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
177 message(WARNING "UDev not found, event input is disabled!")
180 add_definitions(-DWITH_EVENTINPUT)
181 set(EVENT_INPUT_LIBRARIES ${UDEV_LIBRARIES})
182 message(STATUS "event-based input enabled. Using ${UDEV_LIBRARIES}")
185 message(WARNING "event-based input is not supported on this platform yet")
188 # Keep PLIB INPUT enabled as long as EventInput does not replace current joystick configurations.
189 set(ENABLE_PLIB_JOYSTICK 1)
191 set(ENABLE_PLIB_JOYSTICK 1)
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)
206 if ( X11_Xinerama_FOUND )
207 message(STATUS "Found X11_Xinerama...")
208 list(APPEND FLTK_LIBRARIES ${X11_Xinerama_LIB})
212 message(STATUS "Found X11_Xft...")
213 list(APPEND FLTK_LIBRARIES ${X11_Xft_LIB})
216 message(STATUS "Using FLTK_LIBRARIES for fgadmin: ${FLTK_LIBRARIES}")
218 endif(ENABLE_FGADMIN)
221 find_package(SvnClient)
224 message(STATUS "libsvn found, enabling in terrasync")
225 set(HAVE_SVN_CLIENT_H 1)
226 set(HAVE_LIBSVN_CLIENT_1 1)
228 message(STATUS "libsvn missing. Disabling...")
233 find_package(SQLite3 REQUIRED)
234 set(CMAKE_REQUIRED_INCLUDES ${SQLITE3_INCLUDED_DIR})
235 message(STATUS "Using system SQLite3 library")
236 endif (SYSTEM_SQLITE)
238 # Sqlite always depends on the threading lib
239 list(APPEND SQLITE3_LIBRARY ${CMAKE_THREAD_LIBS_INIT})
241 find_package(PLIB REQUIRED puaux pu js fnt)
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)
250 if (NOT SIMGEAR_SHARED)
251 set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES
252 ${CMAKE_THREAD_LIBS_INIT}
257 set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES
260 else(EMBEDDED_SIMGEAR)
261 # FlightGear and SimGear versions need to match
262 find_package(SimGear ${FLIGHTGEAR_VERSION} REQUIRED)
263 endif (EMBEDDED_SIMGEAR)
266 # check simgear was built with JPEG-factory support
267 find_package(JPEG REQUIRED)
268 include_directories(${JPEG_INCLUDE_DIR})
270 set(CMAKE_REQUIRED_INCLUDES
271 ${SIMGEAR_INCLUDE_DIR}
273 ${OPENSCENEGRAPH_INCLUDE_DIRS})
275 check_cxx_source_compiles(
276 "#include <simgear/screen/jpgfactory.hxx>
277 int main() { return 0; } "
280 if (NOT FG_JPEG_SERVER)
281 message(STATUS "JPEG server support requested, but SimGear was built without JPEG support")
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)
290 find_package(GooglePerfTools REQUIRED)
291 set(FG_HAVE_GPERFTOOLS 1)
292 message(STATUS "Built-in profiler using gperftools available")
296 message(STATUS "RTI: ENABLED")
302 message(STATUS "RTI: DISABLED")
305 if(CMAKE_COMPILER_IS_GNUCXX)
306 set(WARNING_FLAGS_CXX "-Wall")
307 set(WARNING_FLAGS_C "-Wall")
308 endif(CMAKE_COMPILER_IS_GNUCXX)
310 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
311 set (WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual")
312 set (WARNING_FLAGS_C "-Wall")
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)
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)
332 set (BOOST_CXX_FLAGS "-DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_BIMAP_DISABLE_SERIALIZATION")
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}")
338 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS}
339 ${Boost_INCLUDE_DIRS}
341 ${OPENGL_INCLUDE_DIR}
342 ${OPENAL_INCLUDE_DIR}
343 ${SIMGEAR_INCLUDE_DIR}
344 ${PLIB_INCLUDE_DIR} )
346 include_directories(${PROJECT_SOURCE_DIR}/src)
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)
353 add_definitions(-DHAVE_CONFIG_H)
355 check_function_exists(mkfifo HAVE_MKFIFO)
357 # configure a header file to pass some of the CMake settings
360 "${PROJECT_SOURCE_DIR}/src/Include/config_cmake.h.in"
361 "${PROJECT_BINARY_DIR}/src/Include/config.h"
364 #and the same for the version header
366 "${PROJECT_SOURCE_DIR}/src/Include/version.h.cmake-in"
367 "${PROJECT_BINARY_DIR}/src/Include/version.h"
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
375 include_directories(${PROJECT_BINARY_DIR}/simgear)
376 endif(EMBEDDED_SIMGEAR)
378 add_subdirectory(src)
379 add_subdirectory(utils)
380 add_subdirectory(man)
382 #-----------------------------------------------------------------------------
384 #-----------------------------------------------------------------------------
386 "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
387 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
389 ADD_CUSTOM_TARGET(uninstall
390 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")