]> git.mxchange.org Git - flightgear.git/blob - CMakeModules/FindSimGear.cmake
AI traffic refused to take-off, because the TrafficRecord destructor would unassign...
[flightgear.git] / CMakeModules / FindSimGear.cmake
1 # Locate SimGear
2 # This module defines
3
4 # SIMGEAR_CORE_LIBRARIES, a list of the core static libraries
5 # SIMGEAR_LIBRARIES, a list of all the static libraries (core + scene)
6 # SIMGEAR_FOUND, if false, do not try to link to SimGear
7 # SIMGEAR_INCLUDE_DIRS, where to find the headers
8 #
9 # $SIMGEAR_DIR is an environment variable that would
10 # correspond to the ./configure --prefix=$SIMGEAR_DIR
11 # used in building SimGear.
12 #
13 # Created by James Turner. This was influenced by the FindOpenAL.cmake module.
14
15 #=============================================================================
16 # Copyright 2005-2009 Kitware, Inc.
17 #
18 # Distributed under the OSI-approved BSD License (the "License");
19 # see accompanying file Copyright.txt for details.
20 #
21 # This software is distributed WITHOUT ANY WARRANTY; without even the
22 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 # See the License for more information.
24 #=============================================================================
25 # (To distributed this file outside of CMake, substitute the full
26 #  License text for the above reference.)
27
28 include(SelectLibraryConfigurations)
29
30 macro(find_sg_library libName varName libs)
31     set(libVarName "${varName}_LIBRARY")
32     # do not cache the library check
33     unset(${libVarName}_DEBUG CACHE)
34     unset(${libVarName}_RELEASE CACHE)
35
36     FIND_LIBRARY(${libVarName}_DEBUG
37       NAMES ${libName}${CMAKE_DEBUG_POSTFIX}
38       HINTS $ENV{SIMGEAR_DIR}
39       PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
40       PATHS
41       ${ADDITIONAL_LIBRARY_PATHS}
42     )
43     FIND_LIBRARY(${libVarName}_RELEASE
44       NAMES ${libName}${CMAKE_RELEASE_POSTFIX}
45       HINTS $ENV{SIMGEAR_DIR}
46       PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
47       PATHS
48       ${ADDITIONAL_LIBRARY_PATHS}
49     )
50
51    # message(STATUS "before: Simgear ${${libVarName}_RELEASE} ")
52   #  message(STATUS "before: Simgear ${${libVarName}_DEBUG} ")
53
54     select_library_configurations( ${varName} )
55
56   #  message(STATUS "after:Simgear ${${libVarName}_RELEASE} ")
57   #  message(STATUS "after:Simgear ${${libVarName}_DEBUG} ")
58
59     set(componentLibRelease ${${libVarName}_RELEASE})
60   #  message(STATUS "Simgear ${libVarName}_RELEASE ${componentLibRelease}")
61     set(componentLibDebug ${${libVarName}_DEBUG})
62    # message(STATUS "Simgear ${libVarName}_DEBUG ${componentLibDebug}")
63
64     if (NOT ${libVarName}_DEBUG)
65         if (NOT ${libVarName}_RELEASE)
66             #message(STATUS "found ${componentLib}")
67             list(APPEND ${libs} ${componentLibRelease})
68         endif()
69     else()
70         list(APPEND ${libs} optimized ${componentLibRelease} debug ${componentLibDebug})
71     endif()
72 endmacro()
73
74 FIND_PATH(SIMGEAR_INCLUDE_DIR simgear/math/SGMath.hxx
75   HINTS $ENV{SIMGEAR_DIR}
76   PATH_SUFFIXES include
77   PATHS
78   ${ADDITIONAL_LIBRARY_PATHS}
79 )
80
81 # make sure the simgear include directory exists
82 if (NOT SIMGEAR_INCLUDE_DIR)
83     message(FATAL_ERROR "Cannot find SimGear includes! (Forgot 'make install' for SimGear?) "
84             "Compile & INSTALL SimGear before configuring FlightGear. "
85             "When using non-standard locations, use 'SIMGEAR_DIR' to configure the SimGear location.")
86 endif()
87
88 message(STATUS "SimGear include directory: ${SIMGEAR_INCLUDE_DIR}")
89
90 # read the simgear version header file, get the version
91 file(READ ${SIMGEAR_INCLUDE_DIR}/simgear/version.h SG_VERSION_FILE)
92
93 # make sure the simgear/version.h header exists
94 if (NOT SG_VERSION_FILE)
95     message(FATAL_ERROR "Found SimGear, but it does not contain a simgear/version.h include! "
96             "SimGear installation is incomplete or mismatching.")
97 endif()
98
99 string(STRIP "${SG_VERSION_FILE}" SIMGEAR_DEFINE)
100 string(REPLACE "#define SIMGEAR_VERSION " "" SIMGEAR_VERSION "${SIMGEAR_DEFINE}")
101
102 if(NOT SIMGEAR_VERSION)
103     message(FATAL_ERROR "Unable to find SimGear or simgear/version.h does not exist/is invalid. "
104             "Make sure you have installed the SimGear ${SimGear_FIND_VERSION} includes. "
105             "When using non-standard locations, please use 'SIMGEAR_DIR' "
106             "to select the SimGear library location to be used.")
107 endif()
108
109 message(STATUS "found SimGear version: ${SIMGEAR_VERSION} (needed ${SimGear_FIND_VERSION})")
110
111 if(NOT "${SIMGEAR_VERSION}" EQUAL "${SimGear_FIND_VERSION}")
112     message(FATAL_ERROR "You have installed a mismatching SimGear version ${SIMGEAR_VERSION} "
113             "instead of ${SimGear_FIND_VERSION} as required by FlightGear. "
114             "When using multiple SimGear installations, please use 'SIMGEAR_DIR' "
115             "to select the SimGear library location to be used.")
116 endif()
117
118 # dependent packages
119 find_package(ZLIB REQUIRED)
120 find_package(Threads REQUIRED)
121
122 if(SIMGEAR_SHARED)
123     message(STATUS "looking for shared Simgear libraries")
124
125     find_sg_library(SimGearCore SIMGEAR_CORE SIMGEAR_CORE_LIBRARIES)
126     find_sg_library(SimGearScene SIMGEAR_SCENE SIMGEAR_LIBRARIES)
127
128     list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
129     set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES "")
130     set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES "")
131
132    # message(STATUS "core lib ${SIMGEAR_CORE_LIBRARIES}")
133   #  message(STATUS "all libs ${SIMGEAR_LIBRARIES}")
134 else(SIMGEAR_SHARED)
135
136     set(SIMGEAR_LIBRARIES "") # clear value
137     set(SIMGEAR_CORE_LIBRARIES "") # clear value
138     message(STATUS "looking for static SimGear libraries")
139
140     find_sg_library(SimGearCore SIMGEAR_CORE SIMGEAR_CORE_LIBRARIES)
141     find_sg_library(SimGearScene SIMGEAR_SCENE SIMGEAR_LIBRARIES)
142
143     # again link order matters - scene libraries depend on core ones
144     list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
145
146     set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES
147         ${CMAKE_THREAD_LIBS_INIT}
148         ${ZLIB_LIBRARY}
149         ${WINMM_LIBRARY})
150
151     set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES
152         ${OPENAL_LIBRARY})
153
154     if(APPLE)
155         find_library(COCOA_LIBRARY Cocoa)
156         list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ${COCOA_LIBRARY})
157     endif()
158
159     if(WIN32)
160         list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ws2_32.lib)
161     endif(WIN32)
162
163     if(NOT MSVC)
164         # basic timing routines on non windows systems, may be also cygwin?!
165         check_library_exists(rt clock_gettime "" have_rt)
166         if(have_rt)
167             list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES rt)
168         endif(have_rt)
169     endif(NOT MSVC)
170 endif(SIMGEAR_SHARED)
171
172 if((NOT SIMGEAR_CORE_LIBRARIES) OR (NOT SIMGEAR_LIBRARIES))
173     message(FATAL_ERROR "Cannot find SimGear libraries! (Forgot 'make install' for SimGear?) "
174             "Compile & INSTALL SimGear before configuring FlightGear. "
175             "When using non-standard locations, use 'SIMGEAR_DIR' to configure the SimGear location.")
176 else()
177     message(STATUS "found SimGear libraries")
178 endif()
179
180 # now we've found SimGear, try test-compiling using its includes
181 include(CheckCXXSourceRuns)
182 include(CheckCXXSourceCompiles)
183
184 set(SIMGEAR_INCLUDE_DIRS
185   ${SIMGEAR_INCLUDE_DIR}
186   ${SIMGEAR_INCLUDE_DIR}/simgear/3rdparty/utf8
187 )
188 SET(CMAKE_REQUIRED_INCLUDES ${SIMGEAR_INCLUDE_DIRS})
189
190 # clear cache, run a fresh compile test every time
191 unset(SIMGEAR_COMPILE_TEST CACHE)
192
193 # disable OSG dependencies for test-compiling
194 set(CMAKE_REQUIRED_DEFINITIONS "-DNO_OPENSCENEGRAPH_INTERFACE")
195 check_cxx_source_runs(
196     "#include <cstdio>
197     #include \"simgear/version.h\"
198     #include \"simgear/math/SGMath.hxx\"
199
200     #define xstr(s) str(s)
201     #define str(s) #s
202
203     #define MIN_MAJOR ${SimGear_FIND_VERSION_MAJOR}
204     #define MIN_MINOR ${SimGear_FIND_VERSION_MINOR}
205     #define MIN_MICRO ${SimGear_FIND_VERSION_PATCH}
206
207     int main() {
208         int major, minor, micro;
209
210         /* printf(%d.%d.%d or greater, , MIN_MAJOR, MIN_MINOR, MIN_MICRO); */
211         printf(\"found %s ... \", xstr(SIMGEAR_VERSION));
212
213         sscanf( xstr(SIMGEAR_VERSION), \"%d.%d.%d\", &major, &minor, &micro );
214
215         if ( (major != MIN_MAJOR) ||
216              (minor != MIN_MINOR) ||
217              (micro != MIN_MICRO) ) {
218          return -1;
219         }
220
221         return 0;
222     }
223     "
224     SIMGEAR_COMPILE_TEST)
225
226 if(NOT SIMGEAR_COMPILE_TEST)
227     message(FATAL_ERROR "Oops, you have installed SimGear includes, however test compiling failed. "
228             "Try removing 'CMakeCache.txt' and reconfigure with 'cmake'.")
229 endif()
230 unset(CMAKE_REQUIRED_DEFINITIONS)
231
232 unset(SIMGEAR_CURL_TEST CACHE)
233 check_cxx_source_compiles("
234   #include \"simgear/simgear_config.h\"
235   #if !defined(ENABLE_CURL)
236     #error Curl not enabled
237   #endif
238   int main() {}
239 "
240 SIMGEAR_CURL_TEST)
241
242 if (SIMGEAR_CURL_TEST)
243     message(STATUS "SimGear uses Curl")
244     find_package(CURL REQUIRED)
245     list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ${CURL_LIBRARIES})
246 endif()
247
248 include(FindPackageHandleStandardArgs)
249 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SimGear DEFAULT_MSG
250      SIMGEAR_LIBRARIES SIMGEAR_CORE_LIBRARIES SIMGEAR_INCLUDE_DIRS SIMGEAR_COMPILE_TEST)