Skip to content

Commit

Permalink
change to fairroot targets
Browse files Browse the repository at this point in the history
  • Loading branch information
YanzhaoW committed May 28, 2024
1 parent 3513a6c commit fddf88e
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 54 deletions.
50 changes: 29 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,35 @@ if(NOT DEFINED ENV{SIMPATH})
"You did not define the environment variable SIMPATH which is nedded to find the external packages. Please set this variable and execute cmake again."
)
endif(NOT DEFINED ENV{SIMPATH})
set(SIMPATH $ENV{SIMPATH})

if(SIMPATH)
set(CMAKE_PREFIX_PATH ${SIMPATH} ${CMAKE_PREFIX_PATH})
endif()

# fairsoft lib path needed to be added for root dictionary detection:
set(LD_LIBRARY_PATH ${SIMPATH}/lib ${LD_LIBRARY_PATH})
set(GRAPHVIZ_EXTERNAL_LIBS FALSE)

if(NOT DEFINED ENV{FAIRROOTPATH})
message(
FATAL_ERROR
"You did not define the environment variable FAIRROOTPATH which is needed to find FairRoot. Please set this variable and execute cmake again."
)
endif(NOT DEFINED ENV{FAIRROOTPATH})
endif()

set(SIMPATH $ENV{SIMPATH})
set(FAIRROOTPATH $ENV{FAIRROOTPATH})

include(cmake/utils/create_library_with_dictionary.cmake)
include(cmake/scripts/set_ld_library_dir.cmake)
set(GRAPHVIZ_EXTERNAL_LIBS FALSE)

string(REGEX MATCHALL "[^:]+" PATH $ENV{PATH})

set(CMAKE_MODULE_PATH "${FAIRROOTPATH}/share/fairbase/cmake/modules" ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/scripts" ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/utils" ${CMAKE_MODULE_PATH})
list(APPEND CMAKE_PREFIX_PATH ${SIMPATH})
list(APPEND CMAKE_PREFIX_PATH ${FAIRROOTPATH})

list(APPEND CMAKE_MODULE_PATH "${FAIRROOTPATH}/share/fairbase/cmake/modules")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/scripts")

# For CMakeLists that still use the old way
set(ROOT_FOUND_VERSION 600000)
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
set(FairRoot_ROOT "${FAIRROOTPATH}")

set(CheckSrcDir "${FAIRROOTPATH}/share/fairbase/cmake/checks")

Expand All @@ -84,7 +84,6 @@ option(WITH_UCESB "Build UCESB" OFF)
option(WITH_EPICS "Build EPICS" OFF)
option(WITH_ACTAR "Build ACTAR" OFF)
option(WITH_SOFIA "Build SOFIA" OFF)
option(WITH_NeuLAND_DNN "Build NeuLAND DNN" OFF)
option(WITH_GTPC "Build GTPC" OFF)
option(WITH_FRS "Build FRS" OFF)
option(WITH_ASYEOS "Build ASYEOS" OFF)
Expand All @@ -95,11 +94,10 @@ if(NOT FairCMakeModules_FOUND)
message(FATAL_ERROR "Could not find FairCMakeModules! ")
endif()

include(create_library_with_dictionary)
include(FairFindPackage2)
include(FairFormattedOutput)

find_package2(PUBLIC FairRoot REQUIRED)
find_package2(PUBLIC FairRoot CONFIG REQUIRED)

