Merge branch 'next' of git://gitorious.org/fg/flightgear into next
[fg: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
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 "" CACHE STRING "add a postfix, usually empty on windows")
14 set(CMAKE_MINSIZEREL_POSTFIX "" 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
22 # split version string into components, note CMAKE_MATCH_0 is the entire regexp match
23 file(READ .gitignore CPACK_SOURCE_IGNORE_FILES)
24 string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" CPACK_PACKAGE_VERSION ${FLIGHTGEAR_VERSION} )
25 set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1}) 
26 set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
27 set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
28 SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")
29 SET(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README")
30
31 set(CPACK_SOURCE_GENERATOR TBZ2 ZIP)
32 set(CPACK_SOURCE_PACKAGE_FILE_NAME "flightgear-${FLIGHTGEAR_VERSION}" CACHE INTERNAL "tarball basename")
33 #set(CPACK_SOURCE_IGNORE_FILES
34 #  "^${PROJECT_SOURCE_DIR}/.git;\\\\.gitignore;Makefile.am;~$;${CPACK_SOURCE_IGNORE_FILES}")
35
36 include (CPack)
37
38 # We have some custom .cmake scripts not in the official distribution.
39 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
40
41 if (FG_DATA_DIR)
42     message(STATUS "Using explicit data-dir: ${FG_DATA_DIR}")
43 else()
44     set(FG_DATA_DIR "${CMAKE_INSTALL_PREFIX}/lib/FlightGear" CACHE PATH "Default location where data files are located")
45     message(STATUS "Using default data-dir:  ${FG_DATA_DIR}")
46 endif()
47
48 # Change the default build type to something fast
49 if(NOT CMAKE_BUILD_TYPE)
50   set(CMAKE_BUILD_TYPE Release CACHE STRING
51       "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
52       FORCE)
53 endif(NOT CMAKE_BUILD_TYPE)
54
55 if($ENV{BUILD_ID})
56         set(HUDSON_BUILD_ID $ENV{BUILD_ID})
57         set(HUDSON_BUILD_NUMBER $ENV{BUILD_NUMBER})
58         message(STATUS "running under Hudson, build-number is ${HUDSON_BUILD_NUMBER}")
59 else()
60         set(HUDSON_BUILD_NUMBER 0)
61         set(HUDSON_BUILD_ID "none")
62 endif()
63
64 IF(APPLE)
65     set(EVENT_INPUT_DEFAULT 1)
66     
67     find_library(CORESERVICES_LIBRARY CoreServices)
68     list(APPEND PLATFORM_LIBS ${CORESERVICES_LIBRARY})
69
70 elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
71     # disabled while DBus / HAL / udev issues are decided
72     #set(EVENT_INPUT_DEFAULT 1)
73 endif()
74
75 find_package(Git)
76 if (GIT_FOUND)
77         execute_process(COMMAND git --git-dir ${PROJECT_SOURCE_DIR}/.git rev-parse  HEAD
78                 OUTPUT_VARIABLE REVISION
79                 OUTPUT_STRIP_TRAILING_WHITESPACE)
80         message(STATUS "Git revision is ${REVISION}")
81 else()
82         set(REVISION "none")
83 endif()
84
85 option(LOGGING "Set to OFF to build FlightGear without logging" ON)
86
87 option(SP_FDMS "Set to ON to build FlightGear with special-purpose FDMs" OFF)
88 option(ENABLE_UIUC_MODEL "Set to ON to build FlightGear with UIUCModel FDM" OFF)
89 option(ENABLE_LARCSIM "Set to ON to build FlightGear with LaRCsim FDM" OFF)
90 option(ENABLE_YASIM "Set to ON to build FlightGear with YASIM FDM" ON)
91 option(ENABLE_JSBSIM "Set to ON to build FlightGear with JSBSim FDM" ON)
92 option(ENABLE_FGADMIN "Set to ON to build FlightGear with FGADMIN" ON)
93 option(EVENT_INPUT "Set to ON to build FlightGear with event-based Input support" ${EVENT_INPUT_DEFAULT})
94 option(ENABLE_LIBSVN "Set to ON to build FlightGear/terrasync with libsvnclient support" ON)
95 option(ENABLE_RTI "Set to ON to build SimGear with RTI support" OFF)
96 option(WITH_FGPANEL "Set to ON to build the fgpanel application" ON)
97 option(JPEG_FACTORY "Enable JPEG-factory support" OFF)
98
99 if (MSVC)
100   GET_FILENAME_COMPONENT(PARENT_DIR ${PROJECT_SOURCE_DIR} PATH)
101   if (CMAKE_CL_64)
102     SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty.x64")
103   else (CMAKE_CL_64)
104     SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty")
105   endif (CMAKE_CL_64)
106   if (EXISTS ${TEST_3RDPARTY_DIR})
107     set(MSVC_3RDPARTY_ROOT ${PARENT_DIR} CACHE PATH "Location where the third-party dependencies are extracted")
108   else (EXISTS ${TEST_3RDPARTY_DIR})
109     set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
110   endif (EXISTS ${TEST_3RDPARTY_DIR})
111   list(APPEND PLATFORM_LIBS "winmm.lib")
112 else (MSVC)
113   set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
114 endif (MSVC)
115
116 if(LOGGING)
117         # nothing
118 else()
119         set(FG_NDEBUG 1)
120 endif()
121
122 if(SP_FDMS)
123         set(ENABLE_SP_FDM 1)
124 endif()
125
126 if (MSVC AND MSVC_3RDPARTY_ROOT)
127   message(STATUS "3rdparty files located in ${MSVC_3RDPARTY_ROOT}")
128   set( OSG_MSVC "msvc" )
129   if (${MSVC_VERSION} EQUAL 1600)
130       set( OSG_MSVC ${OSG_MSVC}100 )
131   else (${MSVC_VERSION} EQUAL 1600)
132       set( OSG_MSVC ${OSG_MSVC}90 )
133   endif (${MSVC_VERSION} EQUAL 1600)
134   if (CMAKE_CL_64)
135       set( OSG_MSVC ${OSG_MSVC}-64 )
136           set( MSVC_3RDPARTY_DIR 3rdParty.x64 )
137   else (CMAKE_CL_64)
138           set( MSVC_3RDPARTY_DIR 3rdParty )
139   endif (CMAKE_CL_64)
140
141   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 )
142   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)
143   set (BOOST_ROOT ${MSVC_3RDPARTY_ROOT}/boost_1_44_0)
144   set (OPENAL_INCLUDE_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include)
145   set (ALUT_INCLUDE_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include)
146   set (OPENAL_LIBRARY_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib)
147 endif (MSVC AND MSVC_3RDPARTY_ROOT)
148
149 if(EVENT_INPUT)
150         message(STATUS "checking event-based Input")
151         
152         IF(APPLE)
153
154         elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
155         find_package(DBus)
156         if(NOT DBUS_FOUND)
157             message(WARNING "DBus not found, event input will be disabled")
158             set(EVENT_INPUT 0)
159         endif()
160         
161         else()
162                 message(WARNING "event input is not supported on this platform yet")
163         endif()
164 else(EVENT_INPUT)
165         set(ENABLE_PLIB_JOYSTICK 1)
166 endif(EVENT_INPUT)
167
168 # check required dependencies
169 find_package(Boost REQUIRED)
170 find_package(ZLIB REQUIRED)
171 find_package(Threads REQUIRED)
172 find_package(OpenGL REQUIRED)
173 find_package(OpenAL REQUIRED)
174 find_package(ALUT REQUIRED)
175 find_package(OpenSceneGraph 2.8.1 REQUIRED osgText osgSim osgDB osgParticle osgFX osgUtil osgViewer osgGA)
176
177 if(ENABLE_FGADMIN)
178   find_package(FLTK)
179 endif(ENABLE_FGADMIN)
180
181 if(ENABLE_LIBSVN)
182         find_package(SvnClient)
183         
184         if(LIBSVN_FOUND)
185                 message(STATUS "libsvn found, enabling in terrasync")
186                 set(HAVE_SVN_CLIENT_H 1)
187                 set(HAVE_LIBSVN_CLIENT_1 1)
188         endif(LIBSVN_FOUND)
189 endif(ENABLE_LIBSVN)
190
191 find_package(PLIB REQUIRED puaux pu js fnt)
192 find_package(SimGear 2.5.0 REQUIRED)
193
194 if (JPEG_FACTORY)
195     # check simgear was built with JPEG-factory support
196     find_package(JPEG REQUIRED)
197     include_directories(${JPEG_INCLUDE_DIR})
198     
199     set(CMAKE_REQUIRED_INCLUDES 
200         ${SIMGEAR_INCLUDE_DIR} 
201         ${JPEG_INCLUDE_DIR} 
202         ${OPENSCENEGRAPH_INCLUDE_DIRS})
203         
204     check_cxx_source_compiles(
205         "#include <simgear/screen/jpgfactory.hxx>
206         int main()    { return 0; } "
207         FG_JPEG_SERVER)
208         
209     if (NOT FG_JPEG_SERVER)
210         message(STATUS "JPEG server support requested, but SimGear was built without JPEG support")
211     endif()
212 endif()
213
214 check_include_file(unistd.h HAVE_UNISTD_H)
215 check_include_file(sys/time.h HAVE_SYS_TIME_H)
216 check_include_file(windows.h HAVE_WINDOWS_H)
217
218 # definition depends on OSG version
219 set(CMAKE_REQUIRED_INCLUDES ${OPENSCENEGRAPH_INCLUDE_DIRS})
220
221 check_cxx_source_compiles(
222     "#include <osg/CullSettings>
223     int main()
224     {
225        osg::CullSettings::VariablesMask mask = osg::CullSettings::CLEAR_MASK;
226        return 0;
227     }
228     "
229     HAVE_CULLSETTINGS_CLEAR_MASK)
230
231 if(ENABLE_RTI)
232     find_package(RTI)
233     if(RTI_FOUND)
234         set(FG_HAVE_HLA 1)
235     endif(RTI_FOUND)
236 endif(ENABLE_RTI)
237
238 if(CMAKE_COMPILER_IS_GNUCXX)
239     set(WARNING_FLAGS -Wall)
240 endif(CMAKE_COMPILER_IS_GNUCXX)
241
242 if(WIN32)
243
244     if(MSVC)
245         # turn off various warnings
246         # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
247         #     SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
248         # endforeach(warning)
249         
250         set(MSVC_FLAGS "-DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS")
251         if (${MSVC_VERSION} EQUAL 1600)
252                   set( MSVC_LD_FLAGS "/FORCE:MULTIPLE" )
253         endif (${MSVC_VERSION} EQUAL 1600)
254     endif(MSVC)
255
256     set(NOMINMAX 1)
257 endif(WIN32)    
258
259 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT")
260 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT")
261 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}")
262
263 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS}
264         ${Boost_INCLUDE_DIRS}
265         ${ZLIB_INCLUDE_DIR}
266         ${ALUT_INCLUDE_DIR}
267         ${OPENAL_INCLUDE_DIR}
268         ${SIMGEAR_INCLUDE_DIR}
269         ${PLIB_INCLUDE_DIR} )
270
271 include_directories(${PROJECT_SOURCE_DIR}/src)
272
273 # following is needed, because config.h is include 'bare', whereas
274 # version.h is included as <Include/version.h> - this should be cleaned up
275 include_directories(${PROJECT_BINARY_DIR}/src)
276 include_directories(${PROJECT_BINARY_DIR}/src/Include)
277
278 add_definitions(-DHAVE_CONFIG_H)
279
280 check_function_exists(mkfifo HAVE_MKFIFO)
281
282 # configure a header file to pass some of the CMake settings
283 # to the source code
284 configure_file (
285   "${PROJECT_SOURCE_DIR}/src/Include/config_cmake.h.in"
286   "${PROJECT_BINARY_DIR}/src/Include/config.h"
287   )
288
289 #and the same for the version header
290 configure_file (
291   "${PROJECT_SOURCE_DIR}/src/Include/version.h.cmake-in"
292   "${PROJECT_BINARY_DIR}/src/Include/version.h"
293   ) 
294
295 add_subdirectory(src)
296 add_subdirectory(utils)
297 add_subdirectory(man)
298
299 set (INSTALL_DOCS 
300     README
301         README.OpenAL
302         README.plib
303         README.OSG
304         README.SimGear)
305
306 INSTALL(FILES ${INSTALL_DOCS} DESTINATION doc OPTIONAL)
307
308 #-----------------------------------------------------------------------------
309 ### uninstall target
310 #-----------------------------------------------------------------------------
311 CONFIGURE_FILE(
312   "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
313   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
314   IMMEDIATE @ONLY)
315 ADD_CUSTOM_TARGET(uninstall
316   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
317