Print

Print


Commit in lcio on MAIN
FindROOT.cmake+173-691.2 -> 1.3
updated to match FindROOT.cmake in CMakeModules

lcio
FindROOT.cmake 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- FindROOT.cmake	22 Jan 2010 14:44:12 -0000	1.2
+++ FindROOT.cmake	25 Jun 2010 09:50:02 -0000	1.3
@@ -1,14 +1,38 @@
-#####################################
+###############################################################################
 # cmake module for finding ROOT
 #
-# returns:
-#   ROOT_FOUND
-#   ROOT_INCLUDE_DIRS
-#   ROOT_LIBRARIES
-#   ROOT_DEFINITIONS
+# Following cmake variables are returned by this module:
+#
+#   ROOT_FOUND              # set to TRUE if ROOT was successfully found
+#   ROOT_INCLUDE_DIRS       # list of directories where ROOT headers live
+#   ROOT_LIBRARIES          # list of all ROOT libraries (including components)
+#   ROOT_DEFINITIONS        # definitions set by this module (-DUSE_ROOT ...)
+#   ROOT_${COMPONENT}_FOUND # for ROOT components, e.g. Minuit2 MathMore ...
+#   
+#
+#   Please note that by convention components should be entered exactly as
+#   the library names, i.e. the component name equivalent to the library
+#   $ROOTSYS/lib/libMathMore.so should be called MathMore and NOT:
+#       mathmore or Mathmore or MATHMORE
+#
+#   However to follow the usual cmake convention it is agreed that the
+#   ROOT_${COMPONENT}_FOUND variables are ALL uppercase, i.e. the MathMore
+#   component returns: ROOT_MATHMORE_FOUND and NOT ROOT_MathMore_FOUND
+#
+#
+# The additional ROOT components can be defined directly in the cmake commando:
+# FIND_PACKAGE( ROOT COMPONENTS MathMore Gdml Geo ...)
+#
+# Or in the variable ROOT_USE_COMPONENTS before calling find_package, i.e.:
+# SET( ROOT_USE_COMPONENTS MathMore Gdml Geo )
+# FIND_PACKAGE( ROOT )
+#
+# The Minuit2 component is always added for backwards compatibility.
 #
 # @author Jan Engels, DESY
-#####################################
+###############################################################################
+
+
 
 SET( ROOT_FOUND FALSE )
 MARK_AS_ADVANCED( ROOT_FOUND )
@@ -16,23 +40,34 @@
 # Threads library is needed for root
 #FIND_PACKAGE( Threads REQUIRED)
 
-# include dirs
-SET( ROOT_INCLUDE_DIR ROOT_INCLUDE_DIR-NOTFOUND )
-MARK_AS_ADVANCED( ROOT_INCLUDE_DIR )
+# set ROOTSYS for running root-config
+IF( DEFINED ROOT_HOME )
+    SET( ENV{ROOTSYS} "${ROOT_HOME}" )
+ENDIF()
 
-# set env ROOTSYS for running root-config
-SET( ENV{ROOTSYS} "${ROOT_HOME}" )
 
-# also try to get include dir from root-config
+
+
+# ==============================================
+# ===          ROOT_INCLUDE_DIR              ===
+# ==============================================
+
+# get include dir from root-config output
 EXEC_PROGRAM( "${ROOT_HOME}/bin/root-config" "${ROOT_HOME}/bin"
     ARGS --incdir
     OUTPUT_VARIABLE ROOT_INC_DIR
-    RETURN_VALUE incdir_ret )
-# if command fails clean up variable
-IF( incdir_ret )
+    RETURN_VALUE exit_code
+)
+IF( NOT exit_code EQUAL 0 )
+    # clear ROOT_INC_DIR if root-config exits with error
+    # it could have garbage output
     SET( ROOT_INC_DIR )
 ENDIF()
 
+
+SET( ROOT_INCLUDE_DIR ROOT_INCLUDE_DIR-NOTFOUND )
+MARK_AS_ADVANCED( ROOT_INCLUDE_DIR )
+
 FIND_PATH( ROOT_INCLUDE_DIR
     NAMES TH1.h
     PATHS ${ROOT_HOME}/include ${ROOT_INC_DIR}
@@ -43,68 +78,125 @@
             " -- failed to find ROOT include directory!!" )
 ENDIF()
 
-# libraries
-SET( ROOT_LIB_NAMES )
+
+
+
+# ==============================================
+# ===            ROOT_LIBRARIES              ===
+# ==============================================
+
+# check if this flag is set to FALSE at the end of
+# this module to make sure all libraries were found
 SET( ROOT_FINDLIB_FAILED FALSE )
-MARK_AS_ADVANCED( ROOT_LIB_NAMES ROOT_FINDLIB_FAILED )
+MARK_AS_ADVANCED( ROOT_FINDLIB_FAILED )
 