# FairRoot_VERSION is eventually set by find_package, for now let's set it explicitly
execute_process(
Expand All @@ -122,16 +120,26 @@ set(R3BROOTPATH ${CMAKE_INSTALL_PREFIX})
# Load some basic macros which are needed later on
include(FairMacros)

list(APPEND required_root_components RIO)
set(required_root_components
RIO
Geom
Physics
Matrix
Hist
Graf
Gpad
Net
Imt
Core
MathCore
RHTTP
Spectrum)
list(APPEND optional_root_components opengl)
list(APPEND optional_root_components gdml vmc)

# TODO: ROOT package should be found with CONFIG mode
find_package2(
PUBLIC
ROOT
# VERSION
# 6.16.00
CONFIG
REQUIRED
COMPONENTS
Expand Down
16 changes: 16 additions & 0 deletions cmake/scripts/set_ld_library_dir.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# fairsoft lib path needed to be added for root dictionary detection:

# add library path to LD_LIBRARY_PATH
macro(ADD_TO_LD_LIBRARY_PATH path)
message(STATUS "Adding ${path}")
if(EXISTS ${path}/lib)
list(APPEND LD_LIBRARY_PATH ${path}/lib)
elseif(EXISTS ${SIMPATH}/lib64)
list(APPEND LD_LIBRARY_PATH ${path}/lib64)
else()
message(FATAL_ERROR "Cannot resolve the library path from \"${path}\"")
endif()
endmacro()

add_to_ld_library_path($ENV{SIMPATH})
add_to_ld_library_path($ENV{FAIRROOTPATH})
2 changes: 1 addition & 1 deletion neuland/executables/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_executable(neulandSim neulandSim.cxx)
target_link_libraries(neulandSim PRIVATE R3BNeulandSimulation ${Geant4_LIBRARIES}
${Geant4VMC_LIBRARIES} ExTestDetector)
${Geant4VMC_LIBRARIES})

add_executable(neulandAna neulandAna.cxx)
target_link_libraries(neulandAna PRIVATE R3BNeulandDigitizing)
5 changes: 2 additions & 3 deletions neuland/executables/neulandSim.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
#include "FairRunSim.h"
#include "R3BCave.h"
#include "R3BNeuland.h"
#include "R3BShared.h"
#include "TStopwatch.h"
#include <FairConstField.h>
#include <G4RunManager.hh>
#include <G4UserEventAction.hh>
#include <R3BFieldConst.h>
#include <R3BProgramOptions.h>
#include <TG4EventAction.h>
#include <boost/exception/diagnostic_information.hpp>
Expand Down Expand Up @@ -67,7 +66,7 @@ int main(int argc, const char** argv)
run->SetStoreTraj(false);
run->SetMaterials("media_r3b.geo");
run->SetSink(std::make_unique<FairRootFileSink>(simuFileName->value().c_str()));
auto fairField = std::make_unique<FairConstField>();
auto fairField = std::make_unique<R3BFieldConst>();
run->SetField(fairField.release());

// Primary particle generator
Expand Down
31 changes: 6 additions & 25 deletions r3bbase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,7 @@ set(HEADERS
R3BTsplinePar.h
R3BWhiterabbitPropagator.h)

set(DEPENDENCIES
GeoBase
ParBase
Base
Gen
Online
FairTools
ROOT::Geom
ROOT::Physics
ROOT::Matrix
ROOT::Hist
ROOT::Graf
ROOT::Gpad
ROOT::Net
ROOT::Imt
VMCLibrary
ROOT::Core
ROOT::MathCore
ROOT::RIO
ROOT::RHTTP
ROOT::Spectrum
FairLogger::FairLogger
fmt::fmt)
set(DEPENDENCIES FairRoot::Generators FairRoot::Online)

add_library_with_dictionary(
LIBNAME
Expand All @@ -81,8 +59,11 @@ add_library_with_dictionary(
DEPENDENCIES
${DEPENDENCIES})

target_link_directories(R3BBase PUBLIC ${FAIRROOT_LIBRARY_DIR})

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
message(STATUS "Linking -lstdc++fs due to the old version of gcc")
target_link_libraries(R3BBase PRIVATE -lstdc++fs)
endif()

if("${FairRoot_VERSION}" VERSION_LESS 19.0.0)
target_link_directories(R3BBase PUBLIC ${ROOT_LIBRARY_DIR})
endif()
4 changes: 1 addition & 3 deletions r3bsource/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,4 @@ add_library_with_dictionary(
${DIRS}
DEPENDENCIES
R3BData
Ucesb
PRIVATE_DEPENDENCIES
MbsAPI)
Ucesb)
2 changes: 1 addition & 1 deletion tracking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ add_library_with_dictionary(
DEPENDENCIES
R3BData
Field
TrkBase)
FairRoot::TrackBase)

0 comments on commit fddf88e

Please sign in to comment.