From 0a378c54f952e12d4745903e97c8aa4ecd068178 Mon Sep 17 00:00:00 2001 From: Christopher Burr Date: Mon, 4 Mar 2019 09:26:47 +0000 Subject: [PATCH] Simplify finding ROOT with CMake --- CMakeLists.txt | 41 ++--------- FindROOT.cmake | 185 ------------------------------------------------- 2 files changed, 6 insertions(+), 220 deletions(-) delete mode 100644 FindROOT.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 98d94ae..c531540 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,6 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g3 -O2") # setting linker flags - IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,-dead_strip_dylibs") SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,-dead_strip_dylibs") @@ -48,41 +47,16 @@ ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") SET(STATIC_LIBRARY_FLAGS "-Wl,--as-needed") ENDIF() - -set (ROOT_FIND_COMPONENTS Core RIO RooFit RooFitCore RooStats Hist Tree Matrix Physics MathCore) - find_file(ROOT_CONFIG ROOTConfig.cmake HINTS $ENV{ROOTSYS} ${ROOTSYS} ${ROOT_DIR} NO_DEFAULT_PATH PATH_SUFFIXES cmake) -if (ROOT_CONFIG) - message(STATUS "ROOTConfig.cmake found and will be used: ${ROOT_CONFIG}") - include(${ROOT_CONFIG}) - message(STATUS "ROOT use file: ${ROOT_USE_FILE}") - include(${ROOT_USE_FILE}) - - if(ROOT_LIBRARIES AND ROOT_INCLUDE_DIRS) - set(ROOT_FOUND TRUE) - endif() - -else() - message(STATUS "ROOTConfig.cmake not found, trying to use FindROOT.cmake...") - find_package(ROOT) - INCLUDE_DIRECTORIES( ${ROOT_INCLUDE_DIR} ) - LINK_DIRECTORIES( ${ROOT_LIBRARY_DIR} ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ROOT_CXX_FLAGS}" ) -endif() - -message(STATUS "ROOT includes: ${ROOT_INCLUDE_DIR}") +find_package(ROOT CONFIG REQUIRED COMPONENTS Core RIO RooFit RooFitCore RooStats Hist Tree Matrix Physics MathCore) +include(${ROOT_USE_FILE}) +message(STATUS "ROOT includes: ${ROOT_INCLUDE_DIRS}") message(STATUS "ROOT libraries: ${ROOT_LIBRARIES}") message(STATUS "ROOT library directory: ${ROOT_LIBRARY_DIR}") -message(STATUS "ROOT_FOUND: ${ROOT_FOUND}") - -if(ROOT_FOUND) - include_directories(${ROOT_INCLUDE_DIRS}) -else() - message(ERROR "ROOT needed for RapidSim not found") -endif() +include_directories(${ROOT_INCLUDE_DIRS}) if(DEFINED ENV{EVTGEN_ROOT}) - message(STATUS "EVTGEN_ROOT is set: ${EVTGEN_ROOT}") - message(STATUS "Will attempt to link against EvtGen") + message(STATUS "EVTGEN_ROOT is set: ${EVTGEN_ROOT}") + message(STATUS "Will attempt to link against EvtGen") find_library(EVTGEN EvtGen PATHS "$ENV{EVTGEN_ROOT}/lib") find_library(EVTGENEXT EvtGenExternal PATHS "$ENV{EVTGEN_ROOT}/lib") if(NOT EVTGEN) @@ -112,6 +86,3 @@ install(DIRECTORY validation DESTINATION ${RAPIDSIM_ROOT} ) install(DIRECTORY rootfiles DESTINATION ${RAPIDSIM_ROOT} ) install(DIRECTORY utils DESTINATION ${RAPIDSIM_ROOT} ) install(DIRECTORY config DESTINATION ${RAPIDSIM_ROOT} ) - - - diff --git a/FindROOT.cmake b/FindROOT.cmake deleted file mode 100644 index ea5021f..0000000 --- a/FindROOT.cmake +++ /dev/null @@ -1,185 +0,0 @@ -# - Finds ROOT instalation -# This module sets up ROOT information -# It defines: -# ROOT_FOUND If the ROOT is found -# ROOT_INCLUDE_DIR PATH to the include directory -# ROOT_INCLUDE_DIRS PATH to the include directories (not cached) -# ROOT_LIBRARIES Most common libraries -# ROOT__LIBRARY Full path to the library -# ROOT_LIBRARY_DIR PATH to the library directory -# ROOT_DEFINITIONS Compiler definitions -# ROOT_CXX_FLAGS Compiler flags to used by client packages -# ROOT_C_FLAGS Compiler flags to used by client packages -# -# Updated by K. Smith (ksmith37@nd.edu) to properly handle -# dependencies in ROOT_GENERATE_DICTIONARY - -find_program(ROOT_CONFIG_EXECUTABLE root-config - HINTS $ENV{ROOTSYS}/bin ${ROOTSYS}/bin NO_DEFAULT_PATH) - -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) -set(ROOT_INCLUDE_DIRS ${ROOT_INCLUDE_DIR}) - -execute_process( - COMMAND ${ROOT_CONFIG_EXECUTABLE} --libdir - OUTPUT_VARIABLE ROOT_LIBRARY_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE) -set(ROOT_LIBRARY_DIRS ${ROOT_LIBRARY_DIR}) - -set(rootlibs Core Cint RIO Net Hist Graf Graf3d Gpad Tree Rint Postscript Matrix Physics MathCore Thread) -set(ROOT_LIBRARIES) -foreach(_cpt ${rootlibs} ${ROOT_FIND_COMPONENTS}) - find_library(ROOT_${_cpt}_LIBRARY ${_cpt} HINTS ${ROOT_LIBRARY_DIR}) - if(ROOT_${_cpt}_LIBRARY) - mark_as_advanced(ROOT_${_cpt}_LIBRARY) - list(APPEND ROOT_LIBRARIES ${ROOT_${_cpt}_LIBRARY}) - list(REMOVE_ITEM ROOT_FIND_COMPONENTS ${_cpt}) - endif() -endforeach() -list(REMOVE_DUPLICATES ROOT_LIBRARIES) - -execute_process( - COMMAND ${ROOT_CONFIG_EXECUTABLE} --cflags - OUTPUT_VARIABLE __cflags - OUTPUT_STRIP_TRAILING_WHITESPACE) -string(REGEX MATCHALL "-(D|U)[^ ]*" ROOT_DEFINITIONS "${__cflags}") -string(REGEX REPLACE "(^|[ ]*)-I[^ ]*" "" ROOT_CXX_FLAGS "${__cflags}") -string(REGEX REPLACE "(^|[ ]*)-I[^ ]*" "" ROOT_C_FLAGS "${__cflags}") - -set(ROOT_USE_FILE ${CMAKE_CURRENT_LIST_DIR}/RootUseFile.cmake) - -execute_process( - COMMAND ${ROOT_CONFIG_EXECUTABLE} --features - OUTPUT_VARIABLE _root_options - OUTPUT_STRIP_TRAILING_WHITESPACE) -separate_arguments(_root_options) -foreach(_opt ${_root_options}) - set(ROOT_${_opt}_FOUND TRUE) -endforeach() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(ROOT DEFAULT_MSG ROOT_CONFIG_EXECUTABLE - ROOTSYS ROOT_VERSION ROOT_INCLUDE_DIR ROOT_LIBRARIES ROOT_LIBRARY_DIR) - -mark_as_advanced(ROOT_CONFIG_EXECUTABLE) - -include(CMakeParseArguments) -find_program(ROOTCINT_EXECUTABLE rootcint HINTS $ENV{ROOTSYS}/bin) -find_program(GENREFLEX_EXECUTABLE genreflex HINTS $ENV{ROOTSYS}/bin) -find_package(GCCXML) - -#---------------------------------------------------------------------------- -# function ROOT_GENERATE_DICTIONARY( dictionary -# header1 header2 ... -# LINKDEF linkdef1 ... -# OPTIONS opt1...) -function(ROOT_GENERATE_DICTIONARY dictionary) - CMAKE_PARSE_ARGUMENTS(ARG "" "" "LINKDEF;OPTIONS" "" ${ARGN}) - #---Get the list of include directories------------------ - get_directory_property(incdirs INCLUDE_DIRECTORIES) - set(includedirs) - foreach( d ${incdirs}) - set(includedirs ${includedirs} -I${d}) - endforeach() - #---Get the list of header files------------------------- - set(headerfiles) - foreach(fp ${ARG_UNPARSED_ARGUMENTS}) - if(${fp} MATCHES "[*?]") # Is this header a globbing expression? - file(GLOB files ${fp}) - foreach(f ${files}) - if(NOT f MATCHES LinkDef) # skip LinkDefs from globbing result - set(headerfiles ${headerfiles} ${f}) - endif() - endforeach() - else() - find_file(headerFile ${fp} HINTS ${incdirs}) - set(headerfiles ${headerfiles} ${headerFile}) - unset(headerFile CACHE) - endif() - endforeach() - #---Get LinkDef.h file------------------------------------ - set(linkdefs) - foreach( f ${ARG_LINKDEF}) - find_file(linkFile ${f} HINTS ${incdirs}) - set(linkdefs ${linkdefs} ${linkFile}) - unset(linkFile CACHE) - endforeach() - #---call rootcint------------------------------------------ - add_custom_command(OUTPUT ${dictionary}.cxx - COMMAND ${ROOTCINT_EXECUTABLE} -cint -f ${dictionary}.cxx - -c ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs} - DEPENDS ${headerfiles} ${linkdefs} VERBATIM) -endfunction() - -#---------------------------------------------------------------------------- -# function REFLEX_GENERATE_DICTIONARY(dictionary -# header1 header2 ... -# SELECTION selectionfile ... -# OPTIONS opt1...) -function(REFLEX_GENERATE_DICTIONARY dictionary) - CMAKE_PARSE_ARGUMENTS(ARG "" "" "SELECTION;OPTIONS" "" ${ARGN}) - #---Get the list of header files------------------------- - set(headerfiles) - foreach(fp ${ARG_UNPARSED_ARGUMENTS}) - file(GLOB files ${fp}) - if(files) - foreach(f ${files}) - set(headerfiles ${headerfiles} ${f}) - endforeach() - else() - set(headerfiles ${headerfiles} ${fp}) - endif() - endforeach() - #---Get Selection file------------------------------------ - if(IS_ABSOLUTE ${ARG_SELECTION}) - set(selectionfile ${ARG_SELECTION}) - else() - set(selectionfile ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SELECTION}) - endif() - #---Get the list of include directories------------------ - get_directory_property(incdirs INCLUDE_DIRECTORIES) - set(includedirs) - foreach( d ${incdirs}) - set(includedirs ${includedirs} -I${d}) - endforeach() - #---Get preprocessor definitions-------------------------- - get_directory_property(defs COMPILE_DEFINITIONS) - foreach( d ${defs}) - set(definitions ${definitions} -D${d}) - endforeach() - #---Nanes and others--------------------------------------- - set(gensrcdict ${dictionary}.cpp) - if(MSVC) - set(gccxmlopts "--gccxmlopt=\"--gccxml-compiler cl\"") - else() - #set(gccxmlopts "--gccxmlopt=\'--gccxml-cxxflags -m64 \'") - set(gccxmlopts) - endif() - #set(rootmapname ${dictionary}Dict.rootmap) - #set(rootmapopts --rootmap=${rootmapname} --rootmap-lib=${libprefix}${dictionary}Dict) - #---Check GCCXML and get path----------------------------- - if(GCCXML) - get_filename_component(gccxmlpath ${GCCXML} PATH) - else() - message(WARNING "GCCXML not found. Install and setup your environment to find 'gccxml' executable") - endif() - #---Actual command---------------------------------------- - add_custom_command(OUTPUT ${gensrcdict} ${rootmapname} - COMMAND ${GENREFLEX_EXECUTABLE} ${headerfiles} -o ${gensrcdict} ${gccxmlopts} ${rootmapopts} --select=${selectionfile} - --gccxmlpath=${gccxmlpath} ${ARG_OPTIONS} ${includedirs} ${definitions} - DEPENDS ${headerfiles} ${selectionfile}) -endfunction() -