1 cmake_minimum_required (VERSION 2.6.4)
3 if(COMMAND cmake_policy)
5 cmake_policy(SET CMP0054 NEW)
8 cmake_policy(SET CMP0042 NEW)
12 include (CheckFunctionExists)
13 include (CheckIncludeFile)
14 include (CheckCXXSourceCompiles)
15 include (CheckCXXCompilerFlag)
19 # using 10.7 because boost requires libc++ and 10.6 doesn't include it
20 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.7")
22 # read 'version' file into a variable (stripping any newlines or spaces)
23 file(READ version versionFile)
24 string(STRIP ${versionFile} SIMGEAR_VERSION)
26 set(FIND_LIBRARY_USE_LIB64_PATHS ON)
28 # use simgear version also as the SO version (if building SOs)
29 SET(SIMGEAR_SOVERSION ${SIMGEAR_VERSION})
31 # Warning when build is not an out-of-source build.
32 string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" InSourceBuild)
34 message(WARNING "Avoid building inside the source tree!")
35 message(WARNING "Create a separate build directory instead (i.e. 'sgbuild') and call CMake from there: ")
36 message(WARNING " mkdir ../sgbuild && cd ../sgbuild && cmake ${CMAKE_SOURCE_DIR}")
40 SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")
41 SET(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README")
42 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Simulation support libraries for FlightGear and related projects")
43 SET(CPACK_PACKAGE_VENDOR "The FlightGear project")
44 SET(CPACK_GENERATOR "TBZ2")
45 SET(CPACK_INSTALL_CMAKE_PROJECTS ${CMAKE_CURRENT_BINARY_DIR};SimGear;ALL;/)
48 # split version string into components, note CMAKE_MATCH_0 is the entire regexp match
49 string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" CPACK_PACKAGE_VERSION ${SIMGEAR_VERSION} )
50 set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
51 set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
52 set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
54 message(STATUS "version is ${CPACK_PACKAGE_VERSION_MAJOR} dot ${CPACK_PACKAGE_VERSION_MINOR} dot ${CPACK_PACKAGE_VERSION_PATCH}")
56 set(CPACK_SOURCE_GENERATOR TBZ2)
57 set(CPACK_SOURCE_PACKAGE_FILE_NAME "simgear-${SIMGEAR_VERSION}" CACHE INTERNAL "tarball basename")
58 set(CPACK_SOURCE_IGNORE_FILES
59 "^${PROJECT_SOURCE_DIR}/.git;\\\\.gitignore;Makefile.am;~$;${CPACK_SOURCE_IGNORE_FILES}")
61 message(STATUS "ignoring: ${CPACK_SOURCE_IGNORE_FILES}")
65 # We have some custom .cmake scripts not in the official distribution.
66 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
68 # Change the default build type to something fast
69 if(NOT CMAKE_BUILD_TYPE)
70 set(CMAKE_BUILD_TYPE Release CACHE STRING
71 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
73 endif(NOT CMAKE_BUILD_TYPE)
75 # Determine name of library installation directory, i.e. "lib" vs "lib64", which
76 # differs between all Debian-based vs all other Linux distros.
77 # See cmake bug #11964, http://cmake.org/gitweb?p=cmake.git;a=commit;h=126c993d
78 # GNUInstallDirs requires CMake >= 2.8.5, use own file for older cmake
79 if(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
80 include(GNUInstallDirs)
81 else(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
82 include(OldGNUInstallDirs)
83 endif(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
84 message(STATUS "Library installation directory: ${CMAKE_INSTALL_LIBDIR}")
86 #####################################################################################
87 # Configure library search paths
88 #####################################################################################
90 if(NOT "${CMAKE_LIBRARY_ARCHITECTURE}" STREQUAL "")
91 # Workaround for Ubuntu/Debian which introduced the "multiarch" library
92 # directory structure, which is unsupported by CMake < 2.8.10, so we need to
94 # see http://www.cmake.org/Bug/view.php?id=12049 and
95 # http://www.cmake.org/Bug/view.php?id=12037
96 list(APPEND ADDITIONAL_LIBRARY_PATHS
97 /usr/local/lib/${CMAKE_LIBRARY_ARCHITECTURE}
98 /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}
99 /lib/${CMAKE_LIBRARY_ARCHITECTURE})
100 message(STATUS "additional library directories: ${ADDITIONAL_LIBRARY_PATHS}")
103 #####################################################################################
106 option(SIMGEAR_SHARED "Set to ON to build SimGear as a shared library/framework" OFF)
107 option(SYSTEM_EXPAT "Set to ON to build SimGear using the system libExpat" OFF)
109 # Building SimGear DLLs is currently not supported for MSVC.
110 set(SIMGEAR_SHARED OFF)
111 # Using a system expat is currently not supported for MSVC - it would require shared simgear (DLL).
112 set(SYSTEM_EXPAT OFF)
115 option(SIMGEAR_HEADLESS "Set to ON to build SimGear without GUI/graphics support" OFF)
116 option(ENABLE_RTI "Set to ON to build SimGear with RTI support" OFF)
117 option(ENABLE_TESTS "Set to OFF to disable building SimGear's test applications" ON)
118 option(ENABLE_SOUND "Set to OFF to disable building SimGear's sound support" ON)
119 option(ENABLE_PKGUTIL "Set to ON to build the sg_pkgutil application (default)" ON)
122 GET_FILENAME_COMPONENT(PARENT_DIR ${PROJECT_BINARY_DIR} PATH)
124 SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty.x64")
126 SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty")
128 if (EXISTS ${TEST_3RDPARTY_DIR})
129 set(MSVC_3RDPARTY_ROOT ${PARENT_DIR} CACHE PATH "Location where the third-party dependencies are extracted")
130 else (EXISTS ${TEST_3RDPARTY_DIR})
131 set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
132 endif (EXISTS ${TEST_3RDPARTY_DIR})
134 set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
137 if (MSVC AND MSVC_3RDPARTY_ROOT)
138 message(STATUS "3rdparty files located in ${MSVC_3RDPARTY_ROOT}")
139 set( OSG_MSVC "msvc" )
140 if (${MSVC_VERSION} EQUAL 1700)
141 set( OSG_MSVC ${OSG_MSVC}110 )
142 elseif (${MSVC_VERSION} EQUAL 1600)
143 set( OSG_MSVC ${OSG_MSVC}100 )
144 else (${MSVC_VERSION} EQUAL 1700)
145 set( OSG_MSVC ${OSG_MSVC}90 )
146 endif (${MSVC_VERSION} EQUAL 1700)
148 set( OSG_MSVC ${OSG_MSVC}-64 )
149 set( MSVC_3RDPARTY_DIR 3rdParty.x64 )
151 set( MSVC_3RDPARTY_DIR 3rdParty )
154 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 )
155 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)
156 find_path(BOOST_ROOT boost/version.hpp
157 ${MSVC_3RDPARTY_ROOT}/boost
158 ${MSVC_3RDPARTY_ROOT}/boost_1_52_0
159 ${MSVC_3RDPARTY_ROOT}/boost_1_51_0
160 ${MSVC_3RDPARTY_ROOT}/boost_1_50_0
161 ${MSVC_3RDPARTY_ROOT}/boost_1_49_0
162 ${MSVC_3RDPARTY_ROOT}/boost_1_48_0
163 ${MSVC_3RDPARTY_ROOT}/boost_1_47_0
164 ${MSVC_3RDPARTY_ROOT}/boost_1_46_1
165 ${MSVC_3RDPARTY_ROOT}/boost_1_46_0
166 ${MSVC_3RDPARTY_ROOT}/boost_1_45_0
167 ${MSVC_3RDPARTY_ROOT}/boost_1_44_0
169 # set (BOOST_ROOT ${MSVC_3RDPARTY_ROOT}/boost_1_44_0)
170 message(STATUS "BOOST_ROOT is ${BOOST_ROOT}")
171 set (OPENAL_INCLUDE_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include)
172 set (OPENAL_LIBRARY_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib)
173 endif (MSVC AND MSVC_3RDPARTY_ROOT)
176 find_library(COCOA_LIBRARY Cocoa)
179 # Somehow this only works if included before searching for Boost...
180 include(BoostTestTargets)
182 find_package(Boost REQUIRED)
183 set (BOOST_CXX_FLAGS "-DBOOST_BIMAP_DISABLE_SERIALIZATION")
186 message(STATUS "SimGear mode: HEADLESS")
189 message(STATUS "SimGear mode: NORMAL")
190 find_package(OpenGL REQUIRED)
193 find_package(OpenAL REQUIRED)
194 message(STATUS "Sound support: ENABLED")
197 find_package(OpenSceneGraph 3.2.0 REQUIRED osgText osgSim osgDB osgParticle osgGA osgViewer osgUtil)
198 endif(SIMGEAR_HEADLESS)
200 find_package(ZLIB REQUIRED)
201 find_package(Threads REQUIRED)
204 message(STATUS "Requested to use system Expat library, forcing SIMGEAR_SHARED to true")
205 set(SIMGEAR_SHARED ON)
206 find_package(EXPAT REQUIRED)
209 message(STATUS "Using built-in expat code")
210 # XML_STATIC is important to avoid sg_expat_external.h
211 # declaring symbols as declspec(import)
212 add_definitions(-DHAVE_EXPAT_CONFIG_H -DXML_STATIC)
213 set(EXPAT_INCLUDE_DIRS
214 ${PROJECT_SOURCE_DIR}/3rdparty/expat
215 ${PROJECT_BINARY_DIR}/3rdparty/expat)
218 include_directories(${EXPAT_INCLUDE_DIRS})
220 check_include_file(inttypes.h HAVE_INTTYPES_H)
221 check_include_file(sys/time.h HAVE_SYS_TIME_H)
222 check_include_file(sys/timeb.h HAVE_SYS_TIMEB_H)
223 check_include_file(unistd.h HAVE_UNISTD_H)
224 check_include_file(windows.h HAVE_WINDOWS_H)
227 # ShivaVG needs inttypes.h
228 add_definitions(-DHAVE_INTTYPES_H)
232 # See if we have any rti library variant installed
233 message(STATUS "RTI: ENABLED")
236 message(STATUS "RTI: DISABLED")
239 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
240 check_function_exists(ftime HAVE_FTIME)
241 check_function_exists(timegm HAVE_TIMEGM)
242 check_function_exists(rint HAVE_RINT)
243 check_function_exists(mkdtemp HAVE_MKDTEMP)
244 check_function_exists(bcopy HAVE_BCOPY)
245 check_function_exists(mmap HAVE_MMAP)
248 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
249 check_cxx_source_compiles(
251 #if !defined(_POSIX_TIMERS) || (0 >= _POSIX_TIMERS)
252 #error clock_gettime is not supported
255 int main() { return 0; }
261 if(HAVE_CLOCK_GETTIME)
262 check_library_exists(rt clock_gettime "" HAVE_RT)
266 endif(HAVE_CLOCK_GETTIME)
269 check_cxx_source_compiles(
278 check_library_exists(dl dlerror "" HAVE_DL)
284 SET(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually 'd' on windows")
285 SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
286 SET(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
287 SET(CMAKE_MINSIZEREL_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
289 # isnan might not be real symbol, so can't check using function_exists
290 check_cxx_source_compiles(
292 int main() { return isnan(0.0);} "
295 check_cxx_source_compiles(
297 int main() { return std::isnan(0.0);} "
300 if(CMAKE_COMPILER_IS_GNUCXX)
301 set(WARNING_FLAGS_CXX "-Wall")
302 set(WARNING_FLAGS_C "-Wall")
304 # certain GCC versions don't provide the atomic builds, and hence
305 # require is to provide them in SGAtomic.cxx
306 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
307 check_cxx_source_compiles(
308 "int main() { unsigned mValue; return __sync_add_and_fetch(&mValue, 1); }"
309 GCC_ATOMIC_BUILTINS_FOUND)
310 endif(CMAKE_COMPILER_IS_GNUCXX)
312 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
313 # Boost redeclares class members
314 set(WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual -Wno-redeclared-class-member")
315 set(WARNING_FLAGS_C "-Wall")
316 set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
317 set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
318 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
321 if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
322 # boost goes haywire wrt static asserts
323 check_cxx_compiler_flag(-Wno-unused-local-typedefs HAS_NOWARN_UNUSED_TYPEDEFS)
324 if(HAS_NOWARN_UNUSED_TYPEDEFS)
325 set(WARNING_FLAGS_CXX " ${WARNING_FLAGS_CXX} -Wno-unused-local-typedefs")
332 add_definitions(-D_WIN32_WINNT=0x501)
336 # turn off various warnings
337 # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
338 # SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
339 # endforeach(warning)
341 set(MSVC_FLAGS "-DWIN32 -DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS /wd4996 /wd4250 -Dstrdup=_strdup")
342 if (${MSVC_VERSION} GREATER 1599)
343 set( MSVC_LD_FLAGS "/FORCE:MULTIPLE" )
344 endif (${MSVC_VERSION} GREATER 1599)
348 set(HAVE_GETLOCALTIME 1)
350 set( WINSOCK_LIBRARY "ws2_32.lib" )
351 set( RT_LIBRARY "winmm" )
354 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS_C} ${MSVC_FLAGS}")
355 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_CXX} ${MSVC_FLAGS} ${BOOST_CXX_FLAGS}")
356 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}")
358 # use BEFORE to ensure local directories are used first,
359 # ahead of system-installed libs
360 include_directories(BEFORE ${PROJECT_SOURCE_DIR})
361 include_directories(BEFORE ${PROJECT_SOURCE_DIR}/simgear/canvas/ShivaVG/include)
362 include_directories(BEFORE ${PROJECT_BINARY_DIR}/simgear)
364 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS}
365 ${Boost_INCLUDE_DIRS}
367 ${OPENAL_INCLUDE_DIR}
370 add_definitions(-DHAVE_CONFIG_H)
372 # configure a header file to pass some of the CMake settings
375 "${PROJECT_SOURCE_DIR}/simgear/simgear_config_cmake.h.in"
376 "${PROJECT_BINARY_DIR}/simgear/simgear_config.h"
380 # enable CTest / make test target
381 message(STATUS "Tests: ENABLED")
386 message(STATUS "Tests: DISABLED")
389 # always set TEST_LIBS as it is also used by other tools/applications
390 set(TEST_LIBS_INTERNAL_CORE
391 ${CMAKE_THREAD_LIBS_INIT}
397 set(TEST_LIBS SimGearCore ${TEST_LIBS_INTERNAL_CORE})
399 if(NOT SIMGEAR_HEADLESS)
400 set(TEST_LIBS SimGearScene ${OPENGL_LIBRARIES} ${TEST_LIBS})
403 install (FILES ${PROJECT_BINARY_DIR}/simgear/simgear_config.h DESTINATION include/simgear/)
405 include_directories(3rdparty/utf8/source)
407 add_subdirectory(3rdparty)
408 add_subdirectory(simgear)
410 #-----------------------------------------------------------------------------
412 #-----------------------------------------------------------------------------
414 "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
415 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
417 ADD_CUSTOM_TARGET(uninstall
418 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")