]> git.mxchange.org Git - flightgear.git/blob - CMakeModules/FindSimGear.cmake
79887afdc1f022d9475089fc885e46bed451ccc5
[flightgear.git] / CMakeModules / FindSimGear.cmake
1 # Locate SimGear
2 # This module defines
3 # SIMGEAR_LIBRARIES
4 # SIMGEAR_FOUND, if false, do not try to link to SimGear
5 # SIMGEAR_INCLUDE_DIR, where to find the headers
6 #
7 # $SIMGEAR_DIR is an environment variable that would
8 # correspond to the ./configure --prefix=$SIMGEAR_DIR
9 # used in building SimGear.
10 #
11 # Created by James Turner. This was influenced by the FindOpenAL.cmake module.
12
13 #=============================================================================
14 # Copyright 2005-2009 Kitware, Inc.
15 #
16 # Distributed under the OSI-approved BSD License (the "License");
17 # see accompanying file Copyright.txt for details.
18 #
19 # This software is distributed WITHOUT ANY WARRANTY; without even the
20 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 # See the License for more information.
22 #=============================================================================
23 # (To distributed this file outside of CMake, substitute the full
24 #  License text for the above reference.)
25
26 # Per my request, CMake should search for frameworks first in
27 # the following order:
28 # ~/Library/Frameworks/SimGear.framework/Headers
29 # /Library/Frameworks/SimGear.framework/Headers
30 # /System/Library/Frameworks/SimGear.framework/Headers
31 #
32 # On OS X, this will prefer the Framework version (if found) over others.
33 # People will have to manually change the cache values of
34 # SimGear_LIBRARIES to override this selection or set the CMake environment
35 # CMAKE_INCLUDE_PATH to modify the search paths.
36
37 include(SelectLibraryConfigurations)
38
39 FIND_PATH(SIMGEAR_INCLUDE_DIR simgear/math/SGMath.hxx
40   HINTS $ENV{SIMGEAR_DIR}
41   PATH_SUFFIXES include
42   PATHS
43   ~/Library/Frameworks
44   /Library/Frameworks
45   /usr/local
46   /usr
47   /opt
48 )
49
50 message(STATUS ${SIMGEAR_INCLUDE_DIR})
51
52 # check for dynamic framework/library
53 FIND_LIBRARY(SIMGEAR_LIBRARIES
54   NAMES simgear SimGear
55   HINTS
56   $ENV{SIMGEAR_DIR}
57   PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
58   PATHS
59   ~/Library/Frameworks
60   /Library/Frameworks
61   /usr/local
62   /usr
63   /opt
64 )
65
66 # dependent packages
67 find_package(ZLIB REQUIRED)
68 find_package(Threads REQUIRED)
69
70 macro(find_sg_component comp libs)
71     set(compLib "sg${comp}")
72     string(TOUPPER "SIMGEAR_${comp}" compLibBase)
73     set( compLibName ${compLibBase}_LIBRARY )
74
75     FIND_LIBRARY(${compLibName}_DEBUG
76       NAMES ${compLib}${CMAKE_DEBUG_POSTFIX}
77       HINTS $ENV{SIMGEAR_DIR}
78       PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
79       PATHS
80       /usr/local
81       /usr
82       /opt
83     )
84     FIND_LIBRARY(${compLibName}_RELEASE
85       NAMES ${compLib}${CMAKE_RELEASE_POSTFIX}
86       HINTS $ENV{SIMGEAR_DIR}
87       PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
88       PATHS
89       /usr/local
90       /usr
91       /opt
92     )
93     select_library_configurations( ${compLibBase} )
94
95     set(componentLibRelease ${${compLibName}_RELEASE})
96     #message(STATUS "Simgear ${compLibName}_RELEASE ${componentLibRelease}")
97     set(componentLibDebug ${${compLibName}_DEBUG})
98     #message(STATUS "Simgear ${compLibName}_DEBUG ${componentLibDebug}")
99     if (NOT ${compLibName}_DEBUG)
100         if (NOT ${compLibName}_RELEASE)
101             #message(STATUS "found ${componentLib}")
102             list(APPEND ${libs} ${componentLibRelease})
103         endif()
104     else()
105         list(APPEND ${libs} optimized ${componentLibRelease} debug ${componentLibDebug})
106     endif()
107 endmacro()
108
109
110 if(${SIMGEAR_LIBRARIES} STREQUAL "SIMGEAR_LIBRARIES-NOTFOUND")
111     set(SIMGEAR_LIBRARIES "") # clear value
112     set(SIMGEAR_CORE_LIBRARIES "") # clear value
113     
114   # note the order here affects the order Simgear libraries are
115   # linked in, and hence ability to link when using a traditional
116   # linker such as GNU ld on Linux
117     set(comps
118         tsync
119         environment
120         nasal
121         bucket
122         bvh
123         util 
124         route
125         timing
126         io
127         serial
128         sound
129         math
130         props
131         structure
132         xml
133         misc
134         threads
135         debug
136         magvar
137     )
138
139     set(scene_comps
140         ephem
141         sky
142         material
143         tgdb
144         model
145         screen)
146             
147     foreach(component ${comps})
148         find_sg_component(${component} SIMGEAR_CORE_LIBRARIES)
149     endforeach()
150
151     foreach(component ${scene_comps})
152         find_sg_component(${component} SIMGEAR_LIBRARIES)
153     endforeach()
154
155     # again link order matters - scene libraires depend on core ones
156     list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
157
158     set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES
159         ${CMAKE_THREAD_LIBS_INIT}
160         ${ZLIB_LIBRARY})
161
162     if(WIN32)
163         list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ws2_32.lib)
164     endif(WIN32)
165
166     if(NOT MSVC)
167         # basic timing routines on non windows systems, may be also cygwin?!
168         check_function_exists(clock_gettime clock_gettime_in_libc)
169         if(NOT clock_gettime_in_libc)
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 clock_gettime_in_libc)
175     endif(NOT MSVC)
176
177 endif()
178
179 # now we've found SimGear, check its version
180
181 include(CheckCXXSourceRuns)
182
183 message(STATUS "looking for version: ${SimGear_FIND_VERSION}")
184
185 SET(CMAKE_REQUIRED_INCLUDES ${SIMGEAR_INCLUDE_DIR})
186
187 check_cxx_source_runs(
188     "#include <cstdio>
189     #include \"simgear/version.h\"
190
191     #define xstr(s) str(s)
192     #define str(s) #s
193
194     #define MIN_MAJOR ${SimGear_FIND_VERSION_MAJOR}
195     #define MIN_MINOR ${SimGear_FIND_VERSION_MINOR}
196     #define MIN_MICRO ${SimGear_FIND_VERSION_PATCH}
197
198     int main() {
199         int major, minor, micro;
200
201         /* printf(%d.%d.%d or greater, , MIN_MAJOR, MIN_MINOR, MIN_MICRO); */
202         printf(\"found %s ... \", xstr(SIMGEAR_VERSION));
203
204         sscanf( xstr(SIMGEAR_VERSION), \"%d.%d.%d\", &major, &minor, &micro );
205
206         if ( (major < MIN_MAJOR) ||
207              (major == MIN_MAJOR && minor < MIN_MINOR) ||
208              (major == MIN_MAJOR && minor == MIN_MINOR && micro < MIN_MICRO) ) {
209          return -1;
210         }
211
212         return 0;
213     }
214     "
215     SIMGEAR_VERSION_OK)
216
217 include(FindPackageHandleStandardArgs)
218 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SimGear DEFAULT_MSG
219      SIMGEAR_LIBRARIES SIMGEAR_INCLUDE_DIR SIMGEAR_VERSION_OK)
220