]> git.mxchange.org Git - simgear.git/blob - CMakeLists.txt
4ed9e8522e064c80d8174fff2e9763fec41a1ac9
[simgear.git] / CMakeLists.txt
1 cmake_minimum_required (VERSION 2.6.4)
2 include (CheckFunctionExists)
3 include (CheckIncludeFile)
4 include (CheckCXXSourceCompiles)
5
6
7 project(SimGear)
8
9 # read 'version' file into a variable (stripping any newlines or spaces)
10 file(READ version versionFile)
11 string(STRIP ${versionFile} SIMGEAR_VERSION)
12
13 # use simgear version also as the SO version (if building SOs)
14 SET(SIMGEAR_SOVERSION ${SIMGEAR_VERSION})
15
16 # Warning when build is not an out-of-source build.
17 string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" InSourceBuild)
18 if(InSourceBuild)
19     message(WARNING  "Avoid building inside the source tree!")
20     message(WARNING  "Create a separate build directory instead (i.e. 'sgbuild') and call CMake from there: ")
21     message(WARNING  "  mkdir ../sgbuild && cd ../sgbuild && cmake ${CMAKE_SOURCE_DIR}")
22 endif(InSourceBuild)
23
24 if (NOT EMBEDDED_SIMGEAR)
25     #packaging
26     SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")
27     SET(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README")
28     SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Simulation support libraries for FlightGear and related projects")
29     SET(CPACK_PACKAGE_VENDOR "The FlightGear project")
30     SET(CPACK_GENERATOR "TBZ2")
31     SET(CPACK_INSTALL_CMAKE_PROJECTS  ${CMAKE_CURRENT_BINARY_DIR};SimGear;ALL;/)
32
33
34     # split version string into components, note CMAKE_MATCH_0 is the entire regexp match
35     string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" CPACK_PACKAGE_VERSION ${SIMGEAR_VERSION} )
36     set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1}) 
37     set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
38     set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
39
40     message(STATUS "version is ${CPACK_PACKAGE_VERSION_MAJOR} dot ${CPACK_PACKAGE_VERSION_MINOR} dot ${CPACK_PACKAGE_VERSION_PATCH}")
41
42     set(CPACK_SOURCE_GENERATOR TBZ2)
43     set(CPACK_SOURCE_PACKAGE_FILE_NAME "simgear-${SIMGEAR_VERSION}" CACHE INTERNAL "tarball basename")
44     set(CPACK_SOURCE_IGNORE_FILES
45       "^${PROJECT_SOURCE_DIR}/.git;\\\\.gitignore;Makefile.am;~$;${CPACK_SOURCE_IGNORE_FILES}")
46
47     message(STATUS "ignoring: ${CPACK_SOURCE_IGNORE_FILES}")
48     
49     include (CPack)
50 endif()
51
52 # We have some custom .cmake scripts not in the official distribution.
53 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
54
55 # Change the default build type to something fast
56 if(NOT CMAKE_BUILD_TYPE)
57   set(CMAKE_BUILD_TYPE Release CACHE STRING
58       "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
59       FORCE)
60 endif(NOT CMAKE_BUILD_TYPE)
61
62 # Determine name of library installation directory, i.e. "lib" vs "lib64", which
63 # differs between all Debian-based vs all other Linux distros.
64 # See cmake bug #11964, http://cmake.org/gitweb?p=cmake.git;a=commit;h=126c993d
65 # GNUInstallDirs requires CMake >= 2.8.5, use own file for older cmake
66 if(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
67   include(GNUInstallDirs)
68 else(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
69   include(OldGNUInstallDirs)
70 endif(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
71 message(STATUS "Library installation directory: ${CMAKE_INSTALL_LIBDIR}")
72
73 #####################################################################################
74 # Configure library search paths
75 #####################################################################################
76
77 if(NOT "${CMAKE_LIBRARY_ARCHITECTURE}" STREQUAL "")
78     # Workaround for Ubuntu/Debian which introduced the "multiarch" library
79     # directory structure, which is unsupported by CMake < 2.8.10, so we need to
80     # add paths manually
81     # see http://www.cmake.org/Bug/view.php?id=12049 and
82     # http://www.cmake.org/Bug/view.php?id=12037
83     list(APPEND ADDITIONAL_LIBRARY_PATHS
84          /usr/local/lib/${CMAKE_LIBRARY_ARCHITECTURE}
85          /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}
86          /lib/${CMAKE_LIBRARY_ARCHITECTURE})
87     message(STATUS "additional library directories: ${ADDITIONAL_LIBRARY_PATHS}")
88 endif()
89
90 if(NOT MSVC)
91     # TBD: are these really necessary? Aren't they considered by cmake automatically?
92     list(APPEND ADDITIONAL_LIBRARY_PATHS
93          /opt/local
94          /usr/local
95          /usr)
96 endif()
97 #####################################################################################
98
99 if (NOT MSVC)
100 option(SIMGEAR_SHARED   "Set to ON to build SimGear as a shared library/framework" OFF)
101 option(SYSTEM_EXPAT     "Set to ON to build SimGear using the system libExpat" OFF)
102 else()
103 # Building SimGear DLLs is currently not supported for MSVC.
104 set(SIMGEAR_SHARED OFF)
105 # Using a system expat is currently not supported for MSVC - it would require shared simgear (DLL).
106 set(SYSTEM_EXPAT OFF)
107 endif()
108
109 option(SIMGEAR_HEADLESS "Set to ON to build SimGear without GUI/graphics support" OFF)
110 option(JPEG_FACTORY     "Enable JPEG-factory support" OFF)
111 option(SG_SVN_CLIENT    "Set to ON to build SimGear with built-in SVN support" OFF)
112 option(ENABLE_LIBSVN    "Set to ON to build SimGear with libsvnclient support" ON)
113 option(ENABLE_RTI       "Set to ON to build SimGear with RTI support" OFF)
114 option(ENABLE_TESTS     "Set to OFF to disable building SimGear's test applications" ON)
115 option(ENABLE_SOUND     "Set to OFF to disable building SimGear's sound support" ON)
116 option(ENABLE_PKGUTIL   "Set to ON to build the sg_pkgutil application (default)" ON)
117
118 if (MSVC)
119   GET_FILENAME_COMPONENT(PARENT_DIR ${PROJECT_BINARY_DIR} PATH)
120   if (CMAKE_CL_64)
121     SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty.x64")
122   else (CMAKE_CL_64)
123     SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty")
124   endif (CMAKE_CL_64)
125   if (EXISTS ${TEST_3RDPARTY_DIR})
126     set(MSVC_3RDPARTY_ROOT ${PARENT_DIR} CACHE PATH "Location where the third-party dependencies are extracted")
127   else (EXISTS ${TEST_3RDPARTY_DIR})
128     set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
129   endif (EXISTS ${TEST_3RDPARTY_DIR})
130 else (MSVC)
131   set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
132 endif (MSVC)
133
134 if (MSVC AND MSVC_3RDPARTY_ROOT)
135   message(STATUS "3rdparty files located in ${MSVC_3RDPARTY_ROOT}")
136   set( OSG_MSVC "msvc" )
137   if (${MSVC_VERSION} EQUAL 1700)
138       set( OSG_MSVC ${OSG_MSVC}110 )
139   elseif (${MSVC_VERSION} EQUAL 1600)
140       set( OSG_MSVC ${OSG_MSVC}100 )
141   else (${MSVC_VERSION} EQUAL 1700)
142       set( OSG_MSVC ${OSG_MSVC}90 )
143   endif (${MSVC_VERSION} EQUAL 1700)
144   if (CMAKE_CL_64)
145       set( OSG_MSVC ${OSG_MSVC}-64 )
146       set( MSVC_3RDPARTY_DIR 3rdParty.x64 )
147   else (CMAKE_CL_64)
148       set( MSVC_3RDPARTY_DIR 3rdParty )
149   endif (CMAKE_CL_64)
150
151   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}/OpenRTI/lib )
152   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}/OpenRTI/include)
153   find_path(BOOST_ROOT boost/version.hpp
154                         ${MSVC_3RDPARTY_ROOT}/boost
155                         ${MSVC_3RDPARTY_ROOT}/boost_1_52_0
156                         ${MSVC_3RDPARTY_ROOT}/boost_1_51_0
157                         ${MSVC_3RDPARTY_ROOT}/boost_1_50_0
158                         ${MSVC_3RDPARTY_ROOT}/boost_1_49_0
159                         ${MSVC_3RDPARTY_ROOT}/boost_1_48_0
160                         ${MSVC_3RDPARTY_ROOT}/boost_1_47_0
161                         ${MSVC_3RDPARTY_ROOT}/boost_1_46_1
162                         ${MSVC_3RDPARTY_ROOT}/boost_1_46_0
163                         ${MSVC_3RDPARTY_ROOT}/boost_1_45_0
164                         ${MSVC_3RDPARTY_ROOT}/boost_1_44_0
165                         )
166   # set (BOOST_ROOT ${MSVC_3RDPARTY_ROOT}/boost_1_44_0)
167   message(STATUS "BOOST_ROOT is ${BOOST_ROOT}")
168   set (OPENAL_INCLUDE_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include)
169   set (OPENAL_LIBRARY_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib)
170 endif (MSVC AND MSVC_3RDPARTY_ROOT)
171
172 if(APPLE)
173   find_library(CORE_SERVICES_LIBRARY CoreServices)
174 endif()
175
176 find_package(Boost REQUIRED)
177 set (BOOST_CXX_FLAGS "-DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_BIMAP_DISABLE_SERIALIZATION")
178
179 if(SIMGEAR_HEADLESS)
180     message(STATUS "SimGear mode: HEADLESS")
181     set(ENABLE_SOUND 0)
182 else()
183     message(STATUS "SimGear mode: NORMAL")
184     find_package(OpenGL REQUIRED)
185     
186     if (ENABLE_SOUND)
187         find_package(OpenAL REQUIRED)
188         message(STATUS "Sound support: ENABLED")
189     endif(ENABLE_SOUND)
190     
191     find_package(OpenSceneGraph 3.0.0 REQUIRED osgText osgSim osgDB osgParticle osgGA osgUtil)
192 endif(SIMGEAR_HEADLESS)
193
194 if(JPEG_FACTORY)
195     message(STATUS "JPEG-factory: ENABLED")
196     find_package(JPEG REQUIRED)
197     include_directories(${JPEG_INCLUDE_DIR})
198 else()
199     message(STATUS "JPEG-factory: DISABLED")
200 endif(JPEG_FACTORY)
201
202 if (SG_SVN_CLIENT)
203     message(STATUS "Using built-in subversion client code")
204 elseif(ENABLE_LIBSVN)
205     find_package(SvnClient)
206
207     if(LIBSVN_FOUND)
208         message(STATUS "Subversion client support: ENABLED")
209         set(HAVE_SVN_CLIENT_H 1)
210         set(HAVE_LIBSVN_CLIENT_1 1)
211     else()
212         # Oops. ENABLE_LIBSVN is ON, but svn is still missing.
213         # Provide clearly visible warning/hint, so builders know what else they should install (or disable).
214         message(WARNING "Failed to enable subversion client support. Unable to find required subversion client library. Some features may not be available (scenery download).")
215         message(WARNING "Install 'libsvn' library/DLL (libsvn-devel/libsvnclient/...). Otherwise disable subversion support (set 'ENABLE_LIBSVN' to 'OFF').")
216     endif(LIBSVN_FOUND)
217 else()
218     message(STATUS "Subversion client support: DISABLED")
219 endif(SG_SVN_CLIENT)
220
221 find_package(ZLIB REQUIRED)
222 find_package(Threads REQUIRED)
223
224 if (SYSTEM_EXPAT)
225     message(STATUS "Requested to use system Expat library, forcing SIMGEAR_SHARED to true")
226     set(SIMGEAR_SHARED ON)
227     find_package(EXPAT REQUIRED)
228     include_directories(${EXPAT_INCLUDE_DIRS})
229 else()
230     message(STATUS "Using built-in expat code")
231     add_definitions(-DHAVE_EXPAT_CONFIG_H)
232 endif(SYSTEM_EXPAT)
233
234 check_include_file(inttypes.h HAVE_INTTYPES_H)
235 check_include_file(sys/time.h HAVE_SYS_TIME_H)
236 check_include_file(sys/timeb.h HAVE_SYS_TIMEB_H)
237 check_include_file(unistd.h HAVE_UNISTD_H)
238 check_include_file(windows.h HAVE_WINDOWS_H)
239
240 if(HAVE_INTTYPES_H)
241   # ShivaVG needs inttypes.h
242   add_definitions(-DHAVE_INTTYPES_H)
243 endif()
244
245 if(ENABLE_RTI)
246     # See if we have any rti library variant installed
247     message(STATUS "RTI: ENABLED")
248     find_package(RTI)
249 else()
250     message(STATUS "RTI: DISABLED")
251 endif(ENABLE_RTI)
252
253 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
254 check_function_exists(ftime HAVE_FTIME)
255 check_function_exists(timegm HAVE_TIMEGM)
256 check_function_exists(rint HAVE_RINT)
257 check_function_exists(mkdtemp HAVE_MKDTEMP)
258 check_function_exists(bcopy HAVE_BCOPY)
259 check_function_exists(mmap HAVE_MMAP)
260
261 if(HAVE_UNISTD_H)
262     set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
263     check_cxx_source_compiles(
264        "#include <unistd.h>
265         #if !defined(_POSIX_TIMERS) || (0 >= _POSIX_TIMERS)
266             #error clock_gettime is not supported
267         #endif
268
269         int main() { return 0; }
270         "
271         HAVE_CLOCK_GETTIME)
272 endif(HAVE_UNISTD_H)
273
274 set(RT_LIBRARY "")
275 if(HAVE_CLOCK_GETTIME)
276     check_library_exists(rt clock_gettime "" HAVE_RT)
277     if(HAVE_RT)
278         set(RT_LIBRARY rt)
279     endif(HAVE_RT)
280 endif(HAVE_CLOCK_GETTIME)
281
282 SET(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually 'd' on windows")
283 SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
284 SET(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
285 SET(CMAKE_MINSIZEREL_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
286
287 # isnan might not be real symbol, so can't check using function_exists
288 check_cxx_source_compiles(
289     "#include <cmath> 
290     void f() { isnan(0.0);} "
291     HAVE_ISNAN)
292
293 check_cxx_source_compiles(
294     "#include <cmath> 
295     void f() { std::isnan(0.0);} "
296     HAVE_STD_ISNAN)
297
298 if(CMAKE_COMPILER_IS_GNUCXX)
299     set(WARNING_FLAGS_CXX "-Wall")
300     set(WARNING_FLAGS_C   "-Wall")
301
302     # certain GCC versions don't provide the atomic builds, and hence
303     # require is to provide them in SGAtomic.cxx
304     set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
305     check_cxx_source_compiles(
306        "int main() { unsigned mValue; return __sync_add_and_fetch(&mValue, 1); }"
307         GCC_ATOMIC_BUILTINS_FOUND)
308 endif(CMAKE_COMPILER_IS_GNUCXX)
309
310 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
311    set(WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual")
312    set(WARNING_FLAGS_C   "-Wall")
313 endif()
314
315 if(WIN32)
316
317     if(MINGW)
318         add_definitions(-D_WIN32_WINNT=0x501)
319     endif()
320
321     if(MSVC)
322         # turn off various warnings
323         # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
324         #     SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
325         # endforeach(warning)
326         
327         set(MSVC_FLAGS "-DWIN32 -DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS /wd4996 /wd4250 -Dstrdup=_strdup")
328         if (${MSVC_VERSION} GREATER 1599)
329             set( MSVC_LD_FLAGS "/FORCE:MULTIPLE" )
330         endif (${MSVC_VERSION} GREATER 1599)
331     endif(MSVC)
332     
333     # assumed on Windows
334     set(HAVE_GETLOCALTIME 1)
335     
336     set( WINSOCK_LIBRARY "ws2_32.lib" )
337     set( RT_LIBRARY "winmm" )
338 endif(WIN32)
339
340 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS_C} ${MSVC_FLAGS}")
341 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_CXX} ${MSVC_FLAGS} ${BOOST_CXX_FLAGS}")
342 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}")
343
344 include_directories(${PROJECT_SOURCE_DIR})
345 include_directories(${PROJECT_SOURCE_DIR}/simgear/canvas/ShivaVG/include)
346 include_directories(${PROJECT_BINARY_DIR}/simgear)
347 include_directories(${PROJECT_BINARY_DIR}/simgear/xml)
348
349 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS} 
350     ${Boost_INCLUDE_DIRS} 
351     ${ZLIB_INCLUDE_DIR} 
352     ${OPENAL_INCLUDE_DIR}
353     ${LibArchive_INCLUDE_DIRS}
354 )
355
356 add_definitions(-DHAVE_CONFIG_H)
357
358 # configure a header file to pass some of the CMake settings
359 # to the source code
360 configure_file (
361   "${PROJECT_SOURCE_DIR}/simgear/simgear_config_cmake.h.in"
362   "${PROJECT_BINARY_DIR}/simgear/simgear_config.h"
363   )
364
365 configure_file (
366     "${PROJECT_SOURCE_DIR}/simgear/xml/expat_config_cmake.in"
367     "${PROJECT_BINARY_DIR}/simgear/xml/expat_config.h"
368 )
369
370 if(ENABLE_TESTS)
371     # enable CTest / make test target
372     message(STATUS "Tests: ENABLED")
373
374     include (Dart)
375     enable_testing()
376 else()
377     message(STATUS "Tests: DISABLED")
378 endif(ENABLE_TESTS)
379
380 # always set TEST_LIBS as it is also used by other tools/applications
381 # TODO maybe better rename?
382 if(SIMGEAR_SHARED)
383     set( TEST_LIBS
384         SimGearCore)
385 else()
386     set( TEST_LIBS
387         SimGearCore
388         ${CMAKE_THREAD_LIBS_INIT}
389         ${ZLIB_LIBRARY}
390         ${WINSOCK_LIBRARY}
391         ${RT_LIBRARY}
392         ${CORE_SERVICES_LIBRARY})
393 endif()
394
395 if(NOT SIMGEAR_HEADLESS)
396     set( TEST_LIBS
397         SimGearScene
398         ${TEST_LIBS}
399         ${OPENGL_LIBRARIES})
400 endif()
401
402 install (FILES ${PROJECT_BINARY_DIR}/simgear/simgear_config.h  DESTINATION include/simgear/)
403 add_subdirectory(simgear)
404
405 if (NOT EMBEDDED_SIMGEAR)
406 #-----------------------------------------------------------------------------
407 ### uninstall target
408 #-----------------------------------------------------------------------------
409 CONFIGURE_FILE(
410   "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
411   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
412   IMMEDIATE @ONLY)
413 ADD_CUSTOM_TARGET(uninstall
414   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
415   
416 endif()
417