]> git.mxchange.org Git - flightgear.git/blob - CMakeModules/FindSimGear.cmake
b4ac321fbcc5fb2b58387753d715544cfd76400e
[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 if(${SIMGEAR_LIBRARIES} STREQUAL "SIMGEAR_LIBRARIES-NOTFOUND")  
86         set(SIMGEAR_LIBRARIES "") # clear value
87         
88   # note the order here affects the order Simgear libraries are
89   # linked in, and hence ability to link when using a traditional
90   # linker such as GNU ld on Linux
91         set(comps 
92                 ephemeris
93                 environment
94                 nasal
95     sky
96                 material tgdb
97     model    
98     screen
99     bucket
100     bvh
101                 util route
102                 timing
103                 threads
104                 io
105     serial
106                 sound
107     structure
108     props
109     xml
110     debug 
111                 misc
112                 magvar
113     math)
114         
115         foreach(component ${comps})
116                 find_sg_component(${component} SIMGEAR_LIBRARIES)
117         endforeach()
118 endif()
119
120 # now we've found SimGear, check its version
121
122 include(CheckCXXSourceRuns)
123
124 message(STATUS "looking for version: ${SimGear_FIND_VERSION}")
125
126 SET(CMAKE_REQUIRED_INCLUDES ${SIMGEAR_INCLUDE_DIR})
127
128 check_cxx_source_runs(
129     "#include <cstdio>
130     #include <simgear/version.h>
131     
132     #define xstr(s) str(s)
133     #define str(s) #s
134      
135         #define MIN_MAJOR ${SimGear_FIND_VERSION_MAJOR}
136         #define MIN_MINOR ${SimGear_FIND_VERSION_MINOR}
137         #define MIN_MICRO ${SimGear_FIND_VERSION_PATCH}
138         
139         int main() {
140             int major, minor, micro;
141
142             /* printf(%d.%d.%d or greater, , MIN_MAJOR, MIN_MINOR, MIN_MICRO); */
143             printf(\"found %s ... \", xstr(SIMGEAR_VERSION));
144
145             sscanf( xstr(SIMGEAR_VERSION), \"%d.%d.%d\", &major, &minor, &micro );
146
147             if ( (major < MIN_MAJOR) ||
148                  (major == MIN_MAJOR && minor < MIN_MINOR) ||
149                  (major == MIN_MAJOR && minor == MIN_MINOR && micro < MIN_MICRO) ) {
150                  return -1;
151             }
152
153             return 0;
154         }
155     "
156     SIMGEAR_VERSION_OK)
157
158 include(FindPackageHandleStandardArgs)
159 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SimGear DEFAULT_MSG 
160          SIMGEAR_LIBRARIES SIMGEAR_INCLUDE_DIR SIMGEAR_VERSION_OK)
161