]> git.mxchange.org Git - flightgear.git/blob - CMakeLists.txt
Win32 fix
[flightgear.git] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.6)
2
3 include (CheckFunctionExists)
4 include (CheckCSourceCompiles)
5 include (CheckCXXSourceCompiles)
6 include (CheckIncludeFile)
7 include (CPack)
8
9 project(FlightGear)
10
11 file(READ version FLIGHTGEAR_VERSION)
12
13 #packaging
14 SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")
15 SET(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README")
16
17 # We have some custom .cmake scripts not in the official distribution.
18 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
19
20 # autoconf compatibility
21 set(PKGLIBDIR "foo")
22
23 option(LOGGING "Set to OFF to build FlightGear without logging" ON)
24
25 option(SP_FDMS "Set to ON to build FlightGear with special-purpose FDMs" OFF)
26 option(ENABLE_UIUC_MODEL "Set to ON to build FlightGear with UIUCModel FDM" ON)
27 option(ENABLE_LARCSIM "Set to ON to build FlightGear with LaRCsim FDM" ON)
28 option(ENABLE_YASIM "Set to ON to build FlightGear with YASIM FDM" ON)
29 option(ENABLE_JSBSIM "Set to ON to build FlightGear with JSBSim FDM" ON)
30 option(EVENT_INPUT "Set to ON to build FlightGear with event-based Input support" OFF)
31
32 if(LOGGING)
33         # nothing
34 else()
35         set(FG_NDEBUG 1)
36 endif()
37
38 if(${SP_FDMS})
39         set(ENABLE_SP_FDM 1)
40 endif()
41
42 if(EVENT_INPUT)
43         message(STATUS "checking event-based Input")
44         IF(APPLE)
45                 
46         elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
47                 
48         else()
49                 message(WARNING "event input is not supported on this platform yet")
50         endif()
51 else(EVENT_INPUT)
52         set(ENABLE_PLIB_JOYSTICK 1)
53 endif(EVENT_INPUT)
54
55 # check required dependencies
56 if (MSVC)
57     # on MSVC, Olaf reports that the serialization library is required at
58     # link time. No one has you explained why, unfortunately.
59     set(Boost_USE_STATIC_LIBS        ON)
60     set(Boost_USE_MULTITHREADED      ON)
61     set(Boost_USE_STATIC_RUNTIME    OFF)
62     find_package(Boost REQUIRED COMPONENTS serialization)
63 else (MSVC)
64     find_package(Boost REQUIRED)
65 endif (MSVC)
66
67 find_package(ZLIB REQUIRED)
68 find_package(Threads REQUIRED)
69 find_package(OpenGL REQUIRED)
70 find_package(OpenAL REQUIRED)
71 find_package(ALUT REQUIRED)
72 find_package(OpenSceneGraph 2.8.2 REQUIRED osgText osgSim osgDB osgParticle osgFX osgUtil osgViewer osgGA)
73 find_package(PLIB REQUIRED puaux pu js fnt)
74 find_package(SimGear 2.0.0 REQUIRED)
75
76 check_include_file(unistd.h HAVE_UNISTD_H)
77 check_include_file(sys/time.h HAVE_SYS_TIME_H)
78
79 # definition depends on OSG version
80 set(CMAKE_REQUIRED_INCLUDES ${OPENSCENEGRAPH_INCLUDE_DIRS})
81
82 check_cxx_source_compiles(
83     "#include <osg/CullSettings>
84     int main()
85     {
86        osg::CullSettings::VariablesMask mask = osg::CullSettings::CLEAR_MASK;
87        return 0;
88     }
89     "
90     HAVE_CULLSETTINGS_CLEAR_MASK)
91
92 # library required by simgear
93 # XXX This should go in a module and only run if simgear is not shared.
94
95 if(HAVE_UNISTD_H)
96 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
97 check_cxx_source_compiles(
98    "#include <unistd.h>
99     #if !defined(_POSIX_TIMERS) || (0 >= _POSIX_TIMERS)
100     #error clock_gettime is not supported
101     #endif
102
103     int main() { return 0; }
104     "
105     HAVE_CLOCK_GETTIME)    
106 endif(HAVE_UNISTD_H)
107
108 set(RT_LIBRARY "")
109 if(HAVE_CLOCK_GETTIME)
110 check_function_exists(clock_gettime CLOCK_GETTIME_IN_LIBC)
111 if(NOT CLOCK_GETTIME_IN_LIBC)
112 check_library_exists(rt clock_gettime "" HAVE_RT)
113 if(HAVE_RT)
114 set(RT_LIBRARY rt)
115 endif(HAVE_RT)
116 endif(NOT CLOCK_GETTIME_IN_LIBC)
117 endif(HAVE_CLOCK_GETTIME)
118
119 if(CMAKE_COMPILER_IS_GNUCXX)
120     set(WARNING_FLAGS -Wall)
121 endif(CMAKE_COMPILER_IS_GNUCXX)
122
123 if(WIN32)
124
125     if(MSVC)
126         # turn off various warnings
127         # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
128         #     SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
129         # endforeach(warning)
130         
131         set(MSVC_FLAGS "-DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS")
132     endif(MSVC)
133
134     set(NOMINMAX 1)
135 endif(WIN32)    
136
137 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT")
138 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT")
139
140 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS} 
141     ${Boost_INCLUDE_DIRS} 
142         ${ZLIB_INCLUDE_DIR} 
143     ${ALUT_INCLUDE_DIR}
144         ${OPENAL_INCLUDE_DIR}
145         ${SIMGEAR_INCLUDE_DIR}
146         ${PLIB_INCLUDE_DIR} )
147
148 include_directories(${PROJECT_SOURCE_DIR}/src)
149 include_directories(${PROJECT_BINARY_DIR}/src/Include)
150
151 add_definitions(-DHAVE_CONFIG_H)
152
153 # configure a header file to pass some of the CMake settings
154 # to the source code
155 configure_file (
156   "${PROJECT_SOURCE_DIR}/src/Include/config_cmake.h.in"
157   "${PROJECT_BINARY_DIR}/src/Include/config.h"
158   )
159   
160 add_subdirectory(src)
161 add_subdirectory(utils)
162
163 #-----------------------------------------------------------------------------
164 ### uninstall target
165 #-----------------------------------------------------------------------------
166 CONFIGURE_FILE(
167   "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
168   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
169   IMMEDIATE @ONLY)
170 ADD_CUSTOM_TARGET(uninstall
171   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
172