Skip to content
Snippets Groups Projects
FindROOT.cmake 5.39 KiB
Newer Older
Pere Mato's avatar
Pere Mato committed
# - Finds ROOT instalation
# This module sets up ROOT information 
# It defines:
# ROOT_FOUND          If the ROOT is found
# ROOT_ROOT           the root directory ($ROOTSYS)
Pere Mato's avatar
Pere Mato committed
# ROOT_INCLUDE_DIR    PATH to the include directory
# ROOT_LIBRARIES      Most common libraries
# ROOT_LIBRARY_DIR    PATH to the library directory 


find_program(ROOT_CONFIG_EXECUTABLE root-config
  HINTS ${ROOTSYS}/bin $ENV{ROOTSYS}/bin)
Pere Mato's avatar
Pere Mato committed

Pere Mato's avatar
Pere Mato committed
  execute_process(
    COMMAND ${ROOT_CONFIG_EXECUTABLE} --prefix 
    OUTPUT_VARIABLE ROOTSYS 
    OUTPUT_STRIP_TRAILING_WHITESPACE)

  execute_process(
    COMMAND ${ROOT_CONFIG_EXECUTABLE} --version 
    OUTPUT_VARIABLE ROOT_VERSION
    OUTPUT_STRIP_TRAILING_WHITESPACE)

  execute_process(
    COMMAND ${ROOT_CONFIG_EXECUTABLE} --incdir
    OUTPUT_VARIABLE ROOT_INCLUDE_DIR
    OUTPUT_STRIP_TRAILING_WHITESPACE)

  execute_process(
    COMMAND ${ROOT_CONFIG_EXECUTABLE} --libs
    OUTPUT_VARIABLE ROOT_LIBRARIES
    OUTPUT_STRIP_TRAILING_WHITESPACE)

  execute_process(
    COMMAND ${ROOT_CONFIG_EXECUTABLE} --evelibs
    OUTPUT_VARIABLE ROOT_EVE_LIBRARIES
    OUTPUT_STRIP_TRAILING_WHITESPACE)

Pere Mato's avatar
Pere Mato committed
  set(ROOT_LIBRARY_DIR ${ROOTSYS}/lib)
  set(ROOT_VERSION     ${ROOT_VERSION})
  set(ROOT_ROOT        ${ROOTSYS})
Pere Mato's avatar
Pere Mato committed
  # Make variables changeble to the advanced user
  mark_as_advanced(ROOT_CONFIG_EXECUTABLE)
endif()

###set(ROOT_LIBRARIES    ${ROOT_LIBRARIES} -lGenVector)     
set(ROOT_EVE_LIBRARIES ${ROOT_EVE_LIBRARIES} )
# handle the QUIETLY and REQUIRED arguments and set ROOT_FOUND to TRUE if
# all listed variables are TRUE
Markus Frank's avatar
Markus Frank committed
include ( FindPackageHandleStandardArgs )
find_package_handle_standard_args(ROOT DEFAULT_MSG ROOTSYS ROOT_INCLUDE_DIR)
mark_as_advanced(ROOT_FOUND ROOT_INCLUDE_DIR)
Pere Mato's avatar
Pere Mato committed

include ( CMakeParseArguments)
Markus Frank's avatar
Markus Frank committed
find_program(ROOTCINT_EXECUTABLE rootcint PATHS ${ROOTSYS}/bin $ENV{ROOTSYS}/bin)
Pere Mato's avatar
Pere Mato committed

if(NOT ROOT_VERSION_STRING)
  file(STRINGS ${ROOT_INCLUDE_DIR}/RVersion.h _RVersion REGEX "define *ROOT_RELEASE ")
  string(REGEX MATCH "\"(([0-9]+)\\.([0-9]+)/([0-9]+)([a-z]*|-rc[0-9]+))\"" _RVersion ${_RVersion})
  set(ROOT_VERSION_STRING ${CMAKE_MATCH_1} CACHE INTERNAL "Version of ROOT")
  set(ROOT_VERSION_MAJOR  ${CMAKE_MATCH_2} CACHE INTERNAL "Major version of ROOT")
  set(ROOT_VERSION_MINOR  ${CMAKE_MATCH_3} CACHE INTERNAL "Minor version of ROOT")
  set(ROOT_VERSION_PATCH  ${CMAKE_MATCH_4} CACHE INTERNAL "Patch version of ROOT")
endif()
##message(WARNING "ROOT ${ROOT_VERSION_MAJOR} ${ROOT_VERSION_MINOR} ${ROOT_VERSION_PATCH}")
Markus Frank's avatar
Markus Frank committed
if ( ${ROOT_VERSION_MAJOR} LESS 6 )
  set ( ROOT_LIBRARIES ${ROOT_LIBRARIES} -lReflex )
else()
  find_program(ROOTCLING_EXECUTABLE rootcling PATHS ${ROOTSYS}/bin $ENV{ROOTSYS}/bin)
  #string(FIND "${CMAKE_CXX_FLAGS}" "-std=c++11" dd4hep_use_cxx11 )
  #string(FIND "${CMAKE_CXX_FLAGS}" "-std=c++14" dd4hep_use_cxx14 )
  #if ( ${dd4hep_use_cxx11} LESS 0 AND ${dd4hep_use_cxx14} LESS 0 )
  #  message ( STATUS "*** FindROOT: ROOT version 6 --> Adding C++11 compile flag...")
  #  set ( CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}" )
  #endif()
Markus Frank's avatar
Markus Frank committed
endif()
Markus Frank's avatar
Markus Frank committed
if(ROOT_FIND_COMPONENTS)
  message( STATUS "ROOT[${ROOT_VERSION_STRING}]: Looking for Components: ${ROOT_FIND_COMPONENTS}" )
  foreach(comp ${ROOT_FIND_COMPONENTS})
    if ( "${comp}" STREQUAL "TEve" )
      set(ROOT_LIBRARIES ${ROOT_LIBRARIES} ${ROOT_EVE_LIBRARIES} FTGL GLEW)
    else()
      set(ROOT_LIBRARIES ${ROOT_LIBRARIES} -l${comp} )
    endif()
Markus Frank's avatar
Markus Frank committed
  endforeach()
endif()
Pere Mato's avatar
Pere Mato committed
#----------------------------------------------------------------------------
# function root_generate_dictionary( dictionary   
Pere Mato's avatar
Pere Mato committed
#                                    header1 header2 ... 
#                                    LINKDEF linkdef1 ... 
#                                    OPTIONS opt1...)
function(root_generate_dictionary dictionary)
Pere Mato's avatar
Pere Mato committed
  CMAKE_PARSE_ARGUMENTS(ARG "" "" "LINKDEF;OPTIONS" "" ${ARGN})
  #---Get the list of header files-------------------------
  set(headerfiles)
  foreach(fp ${ARG_UNPARSED_ARGUMENTS})
    file(GLOB files ${fp})
    if(files)
      foreach(f ${files})
        if(NOT f MATCHES LinkDef)
          set(headerfiles ${headerfiles} ${f})
        endif()
      endforeach()
    else()
      set(headerfiles ${headerfiles} ${fp})
    endif()
  endforeach()
  #---Get the list of include directories------------------
  get_directory_property(incdirs INCLUDE_DIRECTORIES)
  set(includedirs) 
  foreach( d ${incdirs})    
   set(includedirs ${includedirs} -I${d})
  endforeach()
  #---Get LinkDef.h file------------------------------------
  set(linkdefs)
  foreach( f ${ARG_LINKDEF})
    if( IS_ABSOLUTE ${f})
      set(linkdefs ${linkdefs} ${f})
    else() 
      if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/inc/${f})
        set(linkdefs ${linkdefs} ${CMAKE_CURRENT_SOURCE_DIR}/inc/${f})
      else()
        set(linkdefs ${linkdefs} ${CMAKE_CURRENT_SOURCE_DIR}/${f})
      endif()
    endif()
  endforeach()
  #---call rootcint------------------------------------------
  message(STATUS "ROOT Dictionary output: ${dictionary}.cxx ${dictionary}.h")
Pere Mato's avatar
Pere Mato committed
  add_custom_command(OUTPUT ${dictionary}.cxx ${dictionary}.h
Markus Frank's avatar
Markus Frank committed
                     COMMAND echo ${ROOTCINT_EXECUTABLE} -cint -f  ${dictionary}.cxx 
                                          -c -p ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs}
Markus Frank's avatar
Markus Frank committed
                     COMMAND ${ROOTCINT_EXECUTABLE} -f  ${dictionary}.cxx 
                                          -c -p ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs}
Pere Mato's avatar
Pere Mato committed
                     DEPENDS ${headerfiles} ${linkdefs})
endfunction()
Markus Frank's avatar
Markus Frank committed