]> git.mxchange.org Git - simgear.git/blob - CMakeLists.txt
Missing library for Apple
[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
117 if (MSVC)
118   GET_FILENAME_COMPONENT(PARENT_DIR ${PROJECT_BINARY_DIR} PATH)
119   if (CMAKE_CL_64)
120     SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty.x64")
121   else (CMAKE_CL_64)
122     SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty")
123   endif (CMAKE_CL_64)
124   if (EXISTS ${TEST_3RDPARTY_DIR})
125     set(MSVC_3RDPARTY_ROOT ${PARENT_DIR} CACHE PATH "Location where the third-party dependencies are extracted")
126   else (EXISTS ${TEST_3RDPARTY_DIR})
127     set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
128   endif (EXISTS ${TEST_3RDPARTY_DIR})
129 else (MSVC)
130   set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
131 endif (MSVC)
132
133 if (MSVC AND MSVC_3RDPARTY_ROOT)
134   message(STATUS "3rdparty files located in ${MSVC_3RDPARTY_ROOT}")
135   set( OSG_MSVC "msvc" )
136   if (${MSVC_VERSION} EQUAL 1700)
137       set( OSG_MSVC ${OSG_MSVC}110 )
138   elseif (${MSVC_VERSION} EQUAL 1600)
139       set( OSG_MSVC ${OSG_MSVC}100 )
140   else (${MSVC_VERSION} EQUAL 1700)
141       set( OSG_MSVC ${OSG_MSVC}90 )
142   endif (${MSVC_VERSION} EQUAL 1700)
143   if (CMAKE_CL_64)
144       set( OSG_MSVC ${OSG_MSVC}-64 )
145       set( MSVC_3RDPARTY_DIR 3rdParty.x64 )
146   else (CMAKE_CL_64)
147       set( MSVC_3RDPARTY_DIR 3rdParty )
148   endif (CMAKE_CL_64)
149
150   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 )
151   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)
152   find_path(BOOST_ROOT boost/version.hpp
153                         ${MSVC_3RDPARTY_ROOT}/boost
154                         ${MSVC_3RDPARTY_ROOT}/boost_1_52_0
155                         ${MSVC_3RDPARTY_ROOT}/boost_1_51_0
156                         ${MSVC_3RDPARTY_ROOT}/boost_1_50_0
157                         ${MSVC_3RDPARTY_ROOT}/boost_1_49_0
158                         ${MSVC_3RDPARTY_ROOT}/boost_1_48_0
159                         ${MSVC_3RDPARTY_ROOT}/boost_1_47_0
160                         ${MSVC_3RDPARTY_ROOT}/boost_1_46_1
161                         ${MSVC_3RDPARTY_ROOT}/boost_1_46_0
162                         ${MSVC_3RDPARTY_ROOT}/boost_1_45_0
163                         ${MSVC_3RDPARTY_ROOT}/boost_1_44_0
164                         )
165   # set (BOOST_ROOT ${MSVC_3RDPARTY_ROOT}/boost_1_44_0)
166   message(STATUS "BOOST_ROOT is ${BOOST_ROOT}")
167   set (OPENAL_INCLUDE_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include)
168   set (OPENAL_LIBRARY_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib)
169 endif (MSVC AND MSVC_3RDPARTY_ROOT)
170
171 find_package(Boost REQUIRED)
172 set (BOOST_CXX_FLAGS "-DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_BIMAP_DISABLE_SERIALIZATION")
173
174 if(SIMGEAR_HEADLESS)
175     message(STATUS "SimGear mode: HEADLESS")
176     set(ENABLE_SOUND 0)
177 else()
178     message(STATUS "SimGear mode: NORMAL")
179     find_package(OpenGL REQUIRED)
180     
181     if (ENABLE_SOUND)
182         find_package(OpenAL REQUIRED)
183         message(STATUS "Sound support: ENABLED")
184     endif(ENABLE_SOUND)
185     
186     find_package(OpenSceneGraph 3.0.0 REQUIRED osgText osgSim osgDB osgParticle osgGA osgUtil)
187 endif(SIMGEAR_HEADLESS)
188
189 if(JPEG_FACTORY)
190     message(STATUS "JPEG-factory: ENABLED")
191     find_package(JPEG REQUIRED)
192     include_directories(${JPEG_INCLUDE_DIR})
193 else()
194     message(STATUS "JPEG-factory: DISABLED")
195 endif(JPEG_FACTORY)
196
197 if (SG_SVN_CLIENT)
198     message(STATUS "Using built-in subversion client code")
199 elseif(ENABLE_LIBSVN)
200     find_package(SvnClient)
201
202     if(LIBSVN_FOUND)
203         message(STATUS "Subversion client support: ENABLED")
204         set(HAVE_SVN_CLIENT_H 1)
205         set(HAVE_LIBSVN_CLIENT_1 1)
206     else()
207         # Oops. ENABLE_LIBSVN is ON, but svn is still missing.
208         # Provide clearly visible warning/hint, so builders know what else they should install (or disable).
209         message(WARNING "Failed to enable subversion client support. Unable to find required subversion client library. Some features may not be available (scenery download).")
210         message(WARNING "Install 'libsvn' library/DLL (libsvn-devel/libsvnclient/...). Otherwise disable subversion support (set 'ENABLE_LIBSVN' to 'OFF').")
211     endif(LIBSVN_FOUND)
212 else()
213     message(STATUS "Subversion client support: DISABLED")
214 endif(SG_SVN_CLIENT)
215
216 find_package(ZLIB REQUIRED)
217 find_package(Threads REQUIRED)
218
219 if (SYSTEM_EXPAT)
220     message(STATUS "Requested to use system Expat library, forcing SIMGEAR_SHARED to true")
221     set(SIMGEAR_SHARED ON)
222     find_package(EXPAT REQUIRED)
223     include_directories(${EXPAT_INCLUDE_DIRS})
224 else()
225     message(STATUS "Using built-in expat code")
226     add_definitions(-DHAVE_EXPAT_CONFIG_H)
227 endif(SYSTEM_EXPAT)
228
229 check_include_file(inttypes.h HAVE_INTTYPES_H)
230 check_include_file(sys/time.h HAVE_SYS_TIME_H)
231 check_include_file(sys/timeb.h HAVE_SYS_TIMEB_H)
232 check_include_file(unistd.h HAVE_UNISTD_H)
233 check_include_file(windows.h HAVE_WINDOWS_H)
234
235 if(HAVE_INTTYPES_H)
236   # ShivaVG needs inttypes.h
237   add_definitions(-DHAVE_INTTYPES_H)
238 endif()
239
240 if(ENABLE_RTI)
241     # See if we have any rti library variant installed
242     message(STATUS "RTI: ENABLED")
243     find_package(RTI)
244 else()
245     message(STATUS "RTI: DISABLED")
246 endif(ENABLE_RTI)
247
248 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
249 check_function_exists(ftime HAVE_FTIME)
250 check_function_exists(timegm HAVE_TIMEGM)
251 check_function_exists(rint HAVE_RINT)
252 check_function_exists(mkdtemp HAVE_MKDTEMP)
253 check_function_exists(bcopy HAVE_BCOPY)
254 check_function_exists(mmap HAVE_MMAP)
255
256 if(HAVE_UNISTD_H)
257     set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
258     check_cxx_source_compiles(
259        "#include <unistd.h>
260         #if !defined(_POSIX_TIMERS) || (0 >= _POSIX_TIMERS)
261             #error clock_gettime is not supported
262         #endif
263
264         int main() { return 0; }
265         "
266         HAVE_CLOCK_GETTIME)
267 endif(HAVE_UNISTD_H)
268
269 set(RT_LIBRARY "")
270 if(HAVE_CLOCK_GETTIME)
271     check_library_exists(rt clock_gettime "" HAVE_RT)
272     if(HAVE_RT)
273         set(RT_LIBRARY rt)
274     endif(HAVE_RT)
275 endif(HAVE_CLOCK_GETTIME)
276
277 SET(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually 'd' on windows")
278 SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
279 SET(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
280 SET(CMAKE_MINSIZEREL_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
281
282 # isnan might not be real symbol, so can't check using function_exists
283 check_cxx_source_compiles(
284     "#include <cmath> 
285     void f() { isnan(0.0);} "
286     HAVE_ISNAN)
287
288 check_cxx_source_compiles(
289     "#include <cmath> 
290     void f() { std::isnan(0.0);} "
291     HAVE_STD_ISNAN)
292
293 if(CMAKE_COMPILER_IS_GNUCXX)
294     set(WARNING_FLAGS_CXX "-Wall")
295     set(WARNING_FLAGS_C   "-Wall")
296
297     # certain GCC versions don't provide the atomic builds, and hence
298     # require is to provide them in SGAtomic.cxx
299     set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
300     check_cxx_source_compiles(
301        "int main() { unsigned mValue; return __sync_add_and_fetch(&mValue, 1); }"
302         GCC_ATOMIC_BUILTINS_FOUND)
303 endif(CMAKE_COMPILER_IS_GNUCXX)
304
305 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
306    set(WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual")
307    set(WARNING_FLAGS_C   "-Wall")
308 endif()
309
310 if(WIN32)
311
312     if(MINGW)
313         add_definitions(-D_WIN32_WINNT=0x501)
314     endif()
315
316     if(MSVC)
317         # turn off various warnings
318         # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
319         #     SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
320         # endforeach(warning)
321         
322         set(MSVC_FLAGS "-DWIN32 -DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS /wd4996 /wd4250 -Dstrdup=_strdup")
323         if (${MSVC_VERSION} GREATER 1599)
324             set( MSVC_LD_FLAGS "/FORCE:MULTIPLE" )
325         endif (${MSVC_VERSION} GREATER 1599)
326     endif(MSVC)
327     
328     # assumed on Windows
329     set(HAVE_GETLOCALTIME 1)
330     
331     set( WINSOCK_LIBRARY "ws2_32.lib" )
332     set( RT_LIBRARY "winmm" )
333 endif(WIN32)
334
335 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS_C} ${MSVC_FLAGS}")
336 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_CXX} ${MSVC_FLAGS} ${BOOST_CXX_FLAGS}")
337 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}")
338
339 include_directories(${PROJECT_SOURCE_DIR})
340 include_directories(${PROJECT_SOURCE_DIR}/simgear/canvas/ShivaVG/include)
341 include_directories(${PROJECT_BINARY_DIR}/simgear)
342 include_directories(${PROJECT_BINARY_DIR}/simgear/xml)
343
344 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS} 
345     ${Boost_INCLUDE_DIRS} 
346     ${ZLIB_INCLUDE_DIR} 
347     ${OPENAL_INCLUDE_DIR}
348     ${LibArchive_INCLUDE_DIRS}
349 )
350
351 add_definitions(-DHAVE_CONFIG_H)
352
353 # configure a header file to pass some of the CMake settings
354 # to the source code
355 configure_file (
356   "${PROJECT_SOURCE_DIR}/simgear/simgear_config_cmake.h.in"
357   "${PROJECT_BINARY_DIR}/simgear/simgear_config.h"
358   )
359
360 configure_file (
361     "${PROJECT_SOURCE_DIR}/simgear/xml/expat_config_cmake.in"
362     "${PROJECT_BINARY_DIR}/simgear/xml/expat_config.h"
363 )
364
365 if(ENABLE_TESTS)
366     # enable CTest / make test target
367     message(STATUS "Tests: ENABLED")
368
369     include (Dart)
370     enable_testing()
371
372     if(SIMGEAR_SHARED)
373         set( TEST_LIBS
374             SimGearCore)
375     else()
376         set( TEST_LIBS
377             SimGearCore
378             ${CMAKE_THREAD_LIBS_INIT}
379             ${ZLIB_LIBRARY}
380             ${WINSOCK_LIBRARY}
381             ${RT_LIBRARY})
382         if(APPLE)
383           find_library(COCOA_LIBRARY Cocoa)
384           list(APPEND TEST_LIBS ${COCOA_LIBRARY})
385         endif()
386     endif()
387
388     if(NOT SIMGEAR_HEADLESS)
389         set( TEST_LIBS
390             SimGearScene
391             ${TEST_LIBS}
392             ${OPENGL_LIBRARIES})
393     endif()
394 else()
395     message(STATUS "Tests: DISABLED")
396 endif(ENABLE_TESTS)
397
398 install (FILES ${PROJECT_BINARY_DIR}/simgear/simgear_config.h  DESTINATION include/simgear/)
399 add_subdirectory(simgear)
400
401 if (NOT EMBEDDED_SIMGEAR)
402 #-----------------------------------------------------------------------------
403 ### uninstall target
404 #-----------------------------------------------------------------------------
405 CONFIGURE_FILE(
406   "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
407   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
408   IMMEDIATE @ONLY)
409 ADD_CUSTOM_TARGET(uninstall
410   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
411   
412 endif()
413