]> git.mxchange.org Git - simgear.git/blob - CMakeLists.txt
f34d882881bd38699c0e61decc99741696374f23
[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 #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 "SimGear mode: HEADLESS")
118 else()
119     message(STATUS "SimGear mode: NORMAL")
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 osgGA osgUtil)
124 endif(SIMGEAR_HEADLESS)
125
126 if(JPEG_FACTORY)
127     message(STATUS "JPEG-factory: ENABLED")
128     find_package(JPEG REQUIRED)
129     include_directories(${JPEG_INCLUDE_DIR})
130 else()
131     message(STATUS "JPEG-factory: DISABLED")
132 endif(JPEG_FACTORY)
133
134 if(ENABLE_LIBSVN)
135     find_package(SvnClient)
136
137     if(LIBSVN_FOUND)
138         message(STATUS "Subversion client support: ENABLED")
139         set(HAVE_SVN_CLIENT_H 1)
140         set(HAVE_LIBSVN_CLIENT_1 1)
141     else()
142         # Oops. ENABLE_LIBSVN is ON, but svn is still missing.
143         # Provide clearly visible warning/hint, so builders know what else they should install (or disable).
144         message(WARNING "Failed to enable subversion client support. Unable to find required subversion client library. Some features may not be available (scenery download).")
145         message(WARNING "Install 'libsvn' library/DLL (libsvn-devel/libsvnclient/...). Otherwise disable subversion support (set 'ENABLE_LIBSVN' to 'OFF').")
146     endif(LIBSVN_FOUND)
147 else()
148     message(STATUS "Subversion client support: DISABLED")
149 endif(ENABLE_LIBSVN)
150
151 check_include_file(sys/time.h HAVE_SYS_TIME_H)
152 check_include_file(sys/timeb.h HAVE_SYS_TIMEB_H)
153 check_include_file(unistd.h HAVE_UNISTD_H)
154 check_include_file(windows.h HAVE_WINDOWS_H)
155
156 if(ENABLE_RTI)
157     # See if we have any rti library variant installed
158     message(STATUS "RTI: ENABLED")
159     find_package(RTI)
160 else()
161     message(STATUS "RTI: DISABLED")
162 endif(ENABLE_RTI)
163
164 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
165 check_function_exists(ftime HAVE_FTIME)
166 check_function_exists(timegm HAVE_TIMEGM)
167 check_function_exists(rint HAVE_RINT)
168 check_function_exists(mkdtemp HAVE_MKDTEMP)
169 check_function_exists(bcopy HAVE_BCOPY)
170 check_function_exists(mmap HAVE_MMAP)
171
172 if(HAVE_UNISTD_H)
173     set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
174     check_cxx_source_compiles(
175        "#include <unistd.h>
176         #if !defined(_POSIX_TIMERS) || (0 >= _POSIX_TIMERS)
177             #error clock_gettime is not supported
178         #endif
179
180         int main() { return 0; }
181         "
182         HAVE_CLOCK_GETTIME)
183 endif(HAVE_UNISTD_H)
184
185 set(RT_LIBRARY "")
186 if(HAVE_CLOCK_GETTIME)
187     check_library_exists(rt clock_gettime "" HAVE_RT)
188     if(HAVE_RT)
189         set(RT_LIBRARY rt)
190     endif(HAVE_RT)
191 endif(HAVE_CLOCK_GETTIME)
192
193 SET(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually 'd' on windows")
194 SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
195 SET(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
196 SET(CMAKE_MINSIZEREL_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
197
198 # isnan might not be real symbol, so can't check using function_exists
199 check_cxx_source_compiles(
200     "#include <cmath> 
201     void f() { isnan(0.0);} "
202     HAVE_ISNAN)
203
204 if(CMAKE_COMPILER_IS_GNUCXX)
205     set(WARNING_FLAGS_CXX "-Wall")
206     set(WARNING_FLAGS_C   "-Wall")
207
208     # certain GCC versions don't provide the atomic builds, and hence
209     # require is to provide them in SGAtomic.cxx
210     set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
211     check_cxx_source_compiles(
212        "int main() { unsigned mValue; return __sync_add_and_fetch(&mValue, 1); }"
213         GCC_ATOMIC_BUILTINS_FOUND)
214 endif(CMAKE_COMPILER_IS_GNUCXX)
215
216 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
217    set(WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual")
218    set(WARNING_FLAGS_C   "-Wall")
219 endif()
220
221 if(WIN32)
222
223     if(MINGW)
224         add_definitions(-D_WIN32_WINNT=0x501)
225     endif()
226
227     if(MSVC)
228         # turn off various warnings
229         # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
230         #     SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
231         # endforeach(warning)
232         
233         set(MSVC_FLAGS "-DWIN32 -DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS /wd4996")
234     endif(MSVC)
235     
236     # assumed on Windows
237     set(HAVE_GETLOCALTIME 1)
238     
239     set( WINSOCK_LIBRARY "ws2_32.lib" )
240     set( RT_LIBRARY "winmm" )
241 endif(WIN32)
242
243 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS_C} ${MSVC_FLAGS}")
244 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_CXX} ${MSVC_FLAGS} ${BOOST_CXX_FLAGS}")
245
246 include_directories(${PROJECT_SOURCE_DIR})
247 include_directories(${PROJECT_BINARY_DIR}/simgear)
248 include_directories(${PROJECT_BINARY_DIR}/simgear/xml)
249
250 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS} 
251     ${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR} 
252     ${ALUT_INCLUDE_DIR} ${OPENAL_INCLUDE_DIR} )
253
254 add_definitions(-DHAVE_CONFIG_H)
255 add_definitions(-DHAVE_EXPAT_CONFIG_H)
256
257 # configure a header file to pass some of the CMake settings
258 # to the source code
259 configure_file (
260   "${PROJECT_SOURCE_DIR}/simgear/simgear_config_cmake.h.in"
261   "${PROJECT_BINARY_DIR}/simgear/simgear_config.h"
262   )
263
264 configure_file (
265     "${PROJECT_SOURCE_DIR}/simgear/xml/expat_config_cmake.in"
266     "${PROJECT_BINARY_DIR}/simgear/xml/expat_config.h"
267 )
268
269 if(ENABLE_TESTS)
270     # enable CTest / make test target
271     message(STATUS "Tests: ENABLED")
272
273     include (Dart)
274         enable_testing()
275 else()
276     message(STATUS "Tests: DISABLED")
277 endif(ENABLE_TESTS)
278
279 install (FILES ${PROJECT_BINARY_DIR}/simgear/simgear_config.h  DESTINATION include/simgear/)
280 add_subdirectory(simgear)
281
282 #-----------------------------------------------------------------------------
283 ### uninstall target
284 #-----------------------------------------------------------------------------
285 CONFIGURE_FILE(
286   "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
287   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
288   IMMEDIATE @ONLY)
289 ADD_CUSTOM_TARGET(uninstall
290   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")