[soprano] cmake/modules: Improve FindRaptor.cmake

Michael Jansen kde at michael-jansen.biz
Tue Jul 19 18:47:31 CEST 2011


Git commit 267ca255245ac728aa58946c71405fddafe31df9 by Michael Jansen.
Committed on 19/07/2011 at 18:49.
Pushed by mjansen into branch 'master'.

Improve FindRaptor.cmake
	- Is able to look for both raptor1 and raptor2 (raptor2 is default)
	- Handles find_package(Raptor VERSION)
	- If raptor2 is searched and not found but raptor1 is there prints out nice message

Some other small improvements to be more cmake standard compliant.

NOTICE: Untested on windows. Please test if you can.

Could be a candidate for ECM.

CCMAIL: kde-buildsystem at kde.org
CCMAIL: trueg at kde.org
CCMAIL: v.for.vandal at gmail.com

M  +78   -43   cmake/modules/FindRaptor.cmake

http://commits.kde.org/soprano/267ca255245ac728aa58946c71405fddafe31df9

diff --git a/cmake/modules/FindRaptor.cmake b/cmake/modules/FindRaptor.cmake
index 51dccd7..c5043c8 100644
--- a/cmake/modules/FindRaptor.cmake
+++ b/cmake/modules/FindRaptor.cmake
@@ -5,62 +5,97 @@
 #  RAPTOR_LIBRARIES   - Link these to use Raptor
 #  RAPTOR_INCLUDE_DIR - Include directory for using Raptor
 #  RAPTOR_DEFINITIONS - Compiler switches required for using Raptor
+#
+#  Capabilities
+#       RAPTOR_HAVE_TRIG   - Set if raptor has TRIG
 
 # (c) 2007-2011 Sebastian Trueg <trueg at kde.org>
 # (c) 2011 Artem Serebriyskiy <v.for.vandal at gmail.com>
+# (c) 2011 Michael Jansen <kde at michael-jansen.biz>
 #
 # Based on FindFontconfig Copyright (c) 2006,2007 Laurent Montel, <montel at kde.org>
 #
 # Redistribution and use is allowed according to the terms of the BSD license.
 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
 
-include(FindLibraryWithDebug)
-include(MacroEnsureVersion)
 
-if (RAPTOR_INCLUDE_DIR AND RAPTOR_LIBRARIES)
+MACRO ( FIND_RAPTOR libname libhints includehints )
+    find_library_with_debug(
+        RAPTOR_LIBRARIES
+        WIN32_DEBUG_POSTFIX d
+        NAMES ${libname}
+        HINTS ${libhints})
+    find_path(
+        RAPTOR_INCLUDE_DIR raptor.h
+        HINTS ${includehints}
+        PATH_SUFFIXES ${libname})
+ENDMACRO ()
 
-  # in cache already
-  set(RAPTOR_FOUND TRUE)
 
-else (RAPTOR_INCLUDE_DIR AND RAPTOR_LIBRARIES)
 
+# Check if we have cached results in case the last round was successful.
+if ( NOT( RAPTOR_INCLUDE_DIR AND RAPTOR_LIBRARIES ) OR NOT RAPTOR_FOUND )
 
-  if (NOT WIN32)
+    include(FindLibraryWithDebug)
+    include(MacroEnsureVersion)
     find_package(PkgConfig)
