]> git.mxchange.org Git - flightgear.git/blob - CMakeModules/FindSimGear.cmake
Fix Mac data dir finding.
[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_library libName varName libs)
31     set(libVarName "${varName}_LIBRARY")
32     # do not cache the library check
33     unset(${libVarName}_DEBUG CACHE)
34     unset(${libVarName}_RELEASE CACHE)
35
36     FIND_LIBRARY(${libVarName}_DEBUG
37       NAMES ${libName}${CMAKE_DEBUG_POSTFIX}
38       HINTS $ENV{SIMGEAR_DIR}
39       PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
40       PATHS
41       ${ADDITIONAL_LIBRARY_PATHS}
42     )
43     FIND_LIBRARY(${libVarName}_RELEASE
44       NAMES ${libName}${CMAKE_RELEASE_POSTFIX}
45       HINTS $ENV{SIMGEAR_DIR}
46       PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
47       PATHS
48       ${ADDITIONAL_LIBRARY_PATHS}
49     )
50     
51    # message(STATUS "before: Simgear ${${libVarName}_RELEASE} ")
52   #  message(STATUS "before: Simgear ${${libVarName}_DEBUG} ")
53     
54     select_library_configurations( ${varName} )
55
56   #  message(STATUS "after:Simgear ${${libVarName}_RELEASE} ")
57   #  message(STATUS "after:Simgear ${${libVarName}_DEBUG} ")
58
59     set(componentLibRelease ${${libVarName}_RELEASE})
60   #  message(STATUS "Simgear ${libVarName}_RELEASE ${componentLibRelease}")
61     set(componentLibDebug ${${libVarName}_DEBUG})
62    # message(STATUS "Simgear ${libVarName}_DEBUG ${componentLibDebug}")
63     
64     if (NOT ${libVarName}_DEBUG)
65         if (NOT ${libVarName}_RELEASE)
66             #message(STATUS "found ${componentLib}")
67             list(APPEND ${libs} ${componentLibRelease})
68         endif()
69     else()
70         list(APPEND ${libs} optimized ${componentLibRelease} debug ${componentLibDebug})
71     endif()
72 endmacro()
73
74 FIND_PATH(SIMGEAR_INCLUDE_DIR simgear/math/SGMath.hxx
75   HINTS $ENV{SIMGEAR_DIR}
76   PATH_SUFFIXES include
77   PATHS
78   ${ADDITIONAL_LIBRARY_PATHS}
79 )
80
81 # make sure the simgear include directory exists
82 if (NOT SIMGEAR_INCLUDE_DIR)
83     message(FATAL_ERROR "Cannot find SimGear includes! (Forgot 'make install' for SimGear?) "
84             "Compile & INSTALL SimGear before configuring FlightGear. "
85             "When using non-standard locations, use 'SIMGEAR_DIR' to configure the SimGear location.")
86 endif()
87
88 message(STATUS "SimGear include directory: ${SIMGEAR_INCLUDE_DIR}")
89
90 # read the simgear version header file, get the version
91 file(READ ${SIMGEAR_INCLUDE_DIR}/simgear/version.h SG_VERSION_FILE)
92
93 # make sure the simgear/version.h header exists
94 if (NOT SG_VERSION_FILE)
95     message(FATAL_ERROR "Found SimGear, but it does not contain a simgear/version.h include! "
96             "SimGear installation is incomplete or mismatching.")
97 endif()
98
99 string(STRIP "${SG_VERSION_FILE}" SIMGEAR_DEFINE)
100 string(REPLACE "#define SIMGEAR_VERSION " "" SIMGEAR_VERSION "${SIMGEAR_DEFINE}")
101
102 if(NOT SIMGEAR_VERSION)
103     message(FATAL_ERROR "Unable to find SimGear or simgear/version.h does not exist/is invalid. "
104             "Make sure you have installed the SimGear ${SimGear_FIND_VERSION} includes. "
105             "When using non-standard locations, please use 'SIMGEAR_DIR' "
106             "to select the SimGear library location to be used.")
107 endif()
108
109 message(STATUS "found SimGear version: ${SIMGEAR_VERSION} (needed ${SimGear_FIND_VERSION})")
110
111 if(NOT "${SIMGEAR_VERSION}" EQUAL "${SimGear_FIND_VERSION}")
112     message(FATAL_ERROR "You have installed a mismatching SimGear version ${SIMGEAR_VERSION} "
113             "instead of ${SimGear_FIND_VERSION} as required by FlightGear. "
114             "When using multiple SimGear installations, please use 'SIMGEAR_DIR' "
115             "to select the SimGear library location to be used.")
116 endif()
117
118 # dependent packages
119 find_package(ZLIB REQUIRED)
120 find_package(Threads REQUIRED)
121
122 if(SIMGEAR_SHARED)
123     message(STATUS "looking for shared Simgear libraries")
124
125     find_sg_library(SimGearCore SIMGEAR_CORE SIMGEAR_CORE_LIBRARIES)
126     find_sg_library(SimGearScene SIMGEAR_SCENE SIMGEAR_LIBRARIES)
127  
128     list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
129     set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES "")
130     set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES "")
131     
132    # message(STATUS "core lib ${SIMGEAR_CORE_LIBRARIES}")
133   #  message(STATUS "all libs ${SIMGEAR_LIBRARIES}")
134 else(SIMGEAR_SHARED)
135
136     set(SIMGEAR_LIBRARIES "") # clear value
137     set(SIMGEAR_CORE_LIBRARIES "") # clear value
138     message(STATUS "looking for static SimGear libraries")
139     
140     find_sg_library(SimGearCore SIMGEAR_CORE SIMGEAR_CORE_LIBRARIES)
141     find_sg_library(SimGearScene SIMGEAR_SCENE SIMGEAR_LIBRARIES)
142
143     # again link order matters - scene libraries depend on core ones
144     list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
145     
146     set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES
147         ${CMAKE_THREAD_LIBS_INIT}
148         ${ZLIB_LIBRARY}
149         ${LIBSVN_LIBRARIES}
150         ${WINMM_LIBRARY})
151
152     set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES 
153         ${OPENAL_LIBRARY})
154
155     if(APPLE)
156         find_library(CORESERVICES_LIBRARY CoreServices)
157         list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ${CORESERVICES_LIBRARY})
158     endif()
159
160     if(WIN32)
161         list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ws2_32.lib)
162     endif(WIN32)
163
164     if(NOT MSVC)
165         # basic timing routines on non windows systems, may be also cygwin?!
166         check_library_exists(rt clock_gettime "" have_rt)
167         if(have_rt)
168             list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES rt)
169         endif(have_rt)
170     endif(NOT MSVC)
171 endif(SIMGEAR_SHARED)
172
173 if((NOT SIMGEAR_CORE_LIBRARIES)OR(NOT SIMGEAR_LIBRARIES))
174     message(FATAL_ERROR "Cannot find SimGear libraries! (Forgot 'make install' for SimGear?) "
175             "Compile & INSTALL SimGear before configuring FlightGear. "
176             "When using non-standard locations, use 'SIMGEAR_DIR' to configure the SimGear location.")
177 else()
178     message(STATUS "found SimGear libraries")
179 endif()
180
181 # now we've found SimGear, try test-compiling using its includes
182 include(CheckCXXSourceRuns)
183
184 SET(CMAKE_REQUIRED_INCLUDES ${SIMGEAR_INCLUDE_DIR})
185
186 # clear cache, run a fresh compile test every time
187 unset(SIMGEAR_COMPILE_TEST CACHE)
188
189 # disable OSG dependencies for test-compiling
190 set(CMAKE_REQUIRED_DEFINITIONS "-DNO_OPENSCENEGRAPH_INTERFACE")
191 check_cxx_source_runs(
192     "#include <cstdio>
193     #include \"simgear/version.h\"
194     #include \"simgear/math/SGMath.hxx\"
195
196     #define xstr(s) str(s)
197     #define str(s) #s
198
199     #define MIN_MAJOR ${SimGear_FIND_VERSION_MAJOR}
200     #define MIN_MINOR ${SimGear_FIND_VERSION_MINOR}
201     #define MIN_MICRO ${SimGear_FIND_VERSION_PATCH}
202
203     int main() {
204         int major, minor, micro;
205
206         /* printf(%d.%d.%d or greater, , MIN_MAJOR, MIN_MINOR, MIN_MICRO); */
207         printf(\"found %s ... \", xstr(SIMGEAR_VERSION));
208
209         sscanf( xstr(SIMGEAR_VERSION), \"%d.%d.%d\", &major, &minor, &micro );
210
211         if ( (major != MIN_MAJOR) ||
212              (minor != MIN_MINOR) ||
213              (micro != MIN_MICRO) ) {
214          return -1;
215         }
216
217         return 0;
218     }
219     "
220     SIMGEAR_COMPILE_TEST)
221
222 if(NOT SIMGEAR_COMPILE_TEST)
223     message(FATAL_ERROR "Oops, you have installed SimGear includes, however test compiling failed. "
224             "Try removing 'CMakeCache.txt' and reconfigure with 'cmake'.")
225 endif()
226 unset(CMAKE_REQUIRED_DEFINITIONS)
227
228 include(FindPackageHandleStandardArgs)
229 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SimGear DEFAULT_MSG
230      SIMGEAR_LIBRARIES SIMGEAR_CORE_LIBRARIES SIMGEAR_INCLUDE_DIR SIMGEAR_COMPILE_TEST)
231