]> git.mxchange.org Git - simgear.git/blob - CMakeLists.txt
Implement blinking hold-short line lights
[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 "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
159 if(HAVE_UNISTD_H)
160     set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
161     check_cxx_source_compiles(
162        "#include <unistd.h>
163         #if !defined(_POSIX_TIMERS) || (0 >= _POSIX_TIMERS)
164             #error clock_gettime is not supported
165         #endif
166
167         int main() { return 0; }
168         "
169         HAVE_CLOCK_GETTIME)
170 endif(HAVE_UNISTD_H)
171
172 set(RT_LIBRARY "")
173 if(HAVE_CLOCK_GETTIME)
174     check_library_exists(rt clock_gettime "" HAVE_RT)
175     if(HAVE_RT)
176         set(RT_LIBRARY rt)
177     endif(HAVE_RT)
178 endif(HAVE_CLOCK_GETTIME)
179
180 SET(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually 'd' on windows")
181 SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
182 SET(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
183 SET(CMAKE_MINSIZEREL_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
184
185 # isnan might not be real symbol, so can't check using function_exists
186 check_cxx_source_compiles(
187     "#include <cmath> 
188     void f() { isnan(0.0);} "
189     HAVE_ISNAN)
190
191 if(CMAKE_COMPILER_IS_GNUCXX)
192     set(WARNING_FLAGS -Wall)
193     
194     # certain GCC versions don't provide the atomic builds, and hence
195     # require is to provide them in SGAtomic.cxx
196     set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
197     check_cxx_source_compiles(
198        "int main() { unsigned mValue; return __sync_add_and_fetch(&mValue, 1); }"
199         GCC_ATOMIC_BUILTINS_FOUND)
200 endif(CMAKE_COMPILER_IS_GNUCXX)
201
202 if(WIN32)
203
204     if(MINGW)
205         add_definitions(-D_WIN32_WINNT=0x501)
206     endif()
207
208     if(MSVC)
209         # turn off various warnings
210         # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
211         #     SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
212         # endforeach(warning)
213         
214         set(MSVC_FLAGS "-DWIN32 -DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS /wd4996")
215     endif(MSVC)
216     
217     # assumed on Windows
218     set(HAVE_GETLOCALTIME 1)
219     
220     set( WINSOCK_LIBRARY "ws2_32.lib" )
221     set( RT_LIBRARY "winmm" )
222 endif(WIN32)    
223
224 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 
225    set (WARNING_FLAGS "-Wall -Wno-overloaded-virtual")
226 endif() 
227
228 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS}")
229 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} ${BOOST_CXX_FLAGS}")
230
231 include_directories(${PROJECT_SOURCE_DIR})
232 include_directories(${PROJECT_BINARY_DIR}/simgear)
233
234 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS} 
235     ${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR} 
236     ${ALUT_INCLUDE_DIR} ${OPENAL_INCLUDE_DIR} )
237
238
239 add_definitions(-DHAVE_CONFIG_H)
240
241 # configure a header file to pass some of the CMake settings
242 # to the source code
243 configure_file (
244   "${PROJECT_SOURCE_DIR}/simgear/simgear_config_cmake.h.in"
245   "${PROJECT_BINARY_DIR}/simgear/simgear_config.h"
246   )
247
248 if(ENABLE_TESTS)
249 # enable CTest / make test target
250
251 include (Dart)
252 enable_testing()
253 endif(ENABLE_TESTS)
254
255 install (FILES ${PROJECT_BINARY_DIR}/simgear/simgear_config.h  DESTINATION include/simgear/)
256 add_subdirectory(simgear)
257
258 #-----------------------------------------------------------------------------
259 ### uninstall target
260 #-----------------------------------------------------------------------------
261 CONFIGURE_FILE(
262   "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
263   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
264   IMMEDIATE @ONLY)
265 ADD_CUSTOM_TARGET(uninstall
266   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
267