-# get lib names from 'root-config' output
+
+# get library dir from root-config output
 EXEC_PROGRAM( "${ROOT_HOME}/bin/root-config" "${ROOT_HOME}/bin"
-    ARGS --noauxlibs --libs  
-#    ARGS --noauxlibs --glibs
-    OUTPUT_VARIABLE out_tmp
-    RETURN_VALUE out_ret )
+    ARGS --libdir
+    OUTPUT_VARIABLE ROOT_LIB_DIR
+    RETURN_VALUE exit_code
+)
+IF( NOT exit_code EQUAL 0 )
+    # clear ROOT_LIB_DIR if root-config exits with error
+    # it could have garbage output
+    SET( ROOT_LIB_DIR )
+ENDIF()
+
+
+
+# ========== look for standard root libraries =================
 
-#SET( out_tmp  "-L/data/ilcsoft/root/trunk/lib -lCore -lCint -lRIO -lNet  -lHist  -lTree -lMathCore")
+# standard root libraries (without components)
+SET( ROOT_LIB_NAMES )
+SET( ROOT_LIBS )
+MARK_AS_ADVANCED( ROOT_LIB_NAMES ROOT_LIBS )
 
-# check if everything went ok
-IF( NOT out_ret )
+# get standard root libraries from 'root-config --libs' output
+EXEC_PROGRAM( "${ROOT_HOME}/bin/root-config" "${ROOT_HOME}/bin"
+    #ARGS --noauxlibs --glibs
+    ARGS --noauxlibs --libs
+    OUTPUT_VARIABLE cmd_output
+    RETURN_VALUE exit_code
+)
+IF( exit_code EQUAL 0 )
+    
     # create a list out of the output
-    SEPARATE_ARGUMENTS( out_tmp )
+    SEPARATE_ARGUMENTS( cmd_output )
+
     # remove first item -L compiler flag
-    LIST( REMOVE_AT out_tmp 0 )
-    # extract libnames from -l compiler flags
-    FOREACH( lib ${out_tmp} )
+    LIST( REMOVE_AT cmd_output 0 )
+
+    FOREACH( lib ${cmd_output} )
+
+        # extract libnames from -l compiler flags
         STRING( REGEX REPLACE "^-.(.*)$" "\\1" libname "${lib}")
+
+        # append all library names into a list
         LIST( APPEND ROOT_LIB_NAMES ${libname} )
-    ENDFOREACH()
 
-    # check for ROOT Minuit2
-    EXEC_PROGRAM( "${ROOT_HOME}/bin/root-config" "${ROOT_HOME}/bin"
-        ARGS --has-minuit2
-        OUTPUT_VARIABLE has_minuit
-        RETURN_VALUE has_minuit_ret )
-    IF( NOT has_minuit_ret )
-        # determine if Minuit2 is included with ROOT
-        IF( has_minuit STREQUAL "yes" )
-            LIST( APPEND ROOT_LIB_NAMES "Minuit2" )
+        SET( ROOT_LIB_${libname} ROOT_LIB_${libname}-NOTFOUND )
+        MARK_AS_ADVANCED( ROOT_LIB_${libname} )
+
+        FIND_LIBRARY( ROOT_LIB_${libname}
+            NAMES ${libname}
+            PATHS ${ROOT_HOME}/lib ${ROOT_LIB_DIR}
+            NO_DEFAULT_PATH
+        )
+
+        IF( NOT ROOT_LIB_${libname} )
+            SET( ROOT_FINDLIB_FAILED TRUE )
+            IF( NOT ROOT_FIND_QUIETLY )
+                MESSAGE( STATUS "Check for ROOT: ${ROOT_HOME}"
+                        " -- failed to find ROOT library: ${libname}" )
+            ENDIF()
+        ELSE()
+            LIST( APPEND ROOT_LIBS ${ROOT_LIB_${libname}} )
         ENDIF()
-    ENDIF()
+
+    ENDFOREACH()
 
     IF( NOT ROOT_FIND_QUIETLY )
         MESSAGE( STATUS "Check for ROOT: detected libraries: ${ROOT_LIB_NAMES}" )
     ENDIF()
+
 ELSE()
-    #IF( NOT ROOT_FIND_QUIETLY )
-    #    MESSAGE( STATUS "Error trying to execute root-config --noauxlibs --glibs!!" )
-    #    MESSAGE( STATUS "${out_tmp}" )
-    #ENDIF()
-    # ensure that detection fails
     SET( ROOT_FINDLIB_FAILED TRUE )
 ENDIF()
 
