]> git.mxchange.org Git - flightgear.git/blob - CMakeModules/FindSimGear.cmake
Merge branch 'radio-clutter' into attenuation
[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     
33     FIND_LIBRARY(${libVarName}_DEBUG
34       NAMES ${libName}${CMAKE_DEBUG_POSTFIX}
35       HINTS $ENV{SIMGEAR_DIR}
36       PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
37       PATHS
38       /usr/local
39       /usr
40       /opt
41     )
42     FIND_LIBRARY(${libVarName}_RELEASE
43       NAMES ${libName}${CMAKE_RELEASE_POSTFIX}
44       HINTS $ENV{SIMGEAR_DIR}
45       PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
46       PATHS
47       /usr/local
48       /usr
49       /opt
50     )
51     
52    # message(STATUS "before: Simgear ${${libVarName}_RELEASE} ")
53   #  message(STATUS "before: Simgear ${${libVarName}_DEBUG} ")
54     
55     select_library_configurations( ${varName} )
56
57   #  message(STATUS "after:Simgear ${${libVarName}_RELEASE} ")
58   #  message(STATUS "after:Simgear ${${libVarName}_DEBUG} ")
59
60     set(componentLibRelease ${${libVarName}_RELEASE})
61   #  message(STATUS "Simgear ${libVarName}_RELEASE ${componentLibRelease}")
62     set(componentLibDebug ${${libVarName}_DEBUG})
63    # message(STATUS "Simgear ${libVarName}_DEBUG ${componentLibDebug}")
64     
65     if (NOT ${libVarName}_DEBUG)
66         if (NOT ${libVarName}_RELEASE)
67             #message(STATUS "found ${componentLib}")
68             list(APPEND ${libs} ${componentLibRelease})
69         endif()
70     else()
71         list(APPEND ${libs} optimized ${componentLibRelease} debug ${componentLibDebug})
72     endif()
73 endmacro()
74
75 macro(find_sg_component comp libs)
76     set(compLib "sg${comp}")
77     string(TOUPPER "SIMGEAR_${comp}" libVar)
78     
79     find_sg_library(${compLib} ${libVar} ${libs})
80 endmacro()
81
82 FIND_PATH(SIMGEAR_INCLUDE_DIR simgear/math/SGMath.hxx
83   HINTS $ENV{SIMGEAR_DIR}
84   PATH_SUFFIXES include
85   PATHS
86   ~/Library/Frameworks
87   /Library/Frameworks
88   /usr/local
89   /usr
90   /opt
91 )
92
93 # message(STATUS ${SIMGEAR_INCLUDE_DIR})
94
95 # dependent packages
96 find_package(ZLIB REQUIRED)
97 find_package(Threads REQUIRED)
98
99 if(SIMGEAR_SHARED)
100     message(STATUS "looking for shared Simgear libraries")
101
102     find_sg_library(SimGearCore SIMGEAR_CORE SIMGEAR_CORE_LIBRARIES)
103     find_sg_library(SimGearScene SIMGEAR_SCENE SIMGEAR_LIBRARIES)
104
105  
106     list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
107     set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES "")
108     set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES "")
109     
110    # message(STATUS "core lib ${SIMGEAR_CORE_LIBRARIES}")
111   #  message(STATUS "all libs ${SIMGEAR_LIBRARIES}")
112 else(SIMGEAR_SHARED)
113
114     set(SIMGEAR_LIBRARIES "") # clear value
115     set(SIMGEAR_CORE_LIBRARIES "") # clear value
116     message(STATUS "looking for static Simgear libraries")
117     
118   # note the order here affects the order Simgear libraries are
119   # linked in, and hence ability to link when using a traditional
120   # linker such as GNU ld on Linux
121     set(comps
122         environment
123         nasal
124         bucket
125         route
126         timing
127         io
128         serial
129         math
130         props
131         structure
132         xml
133         misc
134         threads
135         debug
136         magvar
137     )
138
139     set(scene_comps
140         tsync
141         ephem
142         sky
143         material
144         tgdb
145         model
146         screen
147         bvh
148         util
149         sound)
150             
151     foreach(component ${comps})
152         find_sg_component(${component} SIMGEAR_CORE_LIBRARIES)
153     endforeach()
154
155     foreach(component ${scene_comps})
156         find_sg_component(${component} SIMGEAR_LIBRARIES)
157     endforeach()
158
159     
160     # again link order matters - scene libraries depend on core ones
161     list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
162
163     #message(STATUS "all libs ${SIMGEAR_LIBRARIES}")
164     
165     set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES
166         ${CMAKE_THREAD_LIBS_INIT}
167         ${ZLIB_LIBRARY})
168
169     set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES 
170         ${ALUT_LIBRARY} 
171         ${OPENAL_LIBRARY}
172         ${LIBSVN_LIBRARIES})
173
174     if(WIN32)
175         list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ws2_32.lib)
176     endif(WIN32)
177
178     if(NOT MSVC)
179         # basic timing routines on non windows systems, may be also cygwin?!
180         check_function_exists(clock_gettime clock_gettime_in_libc)
181         if(NOT clock_gettime_in_libc)
182             check_library_exists(rt clock_gettime "" have_rt)
183             if(have_rt)
184                 list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES rt)
185             endif(have_rt)
186         endif(NOT clock_gettime_in_libc)
187     endif(NOT MSVC)
188 endif(SIMGEAR_SHARED)
189
190 # now we've found SimGear, check its version
191
192 include(CheckCXXSourceRuns)
193
194 message(STATUS "looking for version: ${SimGear_FIND_VERSION}")
195
196 SET(CMAKE_REQUIRED_INCLUDES ${SIMGEAR_INCLUDE_DIR})
197
198 check_cxx_source_runs(
199     "#include <cstdio>
200     #include \"simgear/version.h\"
201
202     #define xstr(s) str(s)
203     #define str(s) #s
204
205     #define MIN_MAJOR ${SimGear_FIND_VERSION_MAJOR}
206     #define MIN_MINOR ${SimGear_FIND_VERSION_MINOR}
207     #define MIN_MICRO ${SimGear_FIND_VERSION_PATCH}
208
209     int main() {
210         int major, minor, micro;
211
212         /* printf(%d.%d.%d or greater, , MIN_MAJOR, MIN_MINOR, MIN_MICRO); */
213         printf(\"found %s ... \", xstr(SIMGEAR_VERSION));
214
215         sscanf( xstr(SIMGEAR_VERSION), \"%d.%d.%d\", &major, &minor, &micro );
216
217         if ( (major < MIN_MAJOR) ||
218              (major == MIN_MAJOR && minor < MIN_MINOR) ||
219              (major == MIN_MAJOR && minor == MIN_MINOR && micro < MIN_MICRO) ) {
220          return -1;
221         }
222
223         return 0;
224     }
225     "
226     SIMGEAR_VERSION_OK)
227
228 include(FindPackageHandleStandardArgs)
229 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SimGear DEFAULT_MSG
230      SIMGEAR_LIBRARIES SIMGEAR_INCLUDE_DIR SIMGEAR_VERSION_OK)
231