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")
33 FIND_LIBRARY(${libVarName}_DEBUG
34 NAMES ${libName}${CMAKE_DEBUG_POSTFIX}
35 HINTS $ENV{SIMGEAR_DIR}
36 PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
42 FIND_LIBRARY(${libVarName}_RELEASE
43 NAMES ${libName}${CMAKE_RELEASE_POSTFIX}
44 HINTS $ENV{SIMGEAR_DIR}
45 PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} libs64 libs libs/Win32 libs/Win64
52 # message(STATUS "before: Simgear ${${libVarName}_RELEASE} ")
53 # message(STATUS "before: Simgear ${${libVarName}_DEBUG} ")
55 select_library_configurations( ${varName} )
57 # message(STATUS "after:Simgear ${${libVarName}_RELEASE} ")
58 # message(STATUS "after:Simgear ${${libVarName}_DEBUG} ")
60 set(componentLibRelease ${${libVarName}_RELEASE})
61 # message(STATUS "Simgear ${libVarName}_RELEASE ${componentLibRelease}")
62 set(componentLibDebug ${${libVarName}_DEBUG})
63 # message(STATUS "Simgear ${libVarName}_DEBUG ${componentLibDebug}")
65 if (NOT ${libVarName}_DEBUG)
66 if (NOT ${libVarName}_RELEASE)
67 #message(STATUS "found ${componentLib}")
68 list(APPEND ${libs} ${componentLibRelease})
71 list(APPEND ${libs} optimized ${componentLibRelease} debug ${componentLibDebug})
75 macro(find_sg_component comp libs)
76 set(compLib "sg${comp}")
77 string(TOUPPER "SIMGEAR_${comp}" libVar)
79 find_sg_library(${compLib} ${libVar} ${libs})
82 FIND_PATH(SIMGEAR_INCLUDE_DIR simgear/math/SGMath.hxx
83 HINTS $ENV{SIMGEAR_DIR}
93 # message(STATUS ${SIMGEAR_INCLUDE_DIR})
96 find_package(ZLIB REQUIRED)
97 find_package(Threads REQUIRED)
100 message(STATUS "looking for shared Simgear libraries")
102 find_sg_library(SimGearCore SIMGEAR_CORE SIMGEAR_CORE_LIBRARIES)
103 find_sg_library(SimGearScene SIMGEAR_SCENE SIMGEAR_LIBRARIES)
106 list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
107 set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES "")
108 set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES "")
110 # message(STATUS "core lib ${SIMGEAR_CORE_LIBRARIES}")
111 # message(STATUS "all libs ${SIMGEAR_LIBRARIES}")
114 set(SIMGEAR_LIBRARIES "") # clear value
115 set(SIMGEAR_CORE_LIBRARIES "") # clear value
116 message(STATUS "looking for static Simgear libraries")
118 # note the order here affects the order Simgear libraries are
119 # linked in, and hence ability to link when using a traditional
120 # linker such as GNU ld on Linux
151 foreach(component ${comps})
152 find_sg_component(${component} SIMGEAR_CORE_LIBRARIES)
155 foreach(component ${scene_comps})
156 find_sg_component(${component} SIMGEAR_LIBRARIES)
160 # again link order matters - scene libraries depend on core ones
161 list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
163 #message(STATUS "all libs ${SIMGEAR_LIBRARIES}")
165 set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES
166 ${CMAKE_THREAD_LIBS_INIT}
169 set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES
175 list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ws2_32.lib)
179 # basic timing routines on non windows systems, may be also cygwin?!
180 check_function_exists(clock_gettime clock_gettime_in_libc)
181 if(NOT clock_gettime_in_libc)
182 check_library_exists(rt clock_gettime "" have_rt)
184 list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES rt)
186 endif(NOT clock_gettime_in_libc)
188 endif(SIMGEAR_SHARED)
190 # now we've found SimGear, check its version
192 include(CheckCXXSourceRuns)
194 message(STATUS "looking for version: ${SimGear_FIND_VERSION}")
196 SET(CMAKE_REQUIRED_INCLUDES ${SIMGEAR_INCLUDE_DIR})
198 check_cxx_source_runs(
200 #include \"simgear/version.h\"
202 #define xstr(s) str(s)
205 #define MIN_MAJOR ${SimGear_FIND_VERSION_MAJOR}
206 #define MIN_MINOR ${SimGear_FIND_VERSION_MINOR}
207 #define MIN_MICRO ${SimGear_FIND_VERSION_PATCH}
210 int major, minor, micro;
212 /* printf(%d.%d.%d or greater, , MIN_MAJOR, MIN_MINOR, MIN_MICRO); */
213 printf(\"found %s ... \", xstr(SIMGEAR_VERSION));
215 sscanf( xstr(SIMGEAR_VERSION), \"%d.%d.%d\", &major, &minor, µ );
217 if ( (major < MIN_MAJOR) ||
218 (major == MIN_MAJOR && minor < MIN_MINOR) ||
219 (major == MIN_MAJOR && minor == MIN_MINOR && micro < MIN_MICRO) ) {
228 include(FindPackageHandleStandardArgs)
229 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SimGear DEFAULT_MSG
230 SIMGEAR_LIBRARIES SIMGEAR_INCLUDE_DIR SIMGEAR_VERSION_OK)