| 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 |
#packaging |
| 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;/) |
| 23 |
|
| 24 |
|
| 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}) |
| 30 |
|
| 31 |
message(STATUS "version is ${CPACK_PACKAGE_VERSION_MAJOR} dot ${CPACK_PACKAGE_VERSION_MINOR} dot ${CPACK_PACKAGE_VERSION_PATCH}") |
| 32 |
|
| 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}") |
| 37 |
|
| 38 |
message(STATUS "ignoring: ${CPACK_SOURCE_IGNORE_FILES}") |
| 39 |
|
| 40 |
include (CPack) |
| 41 |
|
| 42 |
# We have some custom .cmake scripts not in the official distribution. |
| 43 |
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}") |
| 44 |
|
| 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." |
| 49 |
FORCE) |
| 50 |
endif(NOT CMAKE_BUILD_TYPE) |
| 51 |
|
| 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}") |
| 62 |
|
| 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) |
| 69 |
|
| 70 |
if (MSVC) |
| 71 |
GET_FILENAME_COMPONENT(PARENT_DIR ${PROJECT_SOURCE_DIR} PATH) |
| 72 |
if (CMAKE_CL_64) |
| 73 |
SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty.x64") |
| 74 |
else (CMAKE_CL_64) |
| 75 |
SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty") |
| 76 |
endif (CMAKE_CL_64) |
| 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}) |
| 82 |
else (MSVC) |
| 83 |
set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted") |
| 84 |
endif (MSVC) |
| 85 |
|
| 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) |
| 94 |
if (CMAKE_CL_64) |
| 95 |
set( OSG_MSVC ${OSG_MSVC}-64 ) |
| 96 |
set( MSVC_3RDPARTY_DIR 3rdParty.x64 ) |
| 97 |
else (CMAKE_CL_64) |
| 98 |
set( MSVC_3RDPARTY_DIR 3rdParty ) |
| 99 |
endif (CMAKE_CL_64) |
| 100 |
|
| 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) |
| 109 |
|
| 110 |
find_package(Boost REQUIRED) |
| 111 |
set (BOOST_CXX_FLAGS "-DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_BIMAP_DISABLE_SERIALIZATION") |
| 112 |
|
| 113 |
find_package(ZLIB REQUIRED) |
| 114 |
find_package(Threads REQUIRED) |
| 115 |
|
| 116 |
if(SIMGEAR_HEADLESS) |
| 117 |
message(STATUS "headless mode") |
| 118 |
else() |
| 119 |
find_package(OpenGL REQUIRED) |
| 120 |
find_package(OpenAL REQUIRED) |
| 121 |
find_package(ALUT REQUIRED) |
| 122 |
find_package(OpenSceneGraph 3.0.0 REQUIRED osgText osgSim osgDB osgParticle osgUtil) |
| 123 |
endif(SIMGEAR_HEADLESS) |
| 124 |
|
| 125 |
if(JPEG_FACTORY) |
| 126 |
message(STATUS "JPEG-factory enabled") |
| 127 |
find_package(JPEG REQUIRED) |
| 128 |
include_directories(${JPEG_INCLUDE_DIR}) |
| 129 |
endif(JPEG_FACTORY) |
| 130 |
|
| 131 |
if(ENABLE_LIBSVN) |
| 132 |
find_package(SvnClient) |
| 133 |
|
| 134 |
if(LIBSVN_FOUND) |
| 135 |
message(STATUS "libsvn found, enabling in SimGear") |
| 136 |
set(HAVE_SVN_CLIENT_H 1) |
| 137 |
set(HAVE_LIBSVN_CLIENT_1 1) |
| 138 |
else() |
| 139 |
message(STATUS "Missing libsvn, unable to enable SVN in SimGear") |
| 140 |
endif(LIBSVN_FOUND) |
| 141 |
endif(ENABLE_LIBSVN) |
| 142 |
|
| 143 |
check_include_file(sys/time.h HAVE_SYS_TIME_H) |
| 144 |
check_include_file(sys/timeb.h HAVE_SYS_TIMEB_H) |
| 145 |
check_include_file(unistd.h HAVE_UNISTD_H) |
| 146 |
check_include_file(windows.h HAVE_WINDOWS_H) |
| 147 |
|
| 148 |
if(ENABLE_RTI) |
| 149 |
# See if we have any rti library variant installed |
| 150 |
find_package(RTI) |
| 151 |
endif(ENABLE_RTI) |
| 152 |
|
| 153 |
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) |
| 154 |
check_function_exists(ftime HAVE_FTIME) |
| 155 |
check_function_exists(timegm HAVE_TIMEGM) |
| 156 |
check_function_exists(rint HAVE_RINT) |
| 157 |
check_function_exists(mkdtemp HAVE_MKDTEMP) |
| 158 |
check_function_exists(bcopy HAVE_BCOPY) |
| 159 |
check_function_exists(mmap HAVE_MMAP) |
| 160 |
|
| 161 |
if(HAVE_UNISTD_H) |
| 162 |
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH}) |
| 163 |
check_cxx_source_compiles( |
| 164 |
"#include <unistd.h> |
| 165 |
#if !defined(_POSIX_TIMERS) || (0 >= _POSIX_TIMERS) |
| 166 |
#error clock_gettime is not supported |
| 167 |
#endif |
| 168 |
|
| 169 |
int main() { return 0; } |
| 170 |
" |
| 171 |
HAVE_CLOCK_GETTIME) |
| 172 |
endif(HAVE_UNISTD_H) |
| 173 |
|
| 174 |
set(RT_LIBRARY "") |
| 175 |
if(HAVE_CLOCK_GETTIME) |
| 176 |
check_library_exists(rt clock_gettime "" HAVE_RT) |
| 177 |
if(HAVE_RT) |
| 178 |
set(RT_LIBRARY rt) |
| 179 |
endif(HAVE_RT) |
| 180 |
endif(HAVE_CLOCK_GETTIME) |
| 181 |
|
| 182 |
SET(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually 'd' on windows") |
| 183 |
SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows") |
| 184 |
SET(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows") |
| 185 |
SET(CMAKE_MINSIZEREL_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows") |
| 186 |
|
| 187 |
# isnan might not be real symbol, so can't check using function_exists |
| 188 |
check_cxx_source_compiles( |
| 189 |
"#include <cmath> |
| 190 |
void f() { isnan(0.0);} " |
| 191 |
HAVE_ISNAN) |
| 192 |
|
| 193 |
if(CMAKE_COMPILER_IS_GNUCXX) |
| 194 |
set(WARNING_FLAGS_CXX "-Wall") |
| 195 |
set(WARNING_FLAGS_C "-Wall") |
| 196 |
|
| 197 |
# certain GCC versions don't provide the atomic builds, and hence |
| 198 |
# require is to provide them in SGAtomic.cxx |
| 199 |
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH}) |
| 200 |
check_cxx_source_compiles( |
| 201 |
"int main() { unsigned mValue; return __sync_add_and_fetch(&mValue, 1); }" |
| 202 |
GCC_ATOMIC_BUILTINS_FOUND) |
| 203 |
endif(CMAKE_COMPILER_IS_GNUCXX) |
| 204 |
|
| 205 |
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 206 |
set(WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual") |
| 207 |
set(WARNING_FLAGS_C "-Wall") |
| 208 |
endif() |
| 209 |
|
| 210 |
if(WIN32) |
| 211 |
|
| 212 |
if(MINGW) |
| 213 |
add_definitions(-D_WIN32_WINNT=0x501) |
| 214 |
endif() |
| 215 |
|
| 216 |
if(MSVC) |
| 217 |
# turn off various warnings |
| 218 |
# foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996) |
| 219 |
# SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}") |
| 220 |
# endforeach(warning) |
| 221 |
|
| 222 |
set(MSVC_FLAGS "-DWIN32 -DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS /wd4996") |
| 223 |
endif(MSVC) |
| 224 |
|
| 225 |
# assumed on Windows |
| 226 |
set(HAVE_GETLOCALTIME 1) |
| 227 |
|
| 228 |
set( WINSOCK_LIBRARY "ws2_32.lib" ) |
| 229 |
set( RT_LIBRARY "winmm" ) |
| 230 |
endif(WIN32) |
| 231 |
|
| 232 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS_C} ${MSVC_FLAGS}") |
| 233 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_CXX} ${MSVC_FLAGS} ${BOOST_CXX_FLAGS}") |
| 234 |
|
| 235 |
include_directories(${PROJECT_SOURCE_DIR}) |
| 236 |
include_directories(${PROJECT_BINARY_DIR}/simgear) |
| 237 |
include_directories(${PROJECT_BINARY_DIR}/simgear/xml) |
| 238 |
|
| 239 |
include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS} |
| 240 |
${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR} |
| 241 |
${ALUT_INCLUDE_DIR} ${OPENAL_INCLUDE_DIR} ) |
| 242 |
|
| 243 |
add_definitions(-DHAVE_CONFIG_H) |
| 244 |
add_definitions(-DHAVE_EXPAT_CONFIG_H) |
| 245 |
|
| 246 |
# configure a header file to pass some of the CMake settings |
| 247 |
# to the source code |
| 248 |
configure_file ( |
| 249 |
"${PROJECT_SOURCE_DIR}/simgear/simgear_config_cmake.h.in" |
| 250 |
"${PROJECT_BINARY_DIR}/simgear/simgear_config.h" |
| 251 |
) |
| 252 |
|
| 253 |
configure_file ( |
| 254 |
"${PROJECT_SOURCE_DIR}/simgear/xml/expat_config_cmake.in" |
| 255 |
"${PROJECT_BINARY_DIR}/simgear/xml/expat_config.h" |
| 256 |
) |
| 257 |
|
| 258 |
if(ENABLE_TESTS) |
| 259 |
# enable CTest / make test target |
| 260 |
|
| 261 |
include (Dart) |
| 262 |
enable_testing() |
| 263 |
endif(ENABLE_TESTS) |
| 264 |
|
| 265 |
install (FILES ${PROJECT_BINARY_DIR}/simgear/simgear_config.h DESTINATION include/simgear/) |
| 266 |
add_subdirectory(simgear) |
| 267 |
|
| 268 |
#----------------------------------------------------------------------------- |
| 269 |
### uninstall target |
| 270 |
#----------------------------------------------------------------------------- |
| 271 |
CONFIGURE_FILE( |
| 272 |
"${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in" |
| 273 |
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" |
| 274 |
IMMEDIATE @ONLY) |
| 275 |
ADD_CUSTOM_TARGET(uninstall |
| 276 |
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") |