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