]> git.mxchange.org Git - simgear.git/blob - CMakeLists.txt
Add alpha-to-coverage GL parameter to effects code.
[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 # Warning when build is not an out-of-source build.
17 string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" InSourceBuild)
18 if(InSourceBuild)
19     message(WARNING  "Avoid building inside the source tree!")
20     message(WARNING  "Create a separate build directory instead (i.e. 'sgbuild') and call CMake from there: ")
21     message(WARNING  "  mkdir ../sgbuild && cd ../sgbuild && cmake ${CMAKE_SOURCE_DIR}")
22 endif(InSourceBuild)
23
24 #packaging
25 SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")
26 SET(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README")
27 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Simulation support libraries for FlightGear and related projects")
28 SET(CPACK_PACKAGE_VENDOR "The FlightGear project")
29 SET(CPACK_GENERATOR "TBZ2")
30 SET(CPACK_INSTALL_CMAKE_PROJECTS  ${CMAKE_CURRENT_BINARY_DIR};SimGear;ALL;/)
31
32
33 # split version string into components, note CMAKE_MATCH_0 is the entire regexp match
34 string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" CPACK_PACKAGE_VERSION ${SIMGEAR_VERSION} )
35 set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1}) 
36 set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
37 set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
38
39 message(STATUS "version is ${CPACK_PACKAGE_VERSION_MAJOR} dot ${CPACK_PACKAGE_VERSION_MINOR} dot ${CPACK_PACKAGE_VERSION_PATCH}")
40
41 set(CPACK_SOURCE_GENERATOR TBZ2)
42 set(CPACK_SOURCE_PACKAGE_FILE_NAME "simgear-${SIMGEAR_VERSION}" CACHE INTERNAL "tarball basename")
43 set(CPACK_SOURCE_IGNORE_FILES
44   "^${PROJECT_SOURCE_DIR}/.git;\\\\.gitignore;Makefile.am;~$;${CPACK_SOURCE_IGNORE_FILES}")
45
46 message(STATUS "ignoring: ${CPACK_SOURCE_IGNORE_FILES}")
47
48 include (CPack)
49
50 # We have some custom .cmake scripts not in the official distribution.
51 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
52
53 # Change the default build type to something fast
54 if(NOT CMAKE_BUILD_TYPE)
55   set(CMAKE_BUILD_TYPE Release CACHE STRING
56       "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
57       FORCE)
58 endif(NOT CMAKE_BUILD_TYPE)
59
60 # Determine name of library installation directory, i.e. "lib" vs "lib64", which
61 # differs between all Debian-based vs all other Linux distros.
62 # See cmake bug #11964, http://cmake.org/gitweb?p=cmake.git;a=commit;h=126c993d
63 # GNUInstallDirs requires CMake >= 2.8.5, use own file for older cmake
64 if(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
65   include(GNUInstallDirs)
66 else(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
67   include(OldGNUInstallDirs)
68 endif(${CMAKE_VERSION} VERSION_GREATER 2.8.4)
69 message(STATUS "Library installation directory: ${CMAKE_INSTALL_LIBDIR}")
70
71 option(SIMGEAR_SHARED   "Set to ON to build SimGear as a shared library/framework" OFF)
72 option(SIMGEAR_HEADLESS "Set to ON to build SimGear without GUI/graphics support" OFF)
73 option(JPEG_FACTORY     "Enable JPEG-factory support" OFF)
74 option(ENABLE_LIBSVN    "Set to ON to build SimGear with libsvnclient support" ON)
75 option(ENABLE_RTI       "Set to ON to build SimGear with RTI support" OFF)
76 option(ENABLE_TESTS     "Set to OFF to disable building SimGear's test applications" ON)
77 option(SYSTEM_EXPAT     "Set to ON to build SimGear using the system libExpat" OFF)
78
79 if (MSVC)
80   GET_FILENAME_COMPONENT(PARENT_DIR ${PROJECT_SOURCE_DIR} PATH)
81   if (CMAKE_CL_64)
82     SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty.x64")
83   else (CMAKE_CL_64)
84     SET(TEST_3RDPARTY_DIR "${PARENT_DIR}/3rdparty")
85   endif (CMAKE_CL_64)
86   if (EXISTS ${TEST_3RDPARTY_DIR})
87     set(MSVC_3RDPARTY_ROOT ${PARENT_DIR} CACHE PATH "Location where the third-party dependencies are extracted")
88   else (EXISTS ${TEST_3RDPARTY_DIR})
89     set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
90   endif (EXISTS ${TEST_3RDPARTY_DIR})
91 else (MSVC)
92   set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
93 endif (MSVC)
94
95 if (MSVC AND MSVC_3RDPARTY_ROOT)
96   message(STATUS "3rdparty files located in ${MSVC_3RDPARTY_ROOT}")
97   set( OSG_MSVC "msvc" )
98   if (${MSVC_VERSION} EQUAL 1700)
99       set( OSG_MSVC ${OSG_MSVC}110 )
100   elseif (${MSVC_VERSION} EQUAL 1600)
101       set( OSG_MSVC ${OSG_MSVC}100 )
102   else (${MSVC_VERSION} EQUAL 1700)
103       set( OSG_MSVC ${OSG_MSVC}90 )
104   endif (${MSVC_VERSION} EQUAL 1700)
105   if (CMAKE_CL_64)
106       set( OSG_MSVC ${OSG_MSVC}-64 )
107       set( MSVC_3RDPARTY_DIR 3rdParty.x64 )
108   else (CMAKE_CL_64)
109       set( MSVC_3RDPARTY_DIR 3rdParty )
110   endif (CMAKE_CL_64)
111
112   set (CMAKE_LIBRARY_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenScenegraph/lib )
113   set (CMAKE_INCLUDE_PATH ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include ${MSVC_3RDPARTY_ROOT}/install/${OSG_MSVC}/OpenScenegraph/include)
114   find_path(BOOST_ROOT boost/version.hpp
115                         ${MSVC_3RDPARTY_ROOT}/boost
116                         ${MSVC_3RDPARTY_ROOT}/boost_1_51_0
117                         ${MSVC_3RDPARTY_ROOT}/boost_1_50_0
118                         ${MSVC_3RDPARTY_ROOT}/boost_1_49_0
119                         ${MSVC_3RDPARTY_ROOT}/boost_1_48_0
120                         ${MSVC_3RDPARTY_ROOT}/boost_1_47_0
121                         ${MSVC_3RDPARTY_ROOT}/boost_1_46_1
122                         ${MSVC_3RDPARTY_ROOT}/boost_1_46_0
123                         ${MSVC_3RDPARTY_ROOT}/boost_1_45_0
124                         ${MSVC_3RDPARTY_ROOT}/boost_1_44_0
125                         )
126   # set (BOOST_ROOT ${MSVC_3RDPARTY_ROOT}/boost_1_44_0)
127   message(STATUS "BOOST_ROOT is ${BOOST_ROOT}")
128   set (OPENAL_INCLUDE_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/include)
129   set (OPENAL_LIBRARY_DIR ${MSVC_3RDPARTY_ROOT}/${MSVC_3RDPARTY_DIR}/lib)
130 endif (MSVC AND MSVC_3RDPARTY_ROOT)
131
132 find_package(Boost REQUIRED)
133 set (BOOST_CXX_FLAGS "-DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_BIMAP_DISABLE_SERIALIZATION")
134
135 if(SIMGEAR_HEADLESS)
136     message(STATUS "SimGear mode: HEADLESS")
137 else()
138     message(STATUS "SimGear mode: NORMAL")
139     find_package(OpenGL REQUIRED)
140     find_package(OpenAL REQUIRED)
141     find_package(OpenSceneGraph 3.0.0 REQUIRED osgText osgSim osgDB osgParticle osgGA osgUtil)
142 endif(SIMGEAR_HEADLESS)
143
144 if(JPEG_FACTORY)
145     message(STATUS "JPEG-factory: ENABLED")
146     find_package(JPEG REQUIRED)
147     include_directories(${JPEG_INCLUDE_DIR})
148 else()
149     message(STATUS "JPEG-factory: DISABLED")
150 endif(JPEG_FACTORY)
151
152 if(ENABLE_LIBSVN)
153     find_package(SvnClient)
154
155     if(LIBSVN_FOUND)
156         message(STATUS "Subversion client support: ENABLED")
157         set(HAVE_SVN_CLIENT_H 1)
158         set(HAVE_LIBSVN_CLIENT_1 1)
159     else()
160         # Oops. ENABLE_LIBSVN is ON, but svn is still missing.
161         # Provide clearly visible warning/hint, so builders know what else they should install (or disable).
162         message(WARNING "Failed to enable subversion client support. Unable to find required subversion client library. Some features may not be available (scenery download).")
163         message(WARNING "Install 'libsvn' library/DLL (libsvn-devel/libsvnclient/...). Otherwise disable subversion support (set 'ENABLE_LIBSVN' to 'OFF').")
164     endif(LIBSVN_FOUND)
165 else()
166     message(STATUS "Subversion client support: DISABLED")
167 endif(ENABLE_LIBSVN)
168
169 find_package(ZLIB REQUIRED)
170 find_package(Threads REQUIRED)
171
172 if (SYSTEM_EXPAT)
173     message(STATUS "Requested to use system Expat library, forcing SIMGEAR_SHARED to true")
174     set(SIMGEAR_SHARED ON)
175     find_package(EXPAT REQUIRED)
176     include_directories(${EXPAT_INCLUDE_DIRS})
177 else()
178     message(STATUS "Using built-in expat code")
179     add_definitions(-DHAVE_EXPAT_CONFIG_H)
180 endif(SYSTEM_EXPAT)
181
182 check_include_file(sys/time.h HAVE_SYS_TIME_H)
183 check_include_file(sys/timeb.h HAVE_SYS_TIMEB_H)
184 check_include_file(unistd.h HAVE_UNISTD_H)
185 check_include_file(windows.h HAVE_WINDOWS_H)
186
187 if(ENABLE_RTI)
188     # See if we have any rti library variant installed
189     message(STATUS "RTI: ENABLED")
190     find_package(RTI)
191 else()
192     message(STATUS "RTI: DISABLED")
193 endif(ENABLE_RTI)
194
195 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
196 check_function_exists(ftime HAVE_FTIME)
197 check_function_exists(timegm HAVE_TIMEGM)
198 check_function_exists(rint HAVE_RINT)
199 check_function_exists(mkdtemp HAVE_MKDTEMP)
200 check_function_exists(bcopy HAVE_BCOPY)
201 check_function_exists(mmap HAVE_MMAP)
202
203 if(HAVE_UNISTD_H)
204     set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
205     check_cxx_source_compiles(
206        "#include <unistd.h>
207         #if !defined(_POSIX_TIMERS) || (0 >= _POSIX_TIMERS)
208             #error clock_gettime is not supported
209         #endif
210
211         int main() { return 0; }
212         "
213         HAVE_CLOCK_GETTIME)
214 endif(HAVE_UNISTD_H)
215
216 set(RT_LIBRARY "")
217 if(HAVE_CLOCK_GETTIME)
218     check_library_exists(rt clock_gettime "" HAVE_RT)
219     if(HAVE_RT)
220         set(RT_LIBRARY rt)
221     endif(HAVE_RT)
222 endif(HAVE_CLOCK_GETTIME)
223
224 SET(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually 'd' on windows")
225 SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
226 SET(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
227 SET(CMAKE_MINSIZEREL_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows")
228
229 # isnan might not be real symbol, so can't check using function_exists
230 check_cxx_source_compiles(
231     "#include <cmath> 
232     void f() { isnan(0.0);} "
233     HAVE_ISNAN)
234
235 if(CMAKE_COMPILER_IS_GNUCXX)
236     set(WARNING_FLAGS_CXX "-Wall")
237     set(WARNING_FLAGS_C   "-Wall")
238
239     # certain GCC versions don't provide the atomic builds, and hence
240     # require is to provide them in SGAtomic.cxx
241     set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
242     check_cxx_source_compiles(
243        "int main() { unsigned mValue; return __sync_add_and_fetch(&mValue, 1); }"
244         GCC_ATOMIC_BUILTINS_FOUND)
245 endif(CMAKE_COMPILER_IS_GNUCXX)
246
247 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
248    set(WARNING_FLAGS_CXX "-Wall -Wno-overloaded-virtual")
249    set(WARNING_FLAGS_C   "-Wall")
250 endif()
251
252 if(WIN32)
253
254     if(MINGW)
255         add_definitions(-D_WIN32_WINNT=0x501)
256     endif()
257
258     if(MSVC)
259         # turn off various warnings
260         # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996)
261         #     SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
262         # endforeach(warning)
263         
264         set(MSVC_FLAGS "-DWIN32 -DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS /wd4996 /wd4250")
265     endif(MSVC)
266     
267     # assumed on Windows
268     set(HAVE_GETLOCALTIME 1)
269     
270     set( WINSOCK_LIBRARY "ws2_32.lib" )
271     set( RT_LIBRARY "winmm" )
272 endif(WIN32)
273
274 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS_C} ${MSVC_FLAGS}")
275 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS_CXX} ${MSVC_FLAGS} ${BOOST_CXX_FLAGS}")
276
277 include_directories(${PROJECT_SOURCE_DIR})
278 include_directories(${PROJECT_BINARY_DIR}/simgear)
279 include_directories(${PROJECT_BINARY_DIR}/simgear/xml)
280
281 include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS} 
282     ${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR} 
283     ${OPENAL_INCLUDE_DIR} )
284
285 add_definitions(-DHAVE_CONFIG_H)
286
287 # configure a header file to pass some of the CMake settings
288 # to the source code
289 configure_file (
290   "${PROJECT_SOURCE_DIR}/simgear/simgear_config_cmake.h.in"
291   "${PROJECT_BINARY_DIR}/simgear/simgear_config.h"
292   )
293
294 configure_file (
295     "${PROJECT_SOURCE_DIR}/simgear/xml/expat_config_cmake.in"
296     "${PROJECT_BINARY_DIR}/simgear/xml/expat_config.h"
297 )
298
299 if(ENABLE_TESTS)
300     # enable CTest / make test target
301     message(STATUS "Tests: ENABLED")
302
303     include (Dart)
304         enable_testing()
305 else()
306     message(STATUS "Tests: DISABLED")
307 endif(ENABLE_TESTS)
308
309 install (FILES ${PROJECT_BINARY_DIR}/simgear/simgear_config.h  DESTINATION include/simgear/)
310 add_subdirectory(simgear)
311
312 #-----------------------------------------------------------------------------
313 ### uninstall target
314 #-----------------------------------------------------------------------------
315 CONFIGURE_FILE(
316   "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in"
317   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
318   IMMEDIATE @ONLY)
319 ADD_CUSTOM_TARGET(uninstall
320   "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")