]> git.mxchange.org Git - flightgear.git/blobdiff - CMakeModules/FindSimGear.cmake
Try to discover the most recent Boost version installed in MSVC_ROOT (Windows only)
[flightgear.git] / CMakeModules / FindSimGear.cmake
index 84ee6649f284b5e905da7ce5458fde067abe262d..5c21f5716e69df9d1d993652f4ab2cf0d15f4042 100644 (file)
@@ -29,7 +29,10 @@ include(SelectLibraryConfigurations)
 
 macro(find_sg_library libName varName libs)
     set(libVarName "${varName}_LIBRARY")
-    
+    # do not cache the library check
+    unset(${libVarName}_DEBUG CACHE)
+    unset(${libVarName}_RELEASE CACHE)
+
     FIND_LIBRARY(${libVarName}_DEBUG
       NAMES ${libName}${CMAKE_DEBUG_POSTFIX}
       HINTS $ENV{SIMGEAR_DIR}
@@ -90,7 +93,42 @@ FIND_PATH(SIMGEAR_INCLUDE_DIR simgear/math/SGMath.hxx
   /opt
 )
 
-# message(STATUS ${SIMGEAR_INCLUDE_DIR})
+# make sure the simgear include directory exists
+if (NOT SIMGEAR_INCLUDE_DIR)
+    message(FATAL_ERROR "Cannot find SimGear includes! (Forgot 'make install' for SimGear?) "
+            "Compile & INSTALL SimGear before configuring FlightGear. "
+            "When using non-standard locations, use 'SIMGEAR_DIR' to configure the SimGear location.")
+endif()
+
+message(STATUS "SimGear include directory: ${SIMGEAR_INCLUDE_DIR}")
+
+# read the simgear version header file, get the version
+file(READ ${SIMGEAR_INCLUDE_DIR}/simgear/version.h SG_VERSION_FILE)
+
+# make sure the simgear/version.h header exists
+if (NOT SG_VERSION_FILE)
+    message(FATAL_ERROR "Found SimGear, but it does not contain a simgear/version.h include! "
+            "SimGear installation is incomplete or mismatching.")
+endif()
+
+string(STRIP "${SG_VERSION_FILE}" SIMGEAR_DEFINE)
+string(REPLACE "#define SIMGEAR_VERSION " "" SIMGEAR_VERSION "${SIMGEAR_DEFINE}")
+
+if(NOT SIMGEAR_VERSION)
+    message(FATAL_ERROR "Unable to find SimGear or simgear/version.h does not exist/is invalid. "
+            "Make sure you have installed the SimGear ${SimGear_FIND_VERSION} includes. "
+            "When using non-standard locations, please use 'SIMGEAR_DIR' "
+            "to select the SimGear library location to be used.")
+endif()
+
+message(STATUS "found SimGear version: ${SIMGEAR_VERSION} (needed ${SimGear_FIND_VERSION})")
+
+if(NOT "${SIMGEAR_VERSION}" EQUAL "${SimGear_FIND_VERSION}")
+    message(FATAL_ERROR "You have installed a mismatching SimGear version ${SIMGEAR_VERSION} "
+            "instead of ${SimGear_FIND_VERSION} as required by FlightGear. "
+            "When using multiple SimGear installations, please use 'SIMGEAR_DIR' "
+            "to select the SimGear library location to be used.")
+endif()
 
 # dependent packages
 find_package(ZLIB REQUIRED)
@@ -113,7 +151,7 @@ else(SIMGEAR_SHARED)
 
     set(SIMGEAR_LIBRARIES "") # clear value
     set(SIMGEAR_CORE_LIBRARIES "") # clear value
-    message(STATUS "looking for static Simgear libraries")
+    message(STATUS "looking for static SimGear libraries")
     
   # note the order here affects the order Simgear libraries are
   # linked in, and hence ability to link when using a traditional
@@ -121,14 +159,15 @@ else(SIMGEAR_SHARED)
     set(comps
         environment
         nasal
+        tsync
+        bvh
         bucket
-        route
-        timing
         io
         serial
         math
         props
         structure
+        timing
         xml
         misc
         threads
@@ -137,14 +176,12 @@ else(SIMGEAR_SHARED)
     )
 
     set(scene_comps
-        tsync
         ephem
         sky
         material
         tgdb
         model
         screen
-        bvh
         util
         sound)
             
@@ -156,7 +193,6 @@ else(SIMGEAR_SHARED)
         find_sg_component(${component} SIMGEAR_LIBRARIES)
     endforeach()
 
-    
     # again link order matters - scene libraries depend on core ones
     list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES})
 
