1 cmake_minimum_required (VERSION 2.6.4)
2 include (CheckFunctionExists)
3 include (CheckIncludeFile)
4 include (CheckCXXSourceCompiles)
9 # read 'version' file into a variable (stripping any newlines or spaces)
10 file(READ version versionFile)
11 string(STRIP ${versionFile} SIMGEAR_VERSION)
13 # use simgear version also as the SO version (if building SOs)
14 SET(SIMGEAR_SOVERSION ${SIMGEAR_VERSION})
17 SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")
18 SET(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README")
19 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Simulation support libraries for FlightGear and related projects")
20 SET(CPACK_PACKAGE_VENDOR "The FlightGear project")
21 SET(CPACK_GENERATOR "TBZ2")
22 SET(CPACK_INSTALL_CMAKE_PROJECTS ${CMAKE_CURRENT_BINARY_DIR};SimGear;ALL;/)
25 # split version string into components, note CMAKE_MATCH_0 is the entire regexp match
26 string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" CPACK_PACKAGE_VERSION ${SIMGEAR_VERSION} )
27 set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
28 set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
29 set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
31 message(STATUS "version is ${CPACK_PACKAGE_VERSION_MAJOR} dot ${CPACK_PACKAGE_VERSION_MINOR} dot ${CPACK_PACKAGE_VERSION_PATCH}")
33 set(CPACK_SOURCE_GENERATOR TBZ2)
34 set(CPACK_SOURCE_PACKAGE_FILE_NAME "simgear-${SIMGEAR_VERSION}" CACHE INTERNAL "tarball basename")
35 set(CPACK_SOURCE_IGNORE_FILES
36 "^${PROJECT_SOURCE_DIR}/.git;\\\\.gitignore;Makefile.am;~$;${CPACK_SOURCE_IGNORE_FILES}")
38 message(STATUS "ignoring: ${CPACK_SOURCE_IGNORE_FILES}")
42 # We have some custom .cmake scripts not in the official distribution.
43 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
45 # Change the default build type to something fast
46 if(NOT CMAKE_BUILD_TYPE)
47 set(CMAKE_BUILD_TYPE Release CACHE STRING
48 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
50 endif(NOT CMAKE_BUILD_TYPE)
52 # Determine name of library installation directory, i.e. "lib" vs "lib64", which
53 # differs between all Debian-based vs all other Linux distros.
54 # See cmake bug #11964, http://cmake.org/gitweb?p=cmake.git;a=commit;h=126c993d
55 # GNUInstallDirs requires CMake >= 2.8.5, use own file for older cmake
56 if(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
57 include(GNUInstallDirs)
58 else(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
59 include(OldGNUInstallDirs)
60 endif(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
61 message(STATUS "Library installation directory: ${CMAKE_INSTALL_LIBDIR}")
63 option(SIMGEAR_SHARED "Set to ON to build SimGear as a shared library/framework" OFF)
64 option(SIMGEAR_HEADLESS "Set to ON to build SimGear without GUI/graphics support" OFF)
65 option(JPEG_FACTORY "Enable JPEG-factory support" OFF)
66 option(ENABLE_LIBSVN "Set to ON to build SimGear with libsvnclient support" ON)
67 option(ENABLE_RTI "Set to ON to build SimGear with RTI support" OFF)
68 option(ENABLE_TESTS "Set to OFF to disable building SimGear's test applications" ON)
71 GET_FILENAME_COMPONENT(PARENT_DIR ${PROJECT_SOURCE_DIR} PATH)
73 SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty.x64")
75 SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty")
77 if (EXISTS ${TEST_3RDPARTY_DIR})
78 set(MSVC_3RDPARTY_ROOT ${PARENT_DIR} CACHE PATH "Location where the third-party dependencies are extracted")
79 else (EXISTS ${TEST_3RDPARTY_DIR})
80 set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
81 endif (EXISTS ${TEST_3RDPARTY_DIR})
83 set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
86 if (MSVC AND MSVC_3RDPARTY_ROOT)
87 message(STATUS "3rdparty files located in ${MSVC_3RDPARTY_ROOT}")
88 set( OSG_MSVC "msvc" )
89 if (${MSVC_VERSION} EQUAL 1600)
90 set( OSG_MSVC ${OSG_MSVC}100 )
91 else (${MSVC_VERSION} EQUAL 1600)
92 set( OSG_MSVC ${OSG_MSVC}90 )
93 endif (${MSVC_VERSION} EQUAL 1600)
95 set( OSG_MSVC ${OSG_MSVC}-64 )
96 set( MSVC_3RDPARTY_DIR 3rdParty.x64 )
98 set( MSVC_3RDPARTY_DIR 3rdParty )
101 set (CMAKE_LIBRARY_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenScenegraph/lib )
102 set (CMAKE_INCLUDE_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenScenegraph/include)
103 set (BOOST_ROOT ${MSVC_3RDPARTY_ROOT}/boost_1_44_0)
104 message(STATUS "BOOST_ROOT is ${BOOST_ROOT}")
105 set (OPENAL_INCLUDE_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include)
106 set (ALUT_INCLUDE_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include)
107 set (OPENAL_LIBRARY_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib)
108 endif (MSVC AND MSVC_3RDPARTY_ROOT)
110 find_package(Boost REQUIRED)
111 set (BOOST_CXX_FLAGS "-DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_BIMAP_DISABLE_SERIALIZATION")
113 find_package(ZLIB REQUIRED)
114 find_package(Threads REQUIRED)
117 message(STATUS "headless mode")
118 set(NO_OPENSCENEGRAPH_INTERFACE 1)
120 find_package(OpenGL REQUIRED)
121 find_package(OpenAL REQUIRED)
122 find_package(ALUT REQUIRED)
123 find_package(OpenSceneGraph 3.0.0 REQUIRED osgText osgSim osgDB osgParticle osgUtil)
124 endif(SIMGEAR_HEADLESS)
127 message(STATUS "JPEG-factory enabled")
128 find_package(JPEG REQUIRED)
129 include_directories(${JPEG_INCLUDE_DIR})
133 find_package(SvnClient)
136 message(STATUS "libsvn found, enabling in SimGear")
137 set(HAVE_SVN_CLIENT_H 1)
138 set(HAVE_LIBSVN_CLIENT_1 1)
140 message(STATUS "Missing libsvn, unable to enable SVN in SimGear")
144 check_include_file(sys/time.h HAVE_SYS_TIME_H)
145 check_include_file(sys/timeb.h HAVE_SYS_TIMEB_H)
146 check_include_file(unistd.h HAVE_UNISTD_H)
147 check_include_file(windows.h HAVE_WINDOWS_H)
150 # See if we have any rti library variant installed
154 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
155 check_function_exists(ftime HAVE_FTIME)
156 check_function_exists(timegm HAVE_TIMEGM)
157 check_function_exists(rint HAVE_RINT)
158 check_function_exists(mkdtemp HAVE_MKDTEMP)
161 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
162 check_cxx_source_compiles(
164 #if !defined(_POSIX_TIMERS) || (0 >= _POSIX_TIMERS)
165 #error clock_gettime is not supported
168 int main() { return 0; }
174 if(HAVE_CLOCK_GETTIME)
175 check_library_exists(rt clock_gettime "" HAVE_RT)
179 endif(HAVE_CLOCK_GETTIME)
181 SET(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually 'd' on windows")
182 SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
183 SET(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
184 SET(CMAKE_MINSIZEREL_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
186 # isnan might not be real symbol, so can't check using function_exists
187 check_cxx_source_compiles(
189 void f() { isnan(0.0);} "
192 if(CMAKE_COMPILER_IS_GNUCXX)
193 set(WARNING_FLAGS -Wall)
195 # certain GCC versions don't provide the atomic builds, and hence
196 # require is to provide them in SGAtomic.cxx
197 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
198 check_cxx_source_compiles(
199 "int main() { unsigned mValue; return __sync_add_and_fetch(&mValue, 1); }"
200 GCC_ATOMIC_BUILTINS_FOUND)
201 endif(CMAKE_COMPILER_IS_GNUCXX)
206 # turn off various warnings
207 # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
208 # SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
209 # endforeach(warning)
211 set(MSVC_FLAGS "-DWIN32 -DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS /wd4996")
215 set(HAVE_GETLOCALTIME 1)
217 set( WINSOCK_LIBRARY "ws2_32.lib" )
218 set( RT_LIBRARY "winmm" )
221 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
222 set (WARNING_FLAGS "-Wall -Wno-overloaded-virtual")
225 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS}")
226 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} ${BOOST_CXX_FLAGS}")
228 include_directories(${PROJECT_SOURCE_DIR})
229 include_directories(${PROJECT_BINARY_DIR}/simgear)
231 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS}
232 ${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR}
233 ${ALUT_INCLUDE_DIR} ${OPENAL_INCLUDE_DIR} )
236 add_definitions(-DHAVE_CONFIG_H)
238 # configure a header file to pass some of the CMake settings
241 "${PROJECT_SOURCE_DIR}/simgear/simgear_config_cmake.h.in"
242 "${PROJECT_BINARY_DIR}/simgear/simgear_config.h"
246 # enable CTest / make test target
252 install (FILES ${PROJECT_BINARY_DIR}/simgear/simgear_config.h DESTINATION include/simgear/)
253 add_subdirectory(simgear)
255 #-----------------------------------------------------------------------------
257 #-----------------------------------------------------------------------------
259 "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
260 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
262 ADD_CUSTOM_TARGET(uninstall
263 "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")