-    pkg_check_modules(PC_RAPTOR QUIET raptor2)
-    set(RAPTOR_DEFINITIONS ${PC_RAPTOR_CFLAGS_OTHER})
-    set(RAPTOR_VERSION ${PC_RAPTOR_VERSION})
-  endif (NOT WIN32)
-
-
-  find_library_with_debug(RAPTOR_LIBRARIES
-                  WIN32_DEBUG_POSTFIX d
-                  NAMES raptor2 
-                  HINTS ${PC_RAPTOR_LIBDIR} ${PC_RAPTOR_LIBRARY_DIRS}
-                  )
-
-  find_path(RAPTOR_INCLUDE_DIR raptor.h
-            HINTS ${PC_RAPTOR_INCLUDEDIR} ${PC_RAPTOR_INCLUDE_DIRS}
-            PATH_SUFFIXES raptor2 )
-  
-  if (RAPTOR_VERSION)
-    MACRO_ENSURE_VERSION("1.4.16" ${RAPTOR_VERSION} RAPTOR_HAVE_TRIG)
-  endif (RAPTOR_VERSION)
-
-  if (RAPTOR_FOUND)
-    if (NOT Raptor_FIND_QUIETLY)
-      message(STATUS "Found Raptor ${RAPTOR_VERSION}: libs - ${RAPTOR_LIBRARIES}; includes - ${RAPTOR_INCLUDE_DIR}")
-    endif (NOT Raptor_FIND_QUIETLY)
-  else (RAPTOR_FOUND)
-    if (Raptor_FIND_REQUIRED)
-      message(FATAL_ERROR "Could NOT find Raptor")
-    endif (Raptor_FIND_REQUIRED)
-  endif (RAPTOR_FOUND)
-
-  include(FindPackageHandleStandardArgs)
-  find_package_handle_standard_args(RAPTOR  DEFAULT_MSG  RAPTOR_LIBRARIES RAPTOR_INCLUDE_DIR)
-
-  mark_as_advanced(RAPTOR_INCLUDE_DIR RAPTOR_LIBRARIES)
-
-endif (RAPTOR_INCLUDE_DIR AND RAPTOR_LIBRARIES)
+
+    # Vy default look for version 2.0
+    if (NOT Raptor_FIND_VERSION )
+        set( Raptor_FIND_VERSION "2.0")
+        set( Raptor_FIND_VERSION_MAJOR "2" )
+        set( Raptor_FIND_VERSION_MINOR "0" )
+    endif ()
+
+    if ( Raptor_FIND_VERSION_MAJOR EQUAL "2" )
+
+        if ( NOT WIN32 )
+            pkg_check_modules(PC_RAPTOR2 QUIET raptor2)
+            if ( PC_RAPTOR2_FOUND )
+                set(RAPTOR_DEFINITIONS ${PC_RAPTOR2_CFLAGS_OTHER})
+                set(RAPTOR_VERSION ${PC_RAPTOR2_VERSION} CACHE STRING "Raptor Version found" )
+            endif ()
+        endif ()
+        find_raptor( raptor2 "${PC_RAPTOR2_LIBDIR};${PC_RAPTOR2_LIBRARY_DIRS}" "${PC_RAPTOR2_INCLUDEDIR};${PC_RAPTOR2_INCLUDE_DIRS}")
+
+    elseif ( Raptor_FIND_VERSION_MAJOR EQUAL "1" )
+
+        if ( NOT WIN32 )
+            pkg_check_modules(PC_RAPTOR QUIET raptor)
+            if ( PC_RAPTOR_FOUND )
+                set(RAPTOR_DEFINITIONS ${PC_RAPTOR_CFLAGS_OTHER})
+                set(RAPTOR_VERSION ${PC_RAPTOR_VERSION} CACHE STRING "Raptor Version found" )
+            endif ()
+        endif ()
+        find_raptor( raptor "${PC_RAPTOR_LIBDIR};${PC_RAPTOR_LIBRARY_DIRS}" "${PC_RAPTOR_INCLUDEDIR};${PC_RAPTOR_INCLUDE_DIRS}")
+
+    else ()
+
+        message( FATAL_ERROR "No idea how to check for version : ${Raptor_FIND_VERSION}")
+
+    endif()
+
+    if (RAPTOR_VERSION)
+        MACRO_ENSURE_VERSION("1.4.16" ${RAPTOR_VERSION} RAPTOR_HAVE_TRIG)
+    endif (RAPTOR_VERSION)
+
+    mark_as_advanced(RAPTOR_INCLUDE_DIR RAPTOR_LIBRARIES)
+
+endif () # Check for cached values
+
+include(FindPackageHandleStandardArgs)
+
+find_package_handle_standard_args(
+    Raptor
+    VERSION_VAR   RAPTOR_VERSION
+    REQUIRED_VARS RAPTOR_LIBRARIES RAPTOR_INCLUDE_DIR)
+
+mark_as_advanced(RAPTOR_VERSION)
+
+if (NOT RAPTOR_FOUND AND Raptor_FIND_VERSION_MAJOR EQUAL "2" AND NOT Raptor_FIND_QUIET )
+    pkg_check_modules(PC_RAPTOR QUIET raptor)
+    if (PC_RAPTOR_FOUND)
+        message( STATUS "You have raptor1 version ${PC_RAPTOR_VERSION} installed. Please update." )
+    endif ()
+endif ()
 


More information about the Kde-buildsystem mailing list