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_DIRS, 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
41 ${ADDITIONAL_LIBRARY_PATHS}
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
48 ${ADDITIONAL_LIBRARY_PATHS}
51 # message(STATUS "before: Simgear ${${libVarName}_RELEASE} ")
52 # message(STATUS "before: Simgear ${${libVarName}_DEBUG} ")
54 select_library_configurations( ${varName} )
56 # message(STATUS "after:Simgear ${${libVarName}_RELEASE} ")
57 # message(STATUS "after:Simgear ${${libVarName}_DEBUG} ")
59 set(componentLibRelease ${${libVarName}_RELEASE})
60 # message(STATUS "Simgear ${libVarName}_RELEASE ${componentLibRelease}")
61 set(componentLibDebug ${${libVarName}_DEBUG})
62 # message(STATUS "Simgear ${libVarName}_DEBUG ${componentLibDebug}")
64 if (NOT ${libVarName}_DEBUG)
65 if (NOT ${libVarName}_RELEASE)
66 #message(STATUS "found ${componentLib}")
67 list(APPEND ${libs} ${componentLibRelease})
70 list(APPEND ${libs} optimized ${componentLibRelease} debug ${componentLibDebug})
74 FIND_PATH(SIMGEAR_INCLUDE_DIR simgear/math/SGMath.hxx
75 HINTS $ENV{SIMGEAR_DIR}
78 ${ADDITIONAL_LIBRARY_PATHS}
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.")
88 message(STATUS "SimGear include directory: ${SIMGEAR_INCLUDE_DIR}")
90 # read the simgear version header file, get the version
91 file(READ ${SIMGEAR_INCLUDE_DIR}/simgear/version.h SG_VERSION_FILE)
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.")
99 string(STRIP "${SG_VERSION_FILE}" SIMGEAR_DEFINE)
100 string(REPLACE "#define SIMGEAR_VERSION " "" SIMGEAR_VERSION "${SIMGEAR_DEFINE}")
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.")
109 message(STATUS "found SimGear version: ${SIMGEAR_VERSION} (needed ${SimGear_FIND_VERSION})")
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.")
119 find_package(ZLIB REQUIRED)
120 find_package(Threads REQUIRED)
123 message(STATUS "looking for shared Simgear libraries")
125 find_sg_library(SimGearCore SIMGEAR_CORE SIMGEAR_CORE_LIBRARIES)
126 find_sg_library(SimGearScene SIMGEAR_SCENE SIMGEAR_LIBRARIES)
128 list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
129 set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES "")
130 set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES "")
132 # message(STATUS "core lib ${SIMGEAR_CORE_LIBRARIES}")
133 # message(STATUS "all libs ${SIMGEAR_LIBRARIES}")
136 set(SIMGEAR_LIBRARIES "") # clear value
137 set(SIMGEAR_CORE_LIBRARIES "") # clear value
138 message(STATUS "looking for static SimGear libraries")
140 find_sg_library(SimGearCore SIMGEAR_CORE SIMGEAR_CORE_LIBRARIES)
141 find_sg_library(SimGearScene SIMGEAR_SCENE SIMGEAR_LIBRARIES)
143 # again link order matters - scene libraries depend on core ones
144 list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
146 set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES
147 ${CMAKE_THREAD_LIBS_INIT}
151 set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES
155 find_library(COCOA_LIBRARY Cocoa)
156 list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ${COCOA_LIBRARY})
160 list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ws2_32.lib)
164 # basic timing routines on non windows systems, may be also cygwin?!
165 check_library_exists(rt clock_gettime "" have_rt)
167 list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES rt)
170 endif(SIMGEAR_SHARED)
172 if((NOT SIMGEAR_CORE_LIBRARIES) OR (NOT SIMGEAR_LIBRARIES))
173 message(FATAL_ERROR "Cannot find SimGear libraries! (Forgot 'make install' for SimGear?) "
174 "Compile & INSTALL SimGear before configuring FlightGear. "
175 "When using non-standard locations, use 'SIMGEAR_DIR' to configure the SimGear location.")
177 message(STATUS "found SimGear libraries")
180 # now we've found SimGear, try test-compiling using its includes
181 include(CheckCXXSourceRuns)
183 set(SIMGEAR_INCLUDE_DIRS
184 ${SIMGEAR_INCLUDE_DIR}
185 ${SIMGEAR_INCLUDE_DIR}/simgear/3rdparty/utf8
187 SET(CMAKE_REQUIRED_INCLUDES ${SIMGEAR_INCLUDE_DIRS})
189 # clear cache, run a fresh compile test every time
190 unset(SIMGEAR_COMPILE_TEST CACHE)
192 # disable OSG dependencies for test-compiling
193 set(CMAKE_REQUIRED_DEFINITIONS "-DNO_OPENSCENEGRAPH_INTERFACE")
194 check_cxx_source_runs(
196 #include \"simgear/version.h\"
197 #include \"simgear/math/SGMath.hxx\"
199 #define xstr(s) str(s)
202 #define MIN_MAJOR ${SimGear_FIND_VERSION_MAJOR}
203 #define MIN_MINOR ${SimGear_FIND_VERSION_MINOR}
204 #define MIN_MICRO ${SimGear_FIND_VERSION_PATCH}
207 int major, minor, micro;
209 /* printf(%d.%d.%d or greater, , MIN_MAJOR, MIN_MINOR, MIN_MICRO); */
210 printf(\"found %s ... \", xstr(SIMGEAR_VERSION));
212 sscanf( xstr(SIMGEAR_VERSION), \"%d.%d.%d\", &major, &minor, µ );
214 if ( (major != MIN_MAJOR) ||
215 (minor != MIN_MINOR) ||
216 (micro != MIN_MICRO) ) {
223 SIMGEAR_COMPILE_TEST)
225 if(NOT SIMGEAR_COMPILE_TEST)
226 message(FATAL_ERROR "Oops, you have installed SimGear includes, however test compiling failed. "
227 "Try removing 'CMakeCache.txt' and reconfigure with 'cmake'.")
229 unset(CMAKE_REQUIRED_DEFINITIONS)
231 include(FindPackageHandleStandardArgs)
232 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SimGear DEFAULT_MSG
233 SIMGEAR_LIBRARIES SIMGEAR_CORE_LIBRARIES SIMGEAR_INCLUDE_DIRS SIMGEAR_COMPILE_TEST)