PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/cmake/modules/FindROOT.cmake

https://gitlab.com/q-quark/EduKit
CMake | 185 lines | 131 code | 15 blank | 39 comment | 7 complexity | 96dbbec342fe55238b879b0aecd7b925 MD5 | raw file
  1. # - Finds ROOT instalation
  2. # This module sets up ROOT information
  3. # It defines:
  4. # ROOT_FOUND If the ROOT is found
  5. # ROOT_INCLUDE_DIR PATH to the include directory
  6. # ROOT_INCLUDE_DIRS PATH to the include directories (not cached)
  7. # ROOT_LIBRARIES Most common libraries
  8. # ROOT_<name>_LIBRARY Full path to the library <name>
  9. # ROOT_LIBRARY_DIR PATH to the library directory
  10. # ROOT_DEFINITIONS Compiler definitions
  11. # ROOT_CXX_FLAGS Compiler flags to used by client packages
  12. # ROOT_C_FLAGS Compiler flags to used by client packages
  13. #
  14. # Updated by K. Smith (ksmith37@nd.edu) to properly handle
  15. # dependencies in ROOT_GENERATE_DICTIONARY
  16. find_program(ROOT_CONFIG_EXECUTABLE root-config
  17. HINTS $ENV{ROOTSYS}/bin)
  18. execute_process(
  19. COMMAND ${ROOT_CONFIG_EXECUTABLE} --prefix
  20. OUTPUT_VARIABLE ROOTSYS
  21. OUTPUT_STRIP_TRAILING_WHITESPACE)
  22. execute_process(
  23. COMMAND ${ROOT_CONFIG_EXECUTABLE} --version
  24. OUTPUT_VARIABLE ROOT_VERSION
  25. OUTPUT_STRIP_TRAILING_WHITESPACE)
  26. execute_process(
  27. COMMAND ${ROOT_CONFIG_EXECUTABLE} --incdir
  28. OUTPUT_VARIABLE ROOT_INCLUDE_DIR
  29. OUTPUT_STRIP_TRAILING_WHITESPACE)
  30. set(ROOT_INCLUDE_DIRS ${ROOT_INCLUDE_DIR})
  31. execute_process(
  32. COMMAND ${ROOT_CONFIG_EXECUTABLE} --libdir
  33. OUTPUT_VARIABLE ROOT_LIBRARY_DIR
  34. OUTPUT_STRIP_TRAILING_WHITESPACE)
  35. set(ROOT_LIBRARY_DIRS ${ROOT_LIBRARY_DIR})
  36. set(rootlibs Core Cint RIO Net Hist Graf Graf3d Gpad Tree Rint Postscript Matrix Physics MathCore Thread)
  37. set(ROOT_LIBRARIES)
  38. foreach(_cpt ${rootlibs} ${ROOT_FIND_COMPONENTS})
  39. find_library(ROOT_${_cpt}_LIBRARY ${_cpt} HINTS ${ROOT_LIBRARY_DIR})
  40. if(ROOT_${_cpt}_LIBRARY)
  41. mark_as_advanced(ROOT_${_cpt}_LIBRARY)
  42. list(APPEND ROOT_LIBRARIES ${ROOT_${_cpt}_LIBRARY})
  43. list(REMOVE_ITEM ROOT_FIND_COMPONENTS ${_cpt})
  44. endif()
  45. endforeach()
  46. list(REMOVE_DUPLICATES ROOT_LIBRARIES)
  47. execute_process(
  48. COMMAND ${ROOT_CONFIG_EXECUTABLE} --cflags
  49. OUTPUT_VARIABLE __cflags
  50. OUTPUT_STRIP_TRAILING_WHITESPACE)
  51. string(REGEX MATCHALL "-(D|U)[^ ]*" ROOT_DEFINITIONS "${__cflags}")
  52. string(REGEX REPLACE "(^|[ ]*)-I[^ ]*" "" ROOT_CXX_FLAGS "${__cflags}")
  53. string(REGEX REPLACE "(^|[ ]*)-I[^ ]*" "" ROOT_C_FLAGS "${__cflags}")
  54. set(ROOT_USE_FILE ${CMAKE_CURRENT_LIST_DIR}/RootUseFile.cmake)
  55. execute_process(
  56. COMMAND ${ROOT_CONFIG_EXECUTABLE} --features
  57. OUTPUT_VARIABLE _root_options
  58. OUTPUT_STRIP_TRAILING_WHITESPACE)
  59. separate_arguments(_root_options)
  60. foreach(_opt ${_root_options})
  61. set(ROOT_${_opt}_FOUND TRUE)
  62. endforeach()
  63. include(FindPackageHandleStandardArgs)
  64. find_package_handle_standard_args(ROOT DEFAULT_MSG ROOT_CONFIG_EXECUTABLE
  65. ROOTSYS ROOT_VERSION ROOT_INCLUDE_DIR ROOT_LIBRARIES ROOT_LIBRARY_DIR)
  66. mark_as_advanced(ROOT_CONFIG_EXECUTABLE)
  67. include(CMakeParseArguments)
  68. find_program(ROOTCINT_EXECUTABLE rootcint HINTS $ENV{ROOTSYS}/bin)
  69. find_program(GENREFLEX_EXECUTABLE genreflex HINTS $ENV{ROOTSYS}/bin)
  70. find_package(GCCXML)
  71. #----------------------------------------------------------------------------
  72. # function ROOT_GENERATE_DICTIONARY( dictionary
  73. # header1 header2 ...
  74. # LINKDEF linkdef1 ...
  75. # OPTIONS opt1...)
  76. function(ROOT_GENERATE_DICTIONARY dictionary)
  77. CMAKE_PARSE_ARGUMENTS(ARG "" "" "LINKDEF;OPTIONS" "" ${ARGN})
  78. #---Get the list of include directories------------------
  79. get_directory_property(incdirs INCLUDE_DIRECTORIES)
  80. set(includedirs)
  81. foreach( d ${incdirs})
  82. set(includedirs ${includedirs} -I${d})
  83. endforeach()
  84. #---Get the list of header files-------------------------
  85. set(headerfiles)
  86. foreach(fp ${ARG_UNPARSED_ARGUMENTS})
  87. if(${fp} MATCHES "[*?]") # Is this header a globbing expression?
  88. file(GLOB files ${fp})
  89. foreach(f ${files})
  90. if(NOT f MATCHES LinkDef) # skip LinkDefs from globbing result
  91. set(headerfiles ${headerfiles} ${f})
  92. endif()
  93. endforeach()
  94. else()
  95. find_file(headerFile ${fp} HINTS ${incdirs})
  96. set(headerfiles ${headerfiles} ${headerFile})
  97. unset(headerFile CACHE)
  98. endif()
  99. endforeach()
  100. #---Get LinkDef.h file------------------------------------
  101. set(linkdefs)
  102. foreach( f ${ARG_LINKDEF})
  103. find_file(linkFile ${f} HINTS ${incdirs})
  104. set(linkdefs ${linkdefs} ${linkFile})
  105. unset(linkFile CACHE)
  106. endforeach()
  107. #---call rootcint------------------------------------------
  108. add_custom_command(OUTPUT ${dictionary}.cxx
  109. COMMAND ${ROOTCINT_EXECUTABLE} -cint -f ${dictionary}.cxx
  110. -c ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs}
  111. DEPENDS ${headerfiles} ${linkdefs} VERBATIM)
  112. endfunction()
  113. #----------------------------------------------------------------------------
  114. # function REFLEX_GENERATE_DICTIONARY(dictionary
  115. # header1 header2 ...
  116. # SELECTION selectionfile ...
  117. # OPTIONS opt1...)
  118. function(REFLEX_GENERATE_DICTIONARY dictionary)
  119. CMAKE_PARSE_ARGUMENTS(ARG "" "" "SELECTION;OPTIONS" "" ${ARGN})
  120. #---Get the list of header files-------------------------
  121. set(headerfiles)
  122. foreach(fp ${ARG_UNPARSED_ARGUMENTS})
  123. file(GLOB files ${fp})
  124. if(files)
  125. foreach(f ${files})
  126. set(headerfiles ${headerfiles} ${f})
  127. endforeach()
  128. else()
  129. set(headerfiles ${headerfiles} ${fp})
  130. endif()
  131. endforeach()
  132. #---Get Selection file------------------------------------
  133. if(IS_ABSOLUTE ${ARG_SELECTION})
  134. set(selectionfile ${ARG_SELECTION})
  135. else()
  136. set(selectionfile ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SELECTION})
  137. endif()
  138. #---Get the list of include directories------------------
  139. get_directory_property(incdirs INCLUDE_DIRECTORIES)
  140. set(includedirs)
  141. foreach( d ${incdirs})
  142. set(includedirs ${includedirs} -I${d})
  143. endforeach()
  144. #---Get preprocessor definitions--------------------------
  145. get_directory_property(defs COMPILE_DEFINITIONS)
  146. foreach( d ${defs})
  147. set(definitions ${definitions} -D${d})
  148. endforeach()
  149. #---Nanes and others---------------------------------------
  150. set(gensrcdict ${dictionary}.cpp)
  151. if(MSVC)
  152. set(gccxmlopts "--gccxmlopt=\"--gccxml-compiler cl\"")
  153. else()
  154. #set(gccxmlopts "--gccxmlopt=\'--gccxml-cxxflags -m64 \'")
  155. set(gccxmlopts)
  156. endif()
  157. #set(rootmapname ${dictionary}Dict.rootmap)
  158. #set(rootmapopts --rootmap=${rootmapname} --rootmap-lib=${libprefix}${dictionary}Dict)
  159. #---Check GCCXML and get path-----------------------------
  160. if(GCCXML)
  161. get_filename_component(gccxmlpath ${GCCXML} PATH)
  162. else()
  163. message(WARNING "GCCXML not found. Install and setup your environment to find 'gccxml' executable")
  164. endif()
  165. #---Actual command----------------------------------------
  166. add_custom_command(OUTPUT ${gensrcdict} ${rootmapname}
  167. COMMAND ${GENREFLEX_EXECUTABLE} ${headerfiles} -o ${gensrcdict} ${gccxmlopts} ${rootmapopts} --select=${selectionfile}
  168. --gccxmlpath=${gccxmlpath} ${ARG_OPTIONS} ${includedirs} ${definitions}
  169. DEPENDS ${headerfiles} ${selectionfile})
  170. endfunction()