]> git.mxchange.org Git - flightgear.git/blob - CMakeModules/FindSimGear.cmake
Merge branch 'next' of http://git.gitorious.org/fg/flightgear into next
[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 FIND_PATH(SIMGEAR_INCLUDE_DIR simgear/math/SGMath.hxx
38   HINTS $ENV{SIMGEAR_DIR}
39   PATH_SUFFIXES include 
40   PATHS
41   ~/Library/Frameworks
42   /Library/Frameworks
43   /usr/local
44   /usr
45   /opt
46 )
47
48 message(STATUS ${SIMGEAR_INCLUDE_DIR})
49
50 # check for dynamic framework/library
51 FIND_LIBRARY(SIMGEAR_LIBRARIES
52   NAMES simgear SimGear
53   HINTS
54   $ENV{SIMGEAR_DIR}
55   PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
56   PATHS
57   ~/Library/Frameworks
58   /Library/Frameworks
59   /usr/local
60   /usr
61   /opt
62 )
63
64 macro(find_sg_component comp libs)
65     set(compLib "sg${comp}")
66     string(TOUPPER "SIMGEAR_${comp}_LIBRARY" compLibName)
67     
68     FIND_LIBRARY(${compLibName}
69       NAMES ${compLib}
70       HINTS $ENV{SIMGEAR_DIR}
71       PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
72       PATHS
73       /usr/local
74       /usr
75       /opt
76     )
77     
78     set(componentLib ${${compLibName}})
79     if (NOT ${componentLib} STREQUAL "componentLib-NOTFOUND")
80         #message(STATUS "found ${componentLib}")
81         list(APPEND ${libs} ${componentLib})
82     endif()
83 endmacro()
84
85
86 if(${SIMGEAR_LIBRARIES} STREQUAL "SIMGEAR_LIBRARIES-NOTFOUND")  
87     set(SIMGEAR_LIBRARIES "") # clear value
88     
89     if(NOT MSVC)
90         # Olaf indicates that linking the threads libs causes failures
91         # on MSVC builds
92         set(thread_lib threads)
93     endif(NOT MSVC)
94     
95   # note the order here affects the order Simgear libraries are
96   # linked in, and hence ability to link when using a traditional
97   # linker such as GNU ld on Linux
98     set(comps 
99         ephemeris
100         environment
101         nasal
102         sky
103         material tgdb
104         model    
105         screen
106         bucket
107         bvh
108         util route
109         timing
110         ${thread_lib}
111         io
112         serial
113         sound
114         structure
115         props
116         xml
117         debug 
118         misc
119         magvar
120         math)
121     
122     foreach(component ${comps})
123         find_sg_component(${component} SIMGEAR_LIBRARIES)
124     endforeach()
125 endif()
126
127 # now we've found SimGear, check its version
128
129 include(CheckCXXSourceRuns)
130
131 message(STATUS "looking for version: ${SimGear_FIND_VERSION}")
132
133 SET(CMAKE_REQUIRED_INCLUDES ${SIMGEAR_INCLUDE_DIR})
134
135 check_cxx_source_runs(
136     "#include <cstdio>
137     #include \"simgear/version.h\"
138     
139     #define xstr(s) str(s)
140     #define str(s) #s
141      
142     #define MIN_MAJOR ${SimGear_FIND_VERSION_MAJOR}
143     #define MIN_MINOR ${SimGear_FIND_VERSION_MINOR}
144     #define MIN_MICRO ${SimGear_FIND_VERSION_PATCH}
145     
146     int main() {
147         int major, minor, micro;
148
149         /* printf(%d.%d.%d or greater, , MIN_MAJOR, MIN_MINOR, MIN_MICRO); */
150         printf(\"found %s ... \", xstr(SIMGEAR_VERSION));
151
152         sscanf( xstr(SIMGEAR_VERSION), \"%d.%d.%d\", &major, &minor, &micro );
153
154         if ( (major < MIN_MAJOR) ||
155              (major == MIN_MAJOR && minor < MIN_MINOR) ||
156              (major == MIN_MAJOR && minor == MIN_MINOR && micro < MIN_MICRO) ) {
157          return -1;
158         }
159
160         return 0;
161     }
162     "
163     SIMGEAR_VERSION_OK)
164
165 include(FindPackageHandleStandardArgs)
166 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SimGear DEFAULT_MSG 
167      SIMGEAR_LIBRARIES SIMGEAR_INCLUDE_DIR SIMGEAR_VERSION_OK)
168