@@ -164,12 +200,12 @@ else(SIMGEAR_SHARED)
     
     set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES
         ${CMAKE_THREAD_LIBS_INIT}
-        ${ZLIB_LIBRARY})
+        ${ZLIB_LIBRARY}
+        ${LIBSVN_LIBRARIES}
+        ${WINMM_LIBRARY})
 
     set(SIMGEAR_SCENE_LIBRARY_DEPENDENCIES 
-        ${ALUT_LIBRARY} 
-       ${OPENAL_LIBRARY}
-       ${LIBSVN_LIBRARIES})
+        ${OPENAL_LIBRARY})
 
     if(WIN32)
         list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ws2_32.lib)
@@ -177,27 +213,35 @@ else(SIMGEAR_SHARED)
 
     if(NOT MSVC)
         # basic timing routines on non windows systems, may be also cygwin?!
-        check_function_exists(clock_gettime clock_gettime_in_libc)
-        if(NOT clock_gettime_in_libc)
-            check_library_exists(rt clock_gettime "" have_rt)
-            if(have_rt)
-                list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES rt)
-            endif(have_rt)
-        endif(NOT clock_gettime_in_libc)
+        check_library_exists(rt clock_gettime "" have_rt)
+        if(have_rt)
+            list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES rt)
+        endif(have_rt)
     endif(NOT MSVC)
 endif(SIMGEAR_SHARED)
 
-# now we've found SimGear, check its version
+if((NOT SIMGEAR_CORE_LIBRARIES)OR(NOT SIMGEAR_LIBRARIES))
+    message(FATAL_ERROR "Cannot find SimGear libraries! (Forgot 'make install' for SimGear?) "
+            "Compile & INSTALL SimGear before configuring FlightGear. "
+            "When using non-standard locations, use 'SIMGEAR_DIR' to configure the SimGear location.")
+else()
+    message(STATUS "found SimGear libraries")
+endif()
 
+# now we've found SimGear, try test-compiling using its includes
 include(CheckCXXSourceRuns)
 
-message(STATUS "looking for version: ${SimGear_FIND_VERSION}")
-
 SET(CMAKE_REQUIRED_INCLUDES ${SIMGEAR_INCLUDE_DIR})
 
+# clear cache, run a fresh compile test every time
+unset(SIMGEAR_COMPILE_TEST CACHE)
+
+# disable OSG dependencies for test-compiling
+set(CMAKE_REQUIRED_DEFINITIONS "-DNO_OPENSCENEGRAPH_INTERFACE")
 check_cxx_source_runs(
     "#include <cstdio>
     #include \"simgear/version.h\"
+    #include \"simgear/math/SGMath.hxx\"
 
     #define xstr(s) str(s)
     #define str(s) #s
@@ -214,18 +258,24 @@ check_cxx_source_runs(
 
         sscanf( xstr(SIMGEAR_VERSION), \"%d.%d.%d\", &major, &minor, &micro );
 
-        if ( (major < MIN_MAJOR) ||
-             (major == MIN_MAJOR && minor < MIN_MINOR) ||
-             (major == MIN_MAJOR && minor == MIN_MINOR && micro < MIN_MICRO) ) {
+        if ( (major != MIN_MAJOR) ||
+             (minor != MIN_MINOR) ||
+             (micro != MIN_MICRO) ) {
          return -1;
         }
 
         return 0;
     }
     "
-    SIMGEAR_VERSION_OK)
+    SIMGEAR_COMPILE_TEST)
+
+if(NOT SIMGEAR_COMPILE_TEST)
+    message(FATAL_ERROR "Oops, you have installed SimGear includes, however test compiling failed. "
+            "Try removing 'CMakeCache.txt' and reconfigure with 'cmake'.")
+endif()
+unset(CMAKE_REQUIRED_DEFINITIONS)
 
 include(FindPackageHandleStandardArgs)
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SimGear DEFAULT_MSG
-     SIMGEAR_LIBRARIES SIMGEAR_INCLUDE_DIR SIMGEAR_VERSION_OK)
+     SIMGEAR_LIBRARIES SIMGEAR_CORE_LIBRARIES SIMGEAR_INCLUDE_DIR SIMGEAR_COMPILE_TEST)