-# also try to get library dir from root-config
-EXEC_PROGRAM( "${ROOT_HOME}/bin/root-config" "${ROOT_HOME}/bin"
-    ARGS --libdir
-    OUTPUT_VARIABLE ROOT_LIB_DIR
-    RETURN_VALUE libdir_ret )
-# if command fails clean up variable
-IF( libdir_ret )
-    SET( ROOT_LIB_DIR )
+
+
+# ========== look for additional root components =================
+
+SET( ROOT_COMPONENT_LIBS )
+MARK_AS_ADVANCED( ROOT_COMPONENT_LIBS )
+
+# Minuit2 is always included (for backwards compatibility )
+LIST( APPEND ROOT_FIND_COMPONENTS Minuit2 )
+
+# append components defined in the variable ROOT_USE_COMPONENTS
+IF( DEFINED ROOT_USE_COMPONENTS )
+    LIST( APPEND ROOT_FIND_COMPONENTS ${ROOT_USE_COMPONENTS} )
+ENDIF()
+
+# REMOVE_DUPLICATES is only available in cmake versions >= 2.6
+# it is not a problem if a component is duplicated in the list, this is just done
+# for consistency and to display the message below without duplicate components
+IF( ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} EQUAL 2.6 OR
+    ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.6 )
+    IF( ROOT_FIND_COMPONENTS )
+        LIST(REMOVE_DUPLICATES ROOT_FIND_COMPONENTS)
+    ENDIF()
+ENDIF()
+
+IF( NOT ROOT_FIND_QUIETLY )
+    MESSAGE( STATUS "Check for ROOT: additional components: ${ROOT_FIND_COMPONENTS}" )
 ENDIF()
 
-# find libraries
-FOREACH( libname ${ROOT_LIB_NAMES} )
+FOREACH( libname ${ROOT_FIND_COMPONENTS} )
+
+    # name of the component in upper case
+    STRING( TOUPPER ${libname} upper_component_name)
 
     SET( ROOT_LIB_${libname} ROOT_LIB_${libname}-NOTFOUND )
     MARK_AS_ADVANCED( ROOT_LIB_${libname} )
@@ -112,32 +204,43 @@
     FIND_LIBRARY( ROOT_LIB_${libname}
         NAMES ${libname}
         PATHS ${ROOT_HOME}/lib ${ROOT_LIB_DIR}
-        NO_DEFAULT_PATH )
+        NO_DEFAULT_PATH
+    )
 
     IF( NOT ROOT_LIB_${libname} )
-        SET( ROOT_FINDLIB_FAILED TRUE )
+        #SET( ROOT_FINDLIB_FAILED TRUE )
         IF( NOT ROOT_FIND_QUIETLY )
             MESSAGE( STATUS "Check for ROOT: ${ROOT_HOME}"
-                    " -- failed to find ROOT ${libname} library!!" )
+                    " -- failed to find ROOT component: ${libname}" )
         ENDIF()
     ELSE()
-        LIST( APPEND ROOT_LIBS ${ROOT_LIB_${libname}} )
+        SET( ROOT_${upper_component}_FOUND TRUE )
+        LIST( APPEND ROOT_COMPONENT_LIBS ${ROOT_LIB_${libname}} )
     ENDIF()
 ENDFOREACH()
 
-FIND_LIBRARY( DL_LIB NAMES ${CMAKE_DL_LIBS} dl )
-IF( NOT DL_LIB AND NOT ROOT_FIND_QUIETLY )
-    MESSAGE( STATUS "Check for ROOT: failed to find libdl.so" )
-ELSE()
-    MESSAGE( STATUS "Check for ROOT: using dl library: ${DL_LIB}" )
-ENDIF()
+
+# ====== DL LIBRARY ==================================================
+# comment out this code due to cmake bug in 64 bit:
+# see: http://public.kitware.com/mantis/view.php?id=10813
+#
+#FIND_LIBRARY( DL_LIB NAMES ${CMAKE_DL_LIBS} dl )
+#IF( NOT DL_LIB AND NOT ROOT_FIND_QUIETLY )
+#    MESSAGE( STATUS "Check for ROOT: failed to find libdl.so" )
+#    SET( ROOT_FINDLIB_FAILED TRUE )
+#ELSE()
+#    MESSAGE( STATUS "Check for ROOT: using dl library: ${DL_LIB}" )
+#ENDIF()
+
+
 
 # set variables and display results
-IF( ROOT_INCLUDE_DIR AND NOT ROOT_FINDLIB_FAILED AND DL_LIB )
+IF( ROOT_INCLUDE_DIR AND NOT ROOT_FINDLIB_FAILED )
     SET( ROOT_FOUND TRUE )
     SET( ROOT_INCLUDE_DIRS ${ROOT_INCLUDE_DIR} )
     #SET( ROOT_LIBRARIES ${ROOT_LIBS} ${DL_LIB} ${CMAKE_THREAD_LIBS_INIT} )
-    SET( ROOT_LIBRARIES ${ROOT_LIBS} ${DL_LIB} )
+    #SET( ROOT_LIBRARIES ${ROOT_LIBS} ${ROOT_COMPONENT_LIBS} ${DL_LIB} )
+    SET( ROOT_LIBRARIES ${ROOT_LIBS} ${ROOT_COMPONENT_LIBS} )
     SET( ROOT_DEFINITIONS "-DUSEROOT -DUSE_ROOT -DMARLIN_USE_ROOT" )
     MARK_AS_ADVANCED( ROOT_LIBRARIES ROOT_DEFINITIONS )
     MESSAGE( STATUS "Check for ROOT: ${ROOT_HOME} -- works" )
@@ -149,3 +252,4 @@
         MESSAGE( STATUS "Check for ROOT -- failed!! skip this package..." )
     ENDIF()
 ENDIF()
+
CVSspam 0.2.8