]> git.mxchange.org Git - flightgear.git/blob - CMakeModules/FindSimGear.cmake
Make the sound-manager optional in a few places.
[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_DIR, 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       /usr/local
42       /usr
43       /opt
44     )
45     FIND_LIBRARY(${libVarName}_RELEASE
46       NAMES ${libName}${CMAKE_RELEASE_POSTFIX}
47       HINTS $ENV{SIMGEAR_DIR}
48       PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
49       PATHS
50       /usr/local
51       /usr
52       /opt
53     )
54     
55    # message(STATUS "before: Simgear ${${libVarName}_RELEASE} ")
56   #  message(STATUS "before: Simgear ${${libVarName}_DEBUG} ")
57     
58     select_library_configurations( ${varName} )
59
60   #  message(STATUS "after:Simgear ${${libVarName}_RELEASE} ")
61   #  message(STATUS "after:Simgear ${${libVarName}_DEBUG} ")
62
63     set(componentLibRelease ${${libVarName}_RELEASE})
64   #  message(STATUS "Simgear ${libVarName}_RELEASE ${componentLibRelease}")
65     set(componentLibDebug ${${libVarName}_DEBUG})
66    # message(STATUS "Simgear ${libVarName}_DEBUG ${componentLibDebug}")
67     
68     if (NOT ${libVarName}_DEBUG)
69         if (NOT ${libVarName}_RELEASE)
70             #message(STATUS "found ${componentLib}")
71             list(APPEND ${libs} ${componentLibRelease})
72         endif()
73     else()
74         list(APPEND ${libs} optimized ${componentLibRelease} debug ${componentLibDebug})
75     endif()
76 endmacro()
77
78 FIND_PATH(SIMGEAR_INCLUDE_DIR simgear/math/SGMath.hxx
79   HINTS $ENV{SIMGEAR_DIR}
80   PATH_SUFFIXES include
81   PATHS
82   ~/Library/Frameworks
83   /Library/Frameworks
84   /usr/local
85   /usr
86   /opt
87 )
88
89 # make sure the simgear include directory exists
90 if (NOT SIMGEAR_INCLUDE_DIR)
91     message(FATAL_ERROR "Cannot find SimGear includes! (Forgot 'make install' for SimGear?) "
92             "Compile & INSTALL SimGear before configuring FlightGear. "
93             "When using non-standard locations, use 'SIMGEAR_DIR' to configure the SimGear location.")
94 endif()
95
96 message(STATUS "SimGear include directory: ${SIMGEAR_INCLUDE_DIR}")
97
98 # read the simgear version header file, get the version
99 file(READ ${SIMGEAR_INCLUDE_DIR}/simgear/version.h SG_VERSION_FILE)
100
101 # make sure the simgear/version.h header exists
102 if (NOT SG_VERSION_FILE)
103     message(FATAL_ERROR "Found SimGear, but it does not contain a simgear/version.h include! "
104             "SimGear installation is incomplete or mismatching.")
105 endif()
106
107 string(STRIP "${SG_VERSION_FILE}" SIMGEAR_DEFINE)
108 string(REPLACE "#define SIMGEAR_VERSION " "" SIMGEAR_VERSION "${SIMGEAR_DEFINE}")
109
110 if(NOT SIMGEAR_VERSION)
111     message(FATAL_ERROR "Unable to find SimGear or simgear/version.h does not exist/is invalid. "
112             "Make sure you have installed the SimGear ${SimGear_FIND_VERSION} includes. "
113             "When using non-standard locations, please use 'SIMGEAR_DIR' "
114             "to select the SimGear library location to be used.")
115 endif()
116
117 message(STATUS "found SimGear version: ${SIMGEAR_VERSION} (needed ${SimGear_FIND_VERSION})")
118
119 if(NOT "${SIMGEAR_VERSION}" EQUAL "${SimGear_FIND_VERSION}")
120     message(FATAL_ERROR "You have installed a mismatching SimGear version ${SIMGEAR_VERSION} "
121             "instead of ${SimGear_FIND_VERSION} as required by FlightGear. "
122             "When using multiple SimGear installations, please use 'SIMGEAR_DIR' "
123             "to select the SimGear library location to be used.")
124 endif()
125
126 # dependent packages
127 find_package(ZLIB REQUIRED)
128 find_package(Threads REQUIRED)
129
130 if(SIMGEAR_SHARED)
131     message(STATUS "looking for shared Simgear libraries")
132
133     find_sg_library(SimGearCore SIMGEAR_CORE SIMGEAR_CORE_LIBRARIES)
134     find_sg_library(SimGearScene SIMGEAR_SCENE SIMGEAR_LIBRARIES)
135
136  
137     list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
138     set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES "")
139     set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES "")
140     
141    # message(STATUS "core lib ${SIMGEAR_CORE_LIBRARIES}")
142   #  message(STATUS "all libs ${SIMGEAR_LIBRARIES}")
143 else(SIMGEAR_SHARED)
144
145     set(SIMGEAR_LIBRARIES "") # clear value
146     set(SIMGEAR_CORE_LIBRARIES "") # clear value
147     message(STATUS "looking for static SimGear libraries")
148     
149     find_sg_library(SimGearCore SIMGEAR_CORE SIMGEAR_CORE_LIBRARIES)
150     find_sg_library(SimGearScene SIMGEAR_SCENE SIMGEAR_LIBRARIES)
151
152     # again link order matters - scene libraries depend on core ones
153     list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
154     
155     set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES
156         ${CMAKE_THREAD_LIBS_INIT}
157         ${ZLIB_LIBRARY}
158         ${LIBSVN_LIBRARIES}
159         ${WINMM_LIBRARY})
160
161     set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES 
162         ${OPENAL_LIBRARY})
163
164     if(WIN32)
165         list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ws2_32.lib)
166     endif(WIN32)
167
168     if(NOT MSVC)
169         # basic timing routines on non windows systems, may be also cygwin?!
170         check_library_exists(rt clock_gettime "" have_rt)
171         if(have_rt)
172             list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES rt)
173         endif(have_rt)
174     endif(NOT MSVC)
175 endif(SIMGEAR_SHARED)
176
177 if((NOT SIMGEAR_CORE_LIBRARIES)OR(NOT SIMGEAR_LIBRARIES))
178     message(FATAL_ERROR "Cannot find SimGear libraries! (Forgot 'make install' for SimGear?) "
179             "Compile & INSTALL SimGear before configuring FlightGear. "
180             "When using non-standard locations, use 'SIMGEAR_DIR' to configure the SimGear location.")
181 else()
182     message(STATUS "found SimGear libraries")
183 endif()
184
185 # now we've found SimGear, try test-compiling using its includes
186 include(CheckCXXSourceRuns)
187
188 SET(CMAKE_REQUIRED_INCLUDES ${SIMGEAR_INCLUDE_DIR})
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 include(FindPackageHandleStandardArgs)
233 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SimGear DEFAULT_MSG
234      SIMGEAR_LIBRARIES SIMGEAR_CORE_LIBRARIES SIMGEAR_INCLUDE_DIR SIMGEAR_COMPILE_TEST)
235