Skip to content

Commit

Permalink
Merge pull request #136 from rest-for-physics/fixFindRoot
Browse files Browse the repository at this point in the history
Fix `FindROOT.cmake` in case `thisroot.sh` wasn't sourced
  • Loading branch information
jgalan authored Feb 15, 2022
2 parents 23065bb + b7bcef5 commit a415518
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions cmake/FindROOT.cmake
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
# - Finds ROOT instalation
# This module sets up ROOT information
# This module sets up ROOT information
# It defines:
# ROOT_FOUND If the ROOT is found
# ROOT_INCLUDE_DIR PATH to the include directory (deprecated)
# ROOT_INCLUDE_DIRS PATH to the include directory
# ROOT_LIBRARIES Most common libraries
# ROOT_LIBRARY_DIR PATH to the library directory
# ROOT_LIBRARY_DIR PATH to the library directory
# ROOT_BIN_DIR PATH to the excutables directory
# ROOT_PYTHONVER Compatible python version string

# First search for ROOTConfig.cmake on the path defined via user setting
# First search for ROOTConfig.cmake on the path defined via user setting
# ROOT_DIR

if (CMAKE_SYSTEM_NAME MATCHES "Windows")

if(DEFINED ENV{ROOTSYS})
set(ROOTSYS $ENV{ROOTSYS})
set(ROOTSYS $ENV{ROOTSYS})
else()
message(FATAL_ERROR "ROOTSYS environment variable is undefined. Did you forget to source the `thisroot.bat`?")
endif()

if(NOT ROOTSYS)
set(ROOT_FOUND FALSE)
set(ROOT_FOUND FALSE)
else()
set(ROOT_FOUND TRUE)

set(ROOT_LIBRARY_DIR ${ROOTSYS}/lib)
set(ROOT_INCLUDE_DIRS ${ROOTSYS}/include)
set(ROOT_BIN_DIR ${ROOTSYS}/bin)
set(ROOTCINT_EXECUTABLE ${ROOTSYS}/bin/rootcint.exe)
set(GENREFLEX_EXECUTABLE ${ROOTSYS}/bin/genreflex.exe)
set(GENREFLEX_EXECUTABLE ${ROOTSYS}/bin/genreflex.exe)

set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
set(ROOT_LIBRARIES)
foreach(_cpt Core Imt RIO Net Hist Gui Eve RGL Gdml Geom Graf Graf3d Gpad Tree TreePlayer Rint Postscript Matrix Physics MathCore Thread MultiProc Minuit)
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})
endif()
if(ROOT_${_cpt}_LIBRARY)
mark_as_advanced(ROOT_${_cpt}_LIBRARY)
list(APPEND ROOT_LIBRARIES ${ROOT_${_cpt}_LIBRARY})
endif()
endforeach()
if(ROOT_LIBRARIES)
list(REMOVE_DUPLICATES ROOT_LIBRARIES)
Expand All @@ -51,26 +53,21 @@ else()

if(NOT ROOT_CONFIG_EXECUTABLE)
set(ROOT_FOUND FALSE)
else()
else()
set(ROOT_FOUND TRUE)


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

execute_process(
COMMAND ${ROOT_CONFIG_EXECUTABLE} --libdir
execute_process(
COMMAND ${ROOT_CONFIG_EXECUTABLE} --libdir
OUTPUT_VARIABLE ROOT_LIBRARY_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)


set(ROOTCINT_EXECUTABLE $ENV{ROOTSYS}/bin/rootcint)
set(GENREFLEX_EXECUTABLE $ENV{ROOTSYS}/bin/genreflex)

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

Expand All @@ -84,15 +81,18 @@ else()
OUTPUT_VARIABLE ROOT_BIN_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

# Make variables changeble to the advanced user
set(ROOTCINT_EXECUTABLE ${ROOT_BIN_DIR}/rootcint)
set(GENREFLEX_EXECUTABLE ${ROOT_BIN_DIR}/genreflex)

# Make variables changeble to the advanced user
mark_as_advanced(ROOT_CONFIG_EXECUTABLE)
endif()
endif()


if (NOT ROOT_FOUND)
message(FATAL_ERROR "ROOT required, but not found")
message(FATAL_ERROR "ROOT required, but not found")
else()
message(STATUS "Find ROOT ${ROOT_VERSION} in ${ROOT_BIN_DIR}")
message(STATUS "Find ROOT ${ROOT_VERSION} in ${ROOT_BIN_DIR}")
endif()

0 comments on commit a415518

Please sign in to comment.