]> git.mxchange.org Git - flightgear.git/blob - CMakeModules/FindSimGear.cmake
Re-structure the SimGear detection, to bypass shared-library checks by default (and...
[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_component comp libs)
31     set(compLib "sg${comp}")
32     string(TOUPPER "SIMGEAR_${comp}" compLibBase)
33     set( compLibName ${compLibBase}_LIBRARY )
34
35     FIND_LIBRARY(${compLibName}_DEBUG
36       NAMES ${compLib}${CMAKE_DEBUG_POSTFIX}
37       HINTS $ENV{SIMGEAR_DIR}
38       PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
39       PATHS
40       /usr/local
41       /usr
42       /opt
43     )
44     FIND_LIBRARY(${compLibName}_RELEASE
45       NAMES ${compLib}${CMAKE_RELEASE_POSTFIX}
46       HINTS $ENV{SIMGEAR_DIR}
47       PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
48       PATHS
49       /usr/local
50       /usr
51       /opt
52     )
53     select_library_configurations( ${compLibBase} )
54
55     set(componentLibRelease ${${compLibName}_RELEASE})
56     #message(STATUS "Simgear ${compLibName}_RELEASE ${componentLibRelease}")
57     set(componentLibDebug ${${compLibName}_DEBUG})
58     #message(STATUS "Simgear ${compLibName}_DEBUG ${componentLibDebug}")
59     if (NOT ${compLibName}_DEBUG)
60         if (NOT ${compLibName}_RELEASE)
61             #message(STATUS "found ${componentLib}")
62             list(APPEND ${libs} ${componentLibRelease})
63         endif()
64     else()
65         list(APPEND ${libs} optimized ${componentLibRelease} debug ${componentLibDebug})
66     endif()
67 endmacro()
68
69 FIND_PATH(SIMGEAR_INCLUDE_DIR simgear/math/SGMath.hxx
70   HINTS $ENV{SIMGEAR_DIR}
71   PATH_SUFFIXES include
72   PATHS
73   ~/Library/Frameworks
74   /Library/Frameworks
75   /usr/local
76   /usr
77   /opt
78 )
79
80 message(STATUS ${SIMGEAR_INCLUDE_DIR})
81
82 # dependent packages
83 find_package(ZLIB REQUIRED)
84 find_package(Threads REQUIRED)
85
86 if(SIMGEAR_SHARED)
87     message(STATUS "looking for shared Simgear libraries")
88
89     # check for dynamic framework/library (experimental!)
90     FIND_LIBRARY(SIMGEAR_SHARED_CORE_LIBRARY
91       NAMES simgearCore SimGearCore
92       HINTS
93       $ENV{SIMGEAR_DIR}
94       PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
95       PATHS
96       ~/Library/Frameworks
97       /Library/Frameworks
98       /usr/local
99       /usr
100       /opt
101     )
102
103     FIND_LIBRARY(SIMGEAR_SHARED_SCENE_LIBRARY
104       NAMES simgearScene SimGearScene
105       HINTS
106       $ENV{SIMGEAR_DIR}
107       PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
108       PATHS
109       ~/Library/Frameworks
110       /Library/Frameworks
111       /usr/local
112       /usr
113       /opt
114     )
115     
116     set(SIMGEAR_CORE_LIBRARIES ${SIMGEAR_SHARED_CORE_LIBRARY})
117     set(SIMGEAR_LIBRARIES ${SIMGEAR_SHARED_SCENE_LIBRARY} ${SIMGEAR_SHARED_CORE_LIBRARY})
118     set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES "")
119     
120 else(SIMGEAR_SHARED)
121
122     set(SIMGEAR_LIBRARIES "") # clear value
123     set(SIMGEAR_CORE_LIBRARIES "") # clear value
124     message(STATUS "looking for static Simgear libraries")
125     
126   # note the order here affects the order Simgear libraries are
127   # linked in, and hence ability to link when using a traditional
128   # linker such as GNU ld on Linux
129     set(comps
130         tsync
131         environment
132         nasal
133         bucket
134         bvh
135         util 
136         route
137         timing
138         io
139         serial
140         sound
141         math
142         props
143         structure
144         xml
145         misc
146         threads
147         debug
148         magvar
149     )
150
151     set(scene_comps
152         ephem
153         sky
154         material
155         tgdb
156         model
157         screen)
158             
159     foreach(component ${comps})
160         find_sg_component(${component} SIMGEAR_CORE_LIBRARIES)
161     endforeach()
162
163     foreach(component ${scene_comps})
164         find_sg_component(${component} SIMGEAR_LIBRARIES)
165     endforeach()
166
167     # again link order matters - scene libraires depend on core ones
168     list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
169
170     set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES
171         ${CMAKE_THREAD_LIBS_INIT}
172         ${ZLIB_LIBRARY})
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