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
9 # $SIMGEAR_DIR is an environment variable that would
10 # correspond to the ./configure --prefix=$SIMGEAR_DIR
11 # used in building SimGear.
13 # Created by James Turner. This was influenced by the FindOpenAL.cmake module.
15 #=============================================================================
16 # Copyright 2005-2009 Kitware, Inc.
18 # Distributed under the OSI-approved BSD License (the "License");
19 # see accompanying file Copyright.txt for details.
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.)
28 include(SelectLibraryConfigurations)
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)
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
45 FIND_LIBRARY(${libVarName}_RELEASE
46 NAMES ${libName}${CMAKE_RELEASE_POSTFIX}
47 HINTS $ENV{SIMGEAR_DIR}
48 PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
55 # message(STATUS "before: Simgear ${${libVarName}_RELEASE} ")
56 # message(STATUS "before: Simgear ${${libVarName}_DEBUG} ")
58 select_library_configurations( ${varName} )
60 # message(STATUS "after:Simgear ${${libVarName}_RELEASE} ")
61 # message(STATUS "after:Simgear ${${libVarName}_DEBUG} ")
63 set(componentLibRelease ${${libVarName}_RELEASE})
64 # message(STATUS "Simgear ${libVarName}_RELEASE ${componentLibRelease}")
65 set(componentLibDebug ${${libVarName}_DEBUG})
66 # message(STATUS "Simgear ${libVarName}_DEBUG ${componentLibDebug}")
68 if (NOT ${libVarName}_DEBUG)
69 if (NOT ${libVarName}_RELEASE)
70 #message(STATUS "found ${componentLib}")
71 list(APPEND ${libs} ${componentLibRelease})
74 list(APPEND ${libs} optimized ${componentLibRelease} debug ${componentLibDebug})
78 macro(find_sg_component comp libs)
79 set(compLib "sg${comp}")
80 string(TOUPPER "SIMGEAR_${comp}" libVar)
82 find_sg_library(${compLib} ${libVar} ${libs})
85 FIND_PATH(SIMGEAR_INCLUDE_DIR simgear/math/SGMath.hxx
86 HINTS $ENV{SIMGEAR_DIR}
96 # make sure the simgear include directory exists
97 if (NOT SIMGEAR_INCLUDE_DIR)
98 message(FATAL_ERROR "Cannot find SimGear includes! (Forgot 'make install' for SimGear?) "
99 "Compile & INSTALL SimGear before configuring FlightGear. "
100 "When using non-standard locations, use 'SIMGEAR_DIR' to configure the SimGear location.")
103 message(STATUS "SimGear include directory: ${SIMGEAR_INCLUDE_DIR}")
105 # read the simgear version header file, get the version
106 file(READ ${SIMGEAR_INCLUDE_DIR}/simgear/version.h SG_VERSION_FILE)
108 # make sure the simgear/version.h header exists
109 if (NOT SG_VERSION_FILE)
110 message(FATAL_ERROR "Found SimGear, but it does not contain a simgear/version.h include! "
111 "SimGear installation is incomplete or mismatching.")
114 string(STRIP "${SG_VERSION_FILE}" SIMGEAR_DEFINE)
115 string(REPLACE "#define SIMGEAR_VERSION " "" SIMGEAR_VERSION "${SIMGEAR_DEFINE}")
117 if(NOT SIMGEAR_VERSION)
118 message(FATAL_ERROR "Unable to find SimGear or simgear/version.h does not exist/is invalid. "
119 "Make sure you have installed the SimGear ${SimGear_FIND_VERSION} includes. "
120 "When using non-standard locations, please use 'SIMGEAR_DIR' "
121 "to select the SimGear library location to be used.")
124 message(STATUS "found SimGear version: ${SIMGEAR_VERSION} (needed ${SimGear_FIND_VERSION})")
126 if(NOT "${SIMGEAR_VERSION}" EQUAL "${SimGear_FIND_VERSION}")
127 message(FATAL_ERROR "You have installed a mismatching SimGear version ${SIMGEAR_VERSION} "
128 "instead of ${SimGear_FIND_VERSION} as required by FlightGear. "
129 "When using multiple SimGear installations, please use 'SIMGEAR_DIR' "
130 "to select the SimGear library location to be used.")
134 find_package(ZLIB REQUIRED)
135 find_package(Threads REQUIRED)
138 message(STATUS "looking for shared Simgear libraries")
140 find_sg_library(SimGearCore SIMGEAR_CORE SIMGEAR_CORE_LIBRARIES)
141 find_sg_library(SimGearScene SIMGEAR_SCENE SIMGEAR_LIBRARIES)
144 list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
145 set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES "")
146 set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES "")
148 # message(STATUS "core lib ${SIMGEAR_CORE_LIBRARIES}")
149 # message(STATUS "all libs ${SIMGEAR_LIBRARIES}")
152 set(SIMGEAR_LIBRARIES "") # clear value
153 set(SIMGEAR_CORE_LIBRARIES "") # clear value
154 message(STATUS "looking for static SimGear libraries")
156 # note the order here affects the order Simgear libraries are
157 # linked in, and hence ability to link when using a traditional
158 # linker such as GNU ld on Linux
188 foreach(component ${comps})
189 find_sg_component(${component} SIMGEAR_CORE_LIBRARIES)
192 foreach(component ${scene_comps})
193 find_sg_component(${component} SIMGEAR_LIBRARIES)
196 # again link order matters - scene libraries depend on core ones
197 list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
199 #message(STATUS "all libs ${SIMGEAR_LIBRARIES}")
201 set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES
202 ${CMAKE_THREAD_LIBS_INIT}
207 set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES
211 list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ws2_32.lib)
215 # basic timing routines on non windows systems, may be also cygwin?!
216 check_library_exists(rt clock_gettime "" have_rt)
218 list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES rt)
221 endif(SIMGEAR_SHARED)
223 if((NOT SIMGEAR_CORE_LIBRARIES)OR(NOT SIMGEAR_LIBRARIES))
224 message(FATAL_ERROR "Cannot find SimGear libraries! (Forgot 'make install' for SimGear?) "
225 "Compile & INSTALL SimGear before configuring FlightGear. "
226 "When using non-standard locations, use 'SIMGEAR_DIR' to configure the SimGear location.")
228 message(STATUS "found SimGear libraries")
231 # now we've found SimGear, try test-compiling using its includes
232 include(CheckCXXSourceRuns)
234 SET(CMAKE_REQUIRED_INCLUDES ${SIMGEAR_INCLUDE_DIR})
236 # clear cache, run a fresh compile test every time
237 unset(SIMGEAR_COMPILE_TEST CACHE)
239 # disable OSG dependencies for test-compiling
240 set(CMAKE_REQUIRED_DEFINITIONS "-DNO_OPENSCENEGRAPH_INTERFACE")
241 check_cxx_source_runs(
243 #include \"simgear/version.h\"
244 #include \"simgear/math/SGMath.hxx\"
246 #define xstr(s) str(s)
249 #define MIN_MAJOR ${SimGear_FIND_VERSION_MAJOR}
250 #define MIN_MINOR ${SimGear_FIND_VERSION_MINOR}
251 #define MIN_MICRO ${SimGear_FIND_VERSION_PATCH}
254 int major, minor, micro;
256 /* printf(%d.%d.%d or greater, , MIN_MAJOR, MIN_MINOR, MIN_MICRO); */
257 printf(\"found %s ... \", xstr(SIMGEAR_VERSION));
259 sscanf( xstr(SIMGEAR_VERSION), \"%d.%d.%d\", &major, &minor, µ );
261 if ( (major != MIN_MAJOR) ||
262 (minor != MIN_MINOR) ||
263 (micro != MIN_MICRO) ) {
270 SIMGEAR_COMPILE_TEST)
272 if(NOT SIMGEAR_COMPILE_TEST)
273 message(FATAL_ERROR "Oops, you have installed SimGear includes, however test compiling failed. "
274 "Try removing 'CMakeCache.txt' and reconfigure with 'cmake'.")
276 unset(CMAKE_REQUIRED_DEFINITIONS)
278 include(FindPackageHandleStandardArgs)
279 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SimGear DEFAULT_MSG
280 SIMGEAR_LIBRARIES SIMGEAR_CORE_LIBRARIES SIMGEAR_INCLUDE_DIR SIMGEAR_COMPILE_TEST)