Merge branch 'next' into durk-atc
[fg:hoorays-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 set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually d on windows")
12 set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
13 set(CMAKE_RELWITHDEBINFO_POSTFIX "rd" CACHE STRING "add a postfix, usually empty on windows")
14 set(CMAKE_MINSIZEREL_POSTFIX "s" CACHE STRING "add a postfix, usually empty on windows")
15
16 # read 'version' file into a variable (stripping any newlines or spaces)
17 file(READ version versionFile)
18 string(STRIP ${versionFile} FLIGHTGEAR_VERSION) 
19
20 #packaging
21 SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")
22 SET(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README")
23
24 # We have some custom .cmake scripts not in the official distribution.
25 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
26
27 # autoconf compatibility
28 set(PKGLIBDIR "foo")
29
30 if($ENV{BUILD_ID})
31         set(HUDSON_BUILD_ID $ENV{BUILD_ID})
32         set(HUDSON_BUILD_NUMBER $ENV{BUILD_NUMBER})
33         message(STATUS "running under Hudson, build-number is ${HUDSON_BUILD_NUMBER}")
34 else()
35         set(HUDSON_BUILD_NUMBER 0)
36         set(HUDSON_BUILD_ID "none")
37 endif()
38
39 find_package(Git)
40 if (GIT_FOUND)
41         execute_process(COMMAND git --git-dir ${PROJECT_SOURCE_DIR}/.git rev-parse  HEAD
42                 OUTPUT_VARIABLE REVISION
43                 OUTPUT_STRIP_TRAILING_WHITESPACE)
44         message(STATUS "Git revision is ${REVISION}")
45 else()
46         set(REVISION "none")
47 endif()
48
49 option(LOGGING "Set to OFF to build FlightGear without logging" ON)
50
51 option(SP_FDMS "Set to ON to build FlightGear with special-purpose FDMs" OFF)
52 option(ENABLE_UIUC_MODEL "Set to ON to build FlightGear with UIUCModel FDM" ON)
53 option(ENABLE_LARCSIM "Set to ON to build FlightGear with LaRCsim FDM" ON)
54 option(ENABLE_YASIM "Set to ON to build FlightGear with YASIM FDM" ON)
55 option(ENABLE_JSBSIM "Set to ON to build FlightGear with JSBSim FDM" ON)
56 option(ENABLE_FGADMIN "Set to ON to build FlightGear with FGADMIN" ON)
57 option(EVENT_INPUT "Set to ON to build FlightGear with event-based Input support" OFF)
58 option(ENABLE_LIBSVN "Set to ON to build terrasync with libsvnclient support" OFF)
59
60 set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
61
62 if(LOGGING)
63         # nothing
64 else()
65         set(FG_NDEBUG 1)
66 endif()
67
68 if(${SP_FDMS})
69         set(ENABLE_SP_FDM 1)
70 endif()
71
72 if(EVENT_INPUT)
73         message(STATUS "checking event-based Input")
74         IF(APPLE)
75
76         elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
77
78         else()
79                 message(WARNING "event input is not supported on this platform yet")
80         endif()
81 else(EVENT_INPUT)
82         set(ENABLE_PLIB_JOYSTICK 1)
83 endif(EVENT_INPUT)
84
85 if (MSVC AND MSVC_3RDPARTY_ROOT)
86   message(STATUS "3rdparty files located in ${MSVC_3RDPARTY_ROOT}")
87   set( OSG_MSVC "msvc" )
88   if (${MSVC_VERSION} EQUAL 1600)
89       set( OSG_MSVC ${OSG_MSVC}100 )
90   else (${MSVC_VERSION} EQUAL 1600)
91       set( OSG_MSVC ${OSG_MSVC}90 )
92   endif (${MSVC_VERSION} EQUAL 1600)
93   if (CMAKE_CL_64)
94       set( OSG_MSVC ${OSG_MSVC}-64 )
95           set( MSVC_3RDPARTY_DIR 3rdParty.x64 )
96   else (CMAKE_CL_64)
97           set( MSVC_3RDPARTY_DIR 3rdParty )
98   endif (CMAKE_CL_64)
99
100   set (CMAKE_LIBRARY_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenScenegraph/lib ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/SimGear/lib )
101   set (CMAKE_INCLUDE_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenScenegraph/include ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/SimGear/include)
102   set (BOOST_ROOT ${MSVC_3RDPARTY_ROOT}/boost_1_44_0)
103   set (OPENAL_INCLUDE_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include)
104   set (ALUT_INCLUDE_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include)
105   set (OPENAL_LIBRARY_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib)
106 endif (MSVC AND MSVC_3RDPARTY_ROOT)
107
108
109 # check required dependencies
110 find_package(Boost REQUIRED)
111 find_package(ZLIB REQUIRED)
112 find_package(Threads REQUIRED)
113 find_package(OpenGL REQUIRED)
114 find_package(OpenAL REQUIRED)
115 find_package(ALUT REQUIRED)
116 find_package(OpenSceneGraph 2.8.1 REQUIRED osgText osgSim osgDB osgParticle osgFX osgUtil osgViewer osgGA)
117
118 if(ENABLE_FGADMIN)
119   find_package(FLTK)
120 endif(ENABLE_FGADMIN)
121
122 if(ENABLE_LIBSVN)
123         find_package(SvnClient)
124         
125         if(LIBSVN_FOUND)
126                 message(STATUS "libsvn found, enabling in terrasync")
127                 set(HAVE_SVN_CLIENT_H 1)
128                 set(HAVE_LIBSVN_CLIENT_1 1)
129         endif(LIBSVN_FOUND)
130 endif(ENABLE_LIBSVN)
131
132 find_package(PLIB REQUIRED puaux pu js fnt)
133 find_package(SimGear 2.2.0 REQUIRED)
134
135 check_include_file(unistd.h HAVE_UNISTD_H)
136 check_include_file(sys/time.h HAVE_SYS_TIME_H)
137 check_include_file(windows.h HAVE_WINDOWS_H)
138
139 # definition depends on OSG version
140 set(CMAKE_REQUIRED_INCLUDES ${OPENSCENEGRAPH_INCLUDE_DIRS})
141
142 check_cxx_source_compiles(
143     "#include <osg/CullSettings>
144     int main()
145     {
146        osg::CullSettings::VariablesMask mask = osg::CullSettings::CLEAR_MASK;
147        return 0;
148     }
149     "
150     HAVE_CULLSETTINGS_CLEAR_MASK)
151
152 # library required by simgear
153 # XXX This should go in a module and only run if simgear is not shared.
154
155 if(HAVE_UNISTD_H)
156 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
157 check_cxx_source_compiles(
158    "#include <unistd.h>
159     #if !defined(_POSIX_TIMERS) || (0 >= _POSIX_TIMERS)
160     #error clock_gettime is not supported
161     #endif
162
163     int main() { return 0; }
164     "
165     HAVE_CLOCK_GETTIME)    
166 endif(HAVE_UNISTD_H)
167
168 set(RT_LIBRARY "")
169 if(HAVE_CLOCK_GETTIME)
170 check_function_exists(clock_gettime CLOCK_GETTIME_IN_LIBC)
171 if(NOT CLOCK_GETTIME_IN_LIBC)
172 check_library_exists(rt clock_gettime "" HAVE_RT)
173 if(HAVE_RT)
174 set(RT_LIBRARY rt)
175 endif(HAVE_RT)
176 endif(NOT CLOCK_GETTIME_IN_LIBC)
177 endif(HAVE_CLOCK_GETTIME)
178
179 find_package(RTI)
180 if(RTI_FOUND)
181   set(FG_HAVE_HLA 1)
182 endif()
183
184 if(CMAKE_COMPILER_IS_GNUCXX)
185     set(WARNING_FLAGS -Wall)
186 endif(CMAKE_COMPILER_IS_GNUCXX)
187
188 if(WIN32)
189
190     if(MSVC)
191         # turn off various warnings
192         # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
193         #     SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
194         # endforeach(warning)
195         
196         set(MSVC_FLAGS "-DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS")
197         if (${MSVC_VERSION} EQUAL 1600)
198                   set( MSVC_LD_FLAGS "/FORCE:MULTIPLE" )
199         endif (${MSVC_VERSION} EQUAL 1600)
200     endif(MSVC)
201
202     set(NOMINMAX 1)
203     set( WINSOCK_LIBRARY "ws2_32.lib" )
204 endif(WIN32)    
205
206 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT")
207 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT")
208 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}")
209
210 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS}
211     ${Boost_INCLUDE_DIRS}
212         ${ZLIB_INCLUDE_DIR}
213     ${ALUT_INCLUDE_DIR}
214         ${OPENAL_INCLUDE_DIR}
215         ${SIMGEAR_INCLUDE_DIR}
216         ${PLIB_INCLUDE_DIR} )
217
218 include_directories(${PROJECT_SOURCE_DIR}/src)
219
220 # following is needed, because config.h is include 'bare', whereas
221 # version.h is included as <Include/version.h> - this should be cleaned up
222 include_directories(${PROJECT_BINARY_DIR}/src)
223 include_directories(${PROJECT_BINARY_DIR}/src/Include)
224
225 add_definitions(-DHAVE_CONFIG_H)
226
227 # configure a header file to pass some of the CMake settings
228 # to the source code
229 configure_file (
230   "${PROJECT_SOURCE_DIR}/src/Include/config_cmake.h.in"
231   "${PROJECT_BINARY_DIR}/src/Include/config.h"
232   )
233
234 #and the same for the version header
235 configure_file (
236   "${PROJECT_SOURCE_DIR}/src/Include/version.h.cmake-in"
237   "${PROJECT_BINARY_DIR}/src/Include/version.h"
238   ) 
239
240 add_subdirectory(src)
241 add_subdirectory(utils)
242
243 #-----------------------------------------------------------------------------
244 ### uninstall target
245 #-----------------------------------------------------------------------------
246 CONFIGURE_FILE(
247   "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
248   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
249   IMMEDIATE @ONLY)
250 ADD_CUSTOM_TARGET(uninstall
251   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
252