From 7d4fb1cb5fc12b10a81585e3bd22ac1392156b70 Mon Sep 17 00:00:00 2001 From: adrien-matta <a.matta@surrey.ac.uk> Date: Mon, 14 Sep 2015 18:33:30 +0100 Subject: [PATCH] * Fixing compilation of NPS with new Root.cmake file --- NPAnalysis/Example1/CMakeLists.txt | 2 +- NPAnalysis/Example2/CMakeLists.txt | 2 +- NPAnalysis/Hira2/CMakeLists.txt | 2 +- NPAnalysis/S1554/CMakeLists.txt | 2 +- NPAnalysis/TAMU/CMakeLists.txt | 2 +- NPAnalysis/e644pd/CMakeLists.txt | 2 +- NPAnalysis/new/CMakeLists.txt | 2 +- NPAnalysis/newMUGAST/CMakeLists.txt | 2 +- NPLib/CMakeLists.txt | 6 +- NPLib/FindROOT.cmake | 145 ---------------------------- NPLib/Root.cmake | 7 +- NPSimulation/CMakeLists.txt | 53 ++++++++-- 12 files changed, 60 insertions(+), 167 deletions(-) delete mode 100644 NPLib/FindROOT.cmake diff --git a/NPAnalysis/Example1/CMakeLists.txt b/NPAnalysis/Example1/CMakeLists.txt index ceb5ebea2..f0a199fcc 100644 --- a/NPAnalysis/Example1/CMakeLists.txt +++ b/NPAnalysis/Example1/CMakeLists.txt @@ -5,7 +5,7 @@ set(NPLIB "${NPTOOL}/NPLib") set(NPTOOL_INCLUDE_DIR "${NPLIB}/include") set(NPTOOL_LIB_DIR "${NPLIB}/lib") -include("${NPLIB}/FindROOT.cmake") +include("${NPLIB}/Root.cmake") project (NPAnalysis) set(CMAKE_BUILD_TYPE Release) diff --git a/NPAnalysis/Example2/CMakeLists.txt b/NPAnalysis/Example2/CMakeLists.txt index 1d6a34417..e07924d6a 100644 --- a/NPAnalysis/Example2/CMakeLists.txt +++ b/NPAnalysis/Example2/CMakeLists.txt @@ -5,7 +5,7 @@ set(NPLIB "${NPTOOL}/NPLib") set(NPTOOL_INCLUDE_DIR "${NPLIB}/include") set(NPTOOL_LIB_DIR "${NPLIB}/lib") -include("${NPLIB}/FindROOT.cmake") +include("${NPLIB}/Root.cmake") project (NPAnalysis) set(CMAKE_BUILD_TYPE Release) diff --git a/NPAnalysis/Hira2/CMakeLists.txt b/NPAnalysis/Hira2/CMakeLists.txt index ceb5ebea2..f0a199fcc 100644 --- a/NPAnalysis/Hira2/CMakeLists.txt +++ b/NPAnalysis/Hira2/CMakeLists.txt @@ -5,7 +5,7 @@ set(NPLIB "${NPTOOL}/NPLib") set(NPTOOL_INCLUDE_DIR "${NPLIB}/include") set(NPTOOL_LIB_DIR "${NPLIB}/lib") -include("${NPLIB}/FindROOT.cmake") +include("${NPLIB}/Root.cmake") project (NPAnalysis) set(CMAKE_BUILD_TYPE Release) diff --git a/NPAnalysis/S1554/CMakeLists.txt b/NPAnalysis/S1554/CMakeLists.txt index 1d6a34417..e07924d6a 100644 --- a/NPAnalysis/S1554/CMakeLists.txt +++ b/NPAnalysis/S1554/CMakeLists.txt @@ -5,7 +5,7 @@ set(NPLIB "${NPTOOL}/NPLib") set(NPTOOL_INCLUDE_DIR "${NPLIB}/include") set(NPTOOL_LIB_DIR "${NPLIB}/lib") -include("${NPLIB}/FindROOT.cmake") +include("${NPLIB}/Root.cmake") project (NPAnalysis) set(CMAKE_BUILD_TYPE Release) diff --git a/NPAnalysis/TAMU/CMakeLists.txt b/NPAnalysis/TAMU/CMakeLists.txt index dc3f3a57e..34286904a 100644 --- a/NPAnalysis/TAMU/CMakeLists.txt +++ b/NPAnalysis/TAMU/CMakeLists.txt @@ -5,7 +5,7 @@ set(NPLIB "${NPTOOL}/NPLib") set(NPTOOL_INCLUDE_DIR "${NPLIB}/include") set(NPTOOL_LIB_DIR "${NPLIB}/lib") -include("${NPLIB}/FindROOT.cmake") +include("${NPLIB}/Root.cmake") project (NPAnalysis) set(CMAKE_BUILD_TYPE Release) diff --git a/NPAnalysis/e644pd/CMakeLists.txt b/NPAnalysis/e644pd/CMakeLists.txt index 1d6a34417..e07924d6a 100644 --- a/NPAnalysis/e644pd/CMakeLists.txt +++ b/NPAnalysis/e644pd/CMakeLists.txt @@ -5,7 +5,7 @@ set(NPLIB "${NPTOOL}/NPLib") set(NPTOOL_INCLUDE_DIR "${NPLIB}/include") set(NPTOOL_LIB_DIR "${NPLIB}/lib") -include("${NPLIB}/FindROOT.cmake") +include("${NPLIB}/Root.cmake") project (NPAnalysis) set(CMAKE_BUILD_TYPE Release) diff --git a/NPAnalysis/new/CMakeLists.txt b/NPAnalysis/new/CMakeLists.txt index 08575f4c3..7d4ee28a6 100644 --- a/NPAnalysis/new/CMakeLists.txt +++ b/NPAnalysis/new/CMakeLists.txt @@ -5,7 +5,7 @@ set(NPLIB "${NPTOOL}/NPLib") set(NPTOOL_INCLUDE_DIR "${NPLIB}/include") set(NPTOOL_LIB_DIR "${NPLIB}/lib") -include("${NPLIB}/FindROOT.cmake") +include("${NPLIB}/Root.cmake") project (NPAnalysis) set(CMAKE_BUILD_TYPE Release) diff --git a/NPAnalysis/newMUGAST/CMakeLists.txt b/NPAnalysis/newMUGAST/CMakeLists.txt index 1d6a34417..e07924d6a 100644 --- a/NPAnalysis/newMUGAST/CMakeLists.txt +++ b/NPAnalysis/newMUGAST/CMakeLists.txt @@ -5,7 +5,7 @@ set(NPLIB "${NPTOOL}/NPLib") set(NPTOOL_INCLUDE_DIR "${NPLIB}/include") set(NPTOOL_LIB_DIR "${NPLIB}/lib") -include("${NPLIB}/FindROOT.cmake") +include("${NPLIB}/Root.cmake") project (NPAnalysis) set(CMAKE_BUILD_TYPE Release) diff --git a/NPLib/CMakeLists.txt b/NPLib/CMakeLists.txt index 007475406..114476b17 100644 --- a/NPLib/CMakeLists.txt +++ b/NPLib/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required (VERSION 2.8) include(CheckCXXCompilerFlag) project(NPLib CXX) +set(CMAKE_BUILD_TYPE Release) + # Major change in the Core/Physics (affecting the detector/analysis/simulation) set(NPLIB_VERSION_MAJOR 2) # Minor change in the Core/Physics (not affecting any other part) @@ -9,9 +11,6 @@ set(NPLIB_VERSION_MINOR 1) set(NPLIB_VERSION_DETA 35) configure_file(Core/NPLibVersion.h.in Core/NPLibVersion.h @ONLY) - -set(CMAKE_BUILD_TYPE Release) - set(DETLIST ${ETLIST}) string(COMPARE EQUAL "${DETLIST}" "" rdet) @@ -26,7 +25,6 @@ cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) # This suppress the Up-to-Date message of file installed for cmake 3.1 and above set(CMAKE_INSTALL_MESSAGE LAZY) -message("${CMAKE_CXX_FLAGS}") # look for Root include("Root.cmake") diff --git a/NPLib/FindROOT.cmake b/NPLib/FindROOT.cmake deleted file mode 100644 index d81aa457a..000000000 --- a/NPLib/FindROOT.cmake +++ /dev/null @@ -1,145 +0,0 @@ -# - Find ROOT instalation -# This module tries to find the ROOT installation on your system. -# It tries to find the root-config script which gives you all the needed information. -# If the system variable LOCAL_ROOTSYS is set this is straight forward. -# If not the module uses the pathes given in ROOT_CONFIG_SEARCHPATH. -# If you need an other path you should add this path to this varaible. -# The root-config script is then used to detect basically everything else. -# This module defines a number of key variables and macros. - -# F.Uhlig@gsi.de (fairroot.gsi.de) - - -MESSAGE(STATUS "Looking for Root...") - -SET(ROOT_CONFIG_SEARCHPATH - $ENV{ROOTSYS}/bin - /usr/bin -) - -SET(ROOT_DEFINITIONS "") - -SET(ROOT_INSTALLED_VERSION_TOO_OLD FALSE) - -SET(ROOT_CONFIG_EXECUTABLE ROOT_CONFIG_EXECUTABLE-NOTFOUND) - -FIND_PROGRAM(ROOT_CONFIG_EXECUTABLE NAMES root-config PATHS - ${ROOT_CONFIG_SEARCHPATH} - NO_DEFAULT_PATH) - -IF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND") - MESSAGE( FATAL_ERROR "ROOT not installed in the searchpath and LOCAL_ROOTSYS is not set. Please - set LOCAL_ROOTSYS or add the path to your ROOT installation in the Macro FindROOT.cmake in the - subdirectory cmake/modules.") -ELSE (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND") - STRING(REGEX REPLACE "(^.*)/bin/root-config" "\\1" test ${ROOT_CONFIG_EXECUTABLE}) - SET( ENV{LOCAL_ROOTSYS} ${test}) - set( LOCAL_ROOTSYS ${test}) -ENDIF (${ROOT_CONFIG_EXECUTABLE} MATCHES "ROOT_CONFIG_EXECUTABLE-NOTFOUND") - - -IF (ROOT_CONFIG_EXECUTABLE) - - SET(ROOT_FOUND FALSE) - - EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE} ARGS "--version" OUTPUT_VARIABLE ROOTVERSION) - - MESSAGE(STATUS "Looking for Root... - found $ENV{LOCAL_ROOTSYS}/bin/root") - MESSAGE(STATUS "Looking for Root... - version ${ROOTVERSION} ") - - # we need at least version 5.00/00 - IF (NOT ROOT_MIN_VERSION) - SET(ROOT_MIN_VERSION "5.00/00") - ENDIF (NOT ROOT_MIN_VERSION) - - # now parse the parts of the user given version string into variables - STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+" "\\1" req_root_major_vers "${ROOT_MIN_VERSION}") - STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" req_root_minor_vers "${ROOT_MIN_VERSION}") - STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+)" "\\1" req_root_patch_vers "${ROOT_MIN_VERSION}") - - # and now the version string given by qmake - STRING(REGEX REPLACE "^([0-9]+)\\.[0-9][0-9]+\\/[0-9][0-9]+.*" "\\1" found_root_major_vers "${ROOTVERSION}") - STRING(REGEX REPLACE "^[0-9]+\\.([0-9][0-9])+\\/[0-9][0-9]+.*" "\\1" found_root_minor_vers "${ROOTVERSION}") - STRING(REGEX REPLACE "^[0-9]+\\.[0-9][0-9]+\\/([0-9][0-9]+).*" "\\1" found_root_patch_vers "${ROOTVERSION}") - - IF (found_root_major_vers LESS 5) - MESSAGE( FATAL_ERROR "Invalid ROOT version \"${ROOTERSION}\", at least major version 4 is required, e.g. \"5.00/00\"") - ENDIF (found_root_major_vers LESS 5) - - # compute an overall version number which can be compared at once - MATH(EXPR req_vers "${req_root_major_vers}*10000 + ${req_root_minor_vers}*100 + ${req_root_patch_vers}") - MATH(EXPR found_vers "${found_root_major_vers}*10000 + ${found_root_minor_vers}*100 + ${found_root_patch_vers}") - - IF (found_vers LESS req_vers) - SET(ROOT_FOUND FALSE) - SET(ROOT_INSTALLED_VERSION_TOO_OLD TRUE) - ELSE (found_vers LESS req_vers) - SET(ROOT_FOUND TRUE) - ENDIF (found_vers LESS req_vers) - -ENDIF (ROOT_CONFIG_EXECUTABLE) - - -IF (ROOT_FOUND) - - # ask root-config for the library dir - # Set ROOT_LIBRARY_DIR - - EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE} - ARGS "--libdir" - OUTPUT_VARIABLE ROOT_LIBRARY_DIR_TMP ) - - IF(EXISTS "${ROOT_LIBRARY_DIR_TMP}") - SET(ROOT_LIBRARY_DIR ${ROOT_LIBRARY_DIR_TMP} ) - ELSE(EXISTS "${ROOT_LIBRARY_DIR_TMP}") - MESSAGE("Warning: ROOT_CONFIG_EXECUTABLE reported ${ROOT_LIBRARY_DIR_TMP} as library path,") - MESSAGE("Warning: but ${ROOT_LIBRARY_DIR_TMP} does NOT exist, ROOT must NOT be installed correctly.") - ENDIF(EXISTS "${ROOT_LIBRARY_DIR_TMP}") - - # ask root-config for the binary dir - EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE} - ARGS "--bindir" - OUTPUT_VARIABLE root_bins ) - SET(ROOT_BINARY_DIR ${root_bins}) - - # ask root-config for the include dir - EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE} - ARGS "--incdir" - OUTPUT_VARIABLE root_headers ) - SET(ROOT_INCLUDE_DIR ${root_headers}) - # CACHE INTERNAL "") - - # ask root-config for the library varaibles - EXEC_PROGRAM( ${ROOT_CONFIG_EXECUTABLE} -# ARGS "--noldflags --noauxlibs --libs" - ARGS "--glibs" - OUTPUT_VARIABLE root_flags ) - -# STRING(REGEX MATCHALL "([^ ])+" root_libs_all ${root_flags}) -# STRING(REGEX MATCHALL "-L([^ ])+" root_library ${root_flags}) -# REMOVE_FROM_LIST(root_flags "${root_libs_all}" "${root_library}") - - SET(ROOT_LIBRARIES ${root_flags}) - - # Make variables changeble to the advanced user - MARK_AS_ADVANCED( ROOT_LIBRARY_DIR ROOT_INCLUDE_DIR ROOT_DEFINITIONS) - - # Set ROOT_INCLUDES - SET( ROOT_INCLUDES ${ROOT_INCLUDE_DIR}) - - SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${ROOT_LIBRARY_DIR}) - - ####################################### - # - # Check the executables of ROOT - # ( rootcint ) - # - ####################################### - - FIND_PROGRAM(ROOT_CINT_EXECUTABLE - NAMES rootcint - PATHS ${ROOT_BINARY_DIR} - NO_DEFAULT_PATH - ) - -ENDIF (ROOT_FOUND) diff --git a/NPLib/Root.cmake b/NPLib/Root.cmake index 7a3580011..33e2f5a07 100644 --- a/NPLib/Root.cmake +++ b/NPLib/Root.cmake @@ -65,5 +65,8 @@ include_directories( ${ROOT_INCLUDE_DIR}) # Get the compilator flag from root to assure consistancy exec_program(${NPTOOL_ROOT_CONFIG} ARGS "--cflags" OUTPUT_VARIABLE NPTOOL_ROOT_CFLAGS ) -set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS_RELEASE} ${NPTOOL_ROOT_CFLAGS}") - +if(CMAKE_CXX_FLAGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NPTOOL_ROOT_CFLAGS}") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS_RELEASE} ${NPTOOL_ROOT_CFLAGS}") +endif() diff --git a/NPSimulation/CMakeLists.txt b/NPSimulation/CMakeLists.txt index 753c7c1b0..a181c3f7b 100755 --- a/NPSimulation/CMakeLists.txt +++ b/NPSimulation/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 2.8) -#include("../NPLib/FindROOT.cmake") -include("../NPLib/Root.cmake") +include(CheckCXXCompilerFlag) + project (NPSimulation) set (NPSIM_VERSION_MAJOR 2) set (NPSIM_VERSION_MINOR 0) @@ -8,6 +8,12 @@ set (NPSIM_VERSION_DETS 18) set(CMAKE_BUILD_TYPE Release) +# Setting the policy to match Cmake version +cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) + +# This suppress the Up-to-Date message of file installed for cmake 3.1 and above +set(CMAKE_INSTALL_MESSAGE LAZY) + # Finding Geant 4 find_package(Geant4 REQUIRED ui_all vis_all) message(${Geant4_USE_FILE}) @@ -19,6 +25,40 @@ include(${NPLib_USE_FILE}) configure_file(Core/NPSimulationVersion.hh.in Core/NPSimulationVersion.hh @ONLY) +# look for Root +include("../NPLib/Root.cmake") + +# If the compiler is Clang, silence the unrecognised flags +if(${CMAKE_CXX_COMPILER_ID} MATCHES ".*Clang.*") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics") + if( UNIX AND NOT APPLE ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") + endif() +endif() + +# Adjust the compiler language flag +set(NOCPPFLAGS true) +if(${CMAKE_CXX_FLAGS} MATCHES ".*std=.*11") + set(NOCPPFLAGS false) +elseif(${CMAKE_CXX_FLAGS} MATCHES ".*std=.*0x") + set(NOCPPFLAGS false) +endif() + +if(NOCPPFLAGS) + CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) + if(COMPILER_SUPPORTS_CXX11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + else() + CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) + endif() + + if(COMPILER_SUPPORTS_CXX0X) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + endif() +endif() + + + # Detector List set(DETLIST ${NPLib_DETECTOR_LIST}) string(COMPARE EQUAL "${DETLIST}" "" rdet) @@ -28,15 +68,12 @@ if(rdet) message("Building the following detectors ${DETLIST}") endif() -# Setting the policy to match Cmake version -cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) - # Add root to the link and include directories -include_directories( ${ROOT_INCLUDE_DIR}) -link_directories( ${ROOT_LIBRARY_DIR}) +#include_directories( ${ROOT_INCLUDE_DIR}) +#link_directories( ${ROOT_LIBRARY_DIR}) # Get the compilator flag from root to assure consistancy -EXEC_PROGRAM(${ROOT_CONFIG_EXECUTABLE} +EXEC_PROGRAM(${NPTOOL_ROOT_CONFIG} ARGS "--cflags" OUTPUT_VARIABLE root_cflags ) -- GitLab