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_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)
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)
172 # Setup MSVC 3rd party directories
173 include( ConfigureMsvc3rdParty )
177 elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
179 message(WARNING "UDev not found, event input is disabled!")
182 add_definitions(-DWITH_EVENTINPUT)
183 set(EVENT_INPUT_LIBRARIES ${UDEV_LIBRARIES})
184 message(STATUS "event-based input enabled. Using ${UDEV_LIBRARIES}")
187 message(WARNING "event-based input is not supported on this platform yet")
190 # Keep PLIB INPUT enabled as long as EventInput does not replace current joystick configurations.
191 set(ENABLE_PLIB_JOYSTICK 1)
193 set(ENABLE_PLIB_JOYSTICK 1)
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)
208 if ( X11_Xinerama_FOUND )
209 message(STATUS "Found X11_Xinerama...")
210 list(APPEND FLTK_LIBRARIES ${X11_Xinerama_LIB})
214 message(STATUS "Found X11_Xft...")
215 list(APPEND FLTK_LIBRARIES ${X11_Xft_LIB})
219 list(APPEND FLTK_LIBRARIES ${CMAKE_DL_LIBS})
222 message(STATUS "Using FLTK_LIBRARIES for fgadmin: ${FLTK_LIBRARIES}")
224 endif(ENABLE_FGADMIN)
226 ##############################################################################
230 find_package(SQLite3 REQUIRED)
232 message(STATUS "Using system SQLite3 library")
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)
239 # Sqlite always depends on the threading lib
240 list(APPEND SQLITE3_LIBRARY ${CMAKE_THREAD_LIBS_INIT})
242 ##############################################################################
244 find_package(PLIB REQUIRED puaux pu js fnt)
246 # FlightGear and SimGear versions need to match
247 find_package(SimGear ${FLIGHTGEAR_VERSION} REQUIRED)
249 ##############################################################################
252 # check simgear was built with JPEG-factory support
253 find_package(JPEG REQUIRED)
254 include_directories(${JPEG_INCLUDE_DIR})
256 set(CMAKE_REQUIRED_INCLUDES
257 ${SIMGEAR_INCLUDE_DIR}
259 ${OPENSCENEGRAPH_INCLUDE_DIRS})
261 check_cxx_source_compiles(
262 "#include <simgear/screen/jpgfactory.hxx>
263 int main() { return 0; } "
266 if (NOT FG_JPEG_SERVER)
267 message(STATUS "JPEG server support requested, but SimGear was built without JPEG support")
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)
276 find_package(GooglePerfTools REQUIRED)
277 set(FG_HAVE_GPERFTOOLS 1)
278 message(STATUS "Built-in profiler using gperftools available")
282 message(STATUS "RTI: ENABLED")
288 message(STATUS "RTI: DISABLED")
291 if(CMAKE_COMPILER_IS_GNUCXX)
292 set(WARNING_FLAGS_CXX "-Wall")
293 set(WARNING_FLAGS_C "-Wall")
294 endif(CMAKE_COMPILER_IS_GNUCXX)
296 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
297 set (WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual")
298 set (WARNING_FLAGS_C "-Wall")
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)
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)
318 set (BOOST_CXX_FLAGS "-DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_BIMAP_DISABLE_SERIALIZATION")
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}")
324 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS}
325 ${Boost_INCLUDE_DIRS}
327 ${OPENGL_INCLUDE_DIR}
328 ${OPENAL_INCLUDE_DIR}
329 ${SIMGEAR_INCLUDE_DIR}
331 ${SQLITE3_INCLUDED_DIR} )
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)
341 add_definitions(-DHAVE_CONFIG_H)
343 check_function_exists(mkfifo HAVE_MKFIFO)
345 # configure a header file to pass some of the CMake settings
348 "${PROJECT_SOURCE_DIR}/src/Include/config_cmake.h.in"
349 "${PROJECT_BINARY_DIR}/src/Include/config.h"
352 #and the same for the version header
354 "${PROJECT_SOURCE_DIR}/src/Include/version.h.cmake-in"
355 "${PROJECT_BINARY_DIR}/src/Include/version.h"
358 add_subdirectory(3rdparty)
359 add_subdirectory(utils)
360 add_subdirectory(src)
361 add_subdirectory(man)
363 #-----------------------------------------------------------------------------
365 #-----------------------------------------------------------------------------
367 "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
368 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
370 ADD_CUSTOM_TARGET(uninstall
371 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")