FindROOT.cmake 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. # - Find ROOT instalation
  2. # This module tries to find the ROOT installation on your system.
  3. # It tries to find the root-config script which gives you all the needed information.
  4. # If the system variable ROOTSYS is set this is straight forward.
  5. # If not the module uses the pathes given in ROOT_CONFIG_SEARCHPATH.
  6. # If you need an other path you should add this path to this varaible.
  7. # The root-config script is then used to detect basically everything else.
  8. # This module defines a number of key variables and macros.
  9. # F.Uhlig@gsi.de (fairroot.gsi.de)
  10. SET(ROOT_CONFIG_SEARCHPATH
  11. ${SIMPATH}/tools/root/bin
  12. $ENV{ROOTSYS}/bin
  13. /usr/local/bin
  14. /opt/local/bin
  15. /root/bin
  16. )
  17. SET(ROOT_DEFINITIONS "")
  18. SET(ROOT_INSTALLED_VERSION_TOO_OLD FALSE)
  19. SET(ROOT_CONFIG_EXECUTABLE ROOT_CONFIG_EXECUTABLE-NOTFOUND)
  20. FIND_PROGRAM(ROOT_CONFIG_EXECUTABLE NAMES root-config PATHS
  21. ${ROOT_CONFIG_SEARCHPATH}
  22. NO_DEFAULT_PATH)
  23. IF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
  24. MESSAGE( FATAL_ERROR "ROOT not installed in the searchpath and ROOTSYS is not set. Please
  25. set ROOTSYS or add the path to your ROOT installation in the Macro FindROOT.cmake in the
  26. subdirectory cmake/modules.")
  27. ELSE (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
  28. STRING(REGEX REPLACE "(^.*)/bin/root-config" "\\1" test ${ROOT_CONFIG_EXECUTABLE})
  29. SET( ENV{ROOTSYS} ${test})
  30. set( ROOTSYS ${test})
  31. ENDIF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND")
  32. # root config is a bash script and not commonly executable under Windows
  33. # make some static assumptions instead
  34. IF (WIN32)
  35. SET(ROOT_FOUND FALSE)
  36. IF (ROOT_CONFIG_EXECUTABLE)
  37. SET(ROOT_FOUND TRUE)
  38. set(ROOT_INCLUDE_DIR ${ROOTSYS}/include)
  39. set(ROOT_LIBRARY_DIR ${ROOTSYS}/lib)
  40. SET(ROOT_BINARY_DIR ${ROOTSYS}/bin)
  41. set(ROOT_LIBRARIES -LIBPATH:${ROOT_LIBRARY_DIR} libGpad.lib libHist.lib libGraf.lib libGraf3d.lib libTree.lib libRint.lib libPostscript.lib libMatrix.lib libPhysics.lib libMathCore.lib libRIO.lib libNet.lib libThread.lib libCore.lib libCint.lib libMinuit.lib libGui.lib libSpectrum.lib)
  42. FIND_PROGRAM(ROOT_CINT_EXECUTABLE
  43. NAMES rootcint
  44. PATHS ${ROOT_BINARY_DIR}
  45. NO_DEFAULT_PATH
  46. )
  47. MESSAGE(STATUS "Found ROOT: $ENV{ROOTSYS}/bin/root (WIN32/version not identified)")
  48. ENDIF (ROOT_CONFIG_EXECUTABLE)
  49. ELSE(WIN32)
  50. IF (ROOT_CONFIG_EXECUTABLE)
  51. SET(ROOT_FOUND FALSE)
  52. EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE} ARGS "--version" OUTPUT_VARIABLE ROOTVERSION)
  53. MESSAGE(STATUS "Found ROOT: $ENV{ROOTSYS}/bin/root (found version ${ROOTVERSION})")
  54. # we need at least version 5.00/00
  55. IF (NOT ROOT_MIN_VERSION)
  56. SET(ROOT_MIN_VERSION "5.00/00")
  57. ENDIF (NOT ROOT_MIN_VERSION)
  58. # now parse the parts of the user given version string into variables
  59. STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+" "\\1" req_root_major_vers "${ROOT_MIN_VERSION}")
  60. STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" req_root_minor_vers "${ROOT_MIN_VERSION}")
  61. STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+)" "\\1" req_root_patch_vers "${ROOT_MIN_VERSION}")
  62. # and now the version string given by qmake
  63. STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1" found_root_major_vers "${ROOTVERSION}")
  64. STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" found_root_minor_vers "${ROOTVERSION}")
  65. STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1" found_root_patch_vers "${ROOTVERSION}")
  66. IF (found_root_major_vers LESS 5)
  67. MESSAGE( FATAL_ERROR "Invalid ROOT version \"${ROOTERSION}\", at least major version 4 is required, e.g. \"5.00/00\"")
  68. ENDIF (found_root_major_vers LESS 5)
  69. # compute an overall version number which can be compared at once
  70. MATH(EXPR req_vers "${req_root_major_vers}*10000 + ${req_root_minor_vers}*100 + ${req_root_patch_vers}")
  71. MATH(EXPR found_vers "${found_root_major_vers}*10000 + ${found_root_minor_vers}*100 + ${found_root_patch_vers}")
  72. IF (found_vers LESS req_vers)
  73. SET(ROOT_FOUND FALSE)
  74. SET(ROOT_INSTALLED_VERSION_TOO_OLD TRUE)
  75. ELSE (found_vers LESS req_vers)
  76. SET(ROOT_FOUND TRUE)
  77. ENDIF (found_vers LESS req_vers)
  78. ENDIF (ROOT_CONFIG_EXECUTABLE)
  79. IF (ROOT_FOUND)
  80. STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+" "\\1" ROOT_MAJOR_VER "${ROOTVERSION}")
  81. IF(ROOT_MAJOR_VER EQUAL 6)
  82. MESSAGE("-- ROOT 6 detected - requiring C++11")
  83. ADD_DEFINITIONS("-std=c++1z -DROOT_MAJOR_VER=6")
  84. ENDIF(ROOT_MAJOR_VER EQUAL 6)
  85. # ask root-config for the library dir
  86. # Set ROOT_LIBRARY_DIR
  87. EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
  88. ARGS "--libdir"
  89. OUTPUT_VARIABLE ROOT_LIBRARY_DIR_TMP )
  90. IF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
  91. SET(ROOT_LIBRARY_DIR ${ROOT_LIBRARY_DIR_TMP} )
  92. ELSE(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
  93. MESSAGE("Warning: ROOT_CONFIG_EXECUTABLE reported ${ROOT_LIBRARY_DIR_TMP} as library path,")
  94. MESSAGE("Warning: but ${ROOT_LIBRARY_DIR_TMP} does NOT exist, ROOT must NOT be installed correctly.")
  95. ENDIF(EXISTS "${ROOT_LIBRARY_DIR_TMP}")
  96. # ask root-config for the binary dir
  97. EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE}
  98. ARGS "--bindir"
  99. OUTPUT_VARIABLE root_bins )
  100. SET(ROOT_BINARY_DIR ${root_bins})
  101. # ask root-config for the include dir
  102. EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
  103. ARGS "--incdir"
  104. OUTPUT_VARIABLE root_headers )
  105. SET(ROOT_INCLUDE_DIR ${root_headers})
  106. # CACHE INTERNAL "")
  107. # ask root-config for the library varaibles
  108. EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE}
  109. # ARGS "--noldflags --noauxlibs --libs"
  110. ARGS "--glibs"
  111. OUTPUT_VARIABLE root_flags )
  112. # STRING(REGEX MATCHALL "([^ ])+" root_libs_all ${root_flags})
  113. # STRING(REGEX MATCHALL "-L([^ ])+" root_library ${root_flags})
  114. # REMOVE_FROM_LIST(root_flags "${root_libs_all}" "${root_library}")
  115. SET(ROOT_LIBRARIES "${root_flags} -lMinuit -lSpectrum -lTMVA")
  116. # Make variables changeble to the advanced user
  117. MARK_AS_ADVANCED( ROOT_LIBRARY_DIR ROOT_INCLUDE_DIR ROOT_DEFINITIONS)
  118. # Set ROOT_INCLUDES
  119. SET( ROOT_INCLUDES ${ROOT_INCLUDE_DIR})
  120. SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${ROOT_LIBRARY_DIR})
  121. #######################################
  122. #
  123. # Check the executables of ROOT
  124. # ( rootcint )
  125. #
  126. #######################################
  127. FIND_PROGRAM(ROOT_CINT_EXECUTABLE
  128. NAMES rootcint
  129. PATHS ${ROOT_BINARY_DIR}
  130. NO_DEFAULT_PATH
  131. )
  132. ENDIF (ROOT_FOUND)
  133. ENDIF(WIN32)
  134. ###########################################
  135. #
  136. # Macros for building ROOT dictionary
  137. #
  138. ###########################################
  139. MACRO (ROOT_GENERATE_DICTIONARY INFILES LINKDEF_FILE OUTFILE INCLUDE_DIRS_IN)
  140. set(INCLUDE_DIRS)
  141. foreach (_current_FILE ${INCLUDE_DIRS_IN})
  142. set(INCLUDE_DIRS ${INCLUDE_DIRS} -I${_current_FILE})
  143. endforeach (_current_FILE ${INCLUDE_DIRS_IN})
  144. if (CMAKE_SYSTEM_NAME MATCHES Linux)
  145. ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILE}
  146. COMMAND LD_LIBRARY_PATH=${ROOT_LIBRARY_DIR} ROOTSYS=${ROOTSYS} ${ROOT_CINT_EXECUTABLE}
  147. ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES} ${LINKDEF_FILE})
  148. else (CMAKE_SYSTEM_NAME MATCHES Linux)
  149. if (CMAKE_SYSTEM_NAME MATCHES Darwin)
  150. ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILE}
  151. COMMAND DYLD_LIBRARY_PATH=${ROOT_LIBRARY_DIR} ROOTSYS=${ROOTSYS} ${ROOT_CINT_EXECUTABLE}
  152. ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES} ${LINKDEF_FILE})
  153. endif (CMAKE_SYSTEM_NAME MATCHES Darwin)
  154. endif (CMAKE_SYSTEM_NAME MATCHES Linux)
  155. ENDMACRO (ROOT_GENERATE_DICTIONARY)
  156. MACRO (GENERATE_ROOT_TEST_SCRIPT SCRIPT_FULL_NAME)
  157. get_filename_component(path_name ${SCRIPT_FULL_NAME} PATH)
  158. get_filename_component(file_extension ${SCRIPT_FULL_NAME} EXT)
  159. get_filename_component(file_name ${SCRIPT_FULL_NAME} NAME_WE)
  160. set(shell_script_name "${file_name}.sh")
  161. #MESSAGE("PATH: ${path_name}")
  162. #MESSAGE("Ext: ${file_extension}")
  163. #MESSAGE("Name: ${file_name}")
  164. #MESSAGE("Shell Name: ${shell_script_name}")
  165. string(REPLACE ${PROJECT_SOURCE_DIR}
  166. ${PROJECT_BINARY_DIR} new_path ${path_name}
  167. )
  168. #MESSAGE("New PATH: ${new_path}")
  169. file(MAKE_DIRECTORY ${new_path}/data)
  170. CONVERT_LIST_TO_STRING(${LD_LIBRARY_PATH})
  171. set(MY_LD_LIBRARY_PATH ${output})
  172. set(my_script_name ${SCRIPT_FULL_NAME})
  173. if(CMAKE_SYSTEM MATCHES Darwin)
  174. configure_file(${PROJECT_SOURCE_DIR}/cmake/scripts/root_macro_macos.sh.in
  175. ${new_path}/${shell_script_name}
  176. )
  177. else(CMAKE_SYSTEM MATCHES Darwin)
  178. configure_file(${PROJECT_SOURCE_DIR}/cmake/scripts/root_macro.sh.in
  179. ${new_path}/${shell_script_name}
  180. )
  181. endif(CMAKE_SYSTEM MATCHES Darwin)
  182. EXEC_PROGRAM(/bin/chmod ARGS "u+x ${new_path}/${shell_script_name}")
  183. ENDMACRO (GENERATE_ROOT_TEST_SCRIPT)