From 9bf29457b1d00d736189d386dee4792633e46e4a Mon Sep 17 00:00:00 2001 From: Andre Sailer <andre.philippe.sailer@cern.ch> Date: Wed, 17 Jul 2019 09:24:05 +0200 Subject: [PATCH] CMake: make all the packages work without dd4hep_package and using targets from dependencies --- DDAlign/CMakeLists.txt | 2 + DDCond/CMakeLists.txt | 4 +- DDCore/CMakeLists.txt | 33 +++++------ DDDetectors/CMakeLists.txt | 3 + DDDigi/CMakeLists.txt | 44 +++++++++----- DDEve/CMakeLists.txt | 47 +++++++++------ DDG4/CMakeLists.txt | 91 +++++------------------------ DDParsers/CMakeLists.txt | 17 ++++-- DDRec/CMakeLists.txt | 10 +++- DDTest/CMakeLists.txt | 68 +++++++++++++--------- UtilityApps/CMakeLists.txt | 109 ++++++++++++++++++++--------------- cmake/DD4hepConfig.cmake.in | 83 +++++++++++++++----------- cmake/DD4hep_XML_setup.cmake | 8 ++- 13 files changed, 277 insertions(+), 242 deletions(-) diff --git a/DDAlign/CMakeLists.txt b/DDAlign/CMakeLists.txt index 9f5d4382b..cb2f8bf45 100644 --- a/DDAlign/CMakeLists.txt +++ b/DDAlign/CMakeLists.txt @@ -29,4 +29,6 @@ new_dd4hep_add_plugin(DDAlignPlugins LINK_LIBRARIES DDAlign ) +INSTALL(DIRECTORY include/DDAlign DESTINATION include) INSTALL(TARGETS DDAlign EXPORT DD4hep DESTINATION lib) +INSTALL(TARGETS DDAlignPlugins DESTINATION lib) diff --git a/DDCond/CMakeLists.txt b/DDCond/CMakeLists.txt index 0487ddb80..10b9a3873 100644 --- a/DDCond/CMakeLists.txt +++ b/DDCond/CMakeLists.txt @@ -39,4 +39,6 @@ new_dd4hep_add_plugin(DDCondPlugins SOURCES src/plugins/*.cpp src/Type1/*.cpp LINK_LIBRARIES DDCond) -INSTALL(TARGETS DDCond EXPORT DD4hep DESTINATION lib) \ No newline at end of file +INSTALL(DIRECTORY include/DDCond DESTINATION include) +INSTALL(TARGETS DDCond EXPORT DD4hep DESTINATION lib) +INSTALL(TARGETS DDCondPlugins DESTINATION lib) diff --git a/DDCore/CMakeLists.txt b/DDCore/CMakeLists.txt index c387528ff..83280dcd8 100644 --- a/DDCore/CMakeLists.txt +++ b/DDCore/CMakeLists.txt @@ -73,8 +73,8 @@ target_link_libraries(DDCore PUBLIC DD4hepGaudiPluginMgr DDParsers - ROOT::Interface - ROOT::Geom ROOT::Geom GenVector + ROOT::Core + ROOT::Geom ROOT::GenVector ${XML_LIBRARIES} # XercesC or not ) @@ -83,19 +83,6 @@ TARGET_COMPILE_FEATURES(DDCore #cxx_std_${CMAKE_CXX_STANDARD} # Needs cmake 3.8 ) -#FIXME: install header file folders -# dd4hep_package( DDCore -# USES [ROOT REQUIRED COMPONENTS Geom GenVector] -# DDParsers -# OPTIONAL XERCESC -# INCLUDE_DIRS include -# INSTALL_INCLUDES include/DDSegmentation -# include/DD4hep -# include/XML -# include/JSON -# include/Parsers -# include/ROOT ) - # # Generate DDCore plugins--------------------------------------------------------- new_dd4hep_add_plugin(DDCorePlugins SOURCES src/plugins/*.cpp LINK_LIBRARIES DDCore) @@ -104,7 +91,7 @@ new_dd4hep_add_plugin(DDCorePlugins SOURCES src/plugins/*.cpp IF(${ROOT_gdml_FOUND}) new_dd4hep_add_plugin(DDGDMLPlugins SOURCES src/gdml/*.cpp - LINK_LIBRARIES DDCore ROOT::Interface + LINK_LIBRARIES DDCore ROOT::Core ) ELSE() MESSAGE(WARN "ROOT does not include GDML, not building DDCore GDML Plugins") @@ -114,7 +101,7 @@ ENDIF() IF(ROOT_python_FOUND) new_dd4hep_add_plugin(DDPythonPlugins SOURCES src/python/*.cpp - LINK_LIBRARIES DDCore ROOT::Interface ROOT::PyROOT + LINK_LIBRARIES DDCore ROOT::Core ROOT::PyROOT ) ELSE() MESSAGE(WARN "ROOT does not include PyRoot, not building DDCore DDPython Plugins") @@ -125,4 +112,16 @@ ENDIF() #---Package installation procedure(s) ---------------------------------------------- dd4hep_install_files(FILES python/*.py DESTINATION python) +INSTALL(DIRECTORY + include/DDSegmentation + include/DD4hep + include/XML + include/JSON + include/Parsers + include/ROOT + DESTINATION include + ) + + INSTALL(TARGETS DDCore EXPORT DD4hep DESTINATION lib) +INSTALL(TARGETS DDCorePlugins DESTINATION lib) diff --git a/DDDetectors/CMakeLists.txt b/DDDetectors/CMakeLists.txt index 733fd959a..9a0767359 100644 --- a/DDDetectors/CMakeLists.txt +++ b/DDDetectors/CMakeLists.txt @@ -22,3 +22,6 @@ new_dd4hep_add_plugin(DDDetectors LINK_LIBRARIES DDRec INCLUDE_DIRS include ) + +INSTALL(TARGETS DDDetectors DESTINATION lib) +INSTALL(DIRECTORY compact DESTINATION DDDetectors) diff --git a/DDDigi/CMakeLists.txt b/DDDigi/CMakeLists.txt index b2bf08086..df872f784 100644 --- a/DDDigi/CMakeLists.txt +++ b/DDDigi/CMakeLists.txt @@ -8,37 +8,51 @@ # For the list of contributors see $DD4hepINSTALL/doc/CREDITS. # #========================================================================== -dd4hep_package( DDDigi - USES DDCore - [ROOT REQUIRED COMPONENTS Geom GenVector RIO] - BOOST - INCLUDE_DIRS include - INSTALL_INCLUDES include/DDDigi ) +# dd4hep_package( DDDigi +# USES DDCore +# [ROOT REQUIRED COMPONENTS Geom GenVector RIO] +# BOOST +# INCLUDE_DIRS include +# INSTALL_INCLUDES include/DDDigi ) #---Add Library--------------------------------------------------------------------- -dd4hep_add_package_library(DDDigi SOURCES src/*.cpp - [OPTIONAL TBB REQUIRED] +file(GLOB DDDigi_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) +add_library(DDDigi SHARED ${DDDigi_SOURCES}) +target_link_libraries(DDDigi PUBLIC + DDCore Boost::boost ROOT::Core ROOT::Geom ROOT::GenVector ROOT::RIO) + +target_include_directories(DDDigi + PUBLIC + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> + $<INSTALL_INTERFACE:include> ) -if( TBB_INCLUDE_DIR ) + +FIND_PACKAGE(TBB QUIET) +if(TBB_FOUND) dd4hep_print( "|++> TBB_INCLUDE_DIR --> ${TBB_INCLUDE_DIR}") dd4hep_print( "|++> TBB_LIBRARY --> ${TBB_LIBRARY}") dd4hep_print( "|++> TBB found. DDDigi will run multi threaded.") target_compile_definitions(DDDigi PUBLIC DD4HEP_USE_TBB) target_link_libraries(DDDigi ${TBB_LIBRARY}) + target_include_directories(DDDigi ${TBB_INCLUDE_DIRS}) else() dd4hep_print( "|++> TBB not found. DDDigi will only work single threaded.") endif() #--------------------------- Legacy libraries ------------------------------------- -dd4hep_add_dictionary( G__DDDigi +new_dd4hep_add_dictionary(G__DDDigi SOURCES ${DDCore_INCLUDE_DIRS}/include/ROOT/Warnings.h python/DDDigiDict.C LINKDEF ${DDCore_INCLUDE_DIRS}/include/ROOT/LinkDef.h + DEPENDS DDCore ROOT::Core ROOT::Geom ROOT::GenVector ROOT::RIO Boost::boost ) #--------------------------- Plugin library for the digitization framework ------- -dd4hep_add_plugin(DDDigiPlugins - GENERATED G__DDDigi.cxx - SOURCES plugins/*.cpp +new_dd4hep_add_plugin(DDDigiPlugins + SOURCES plugins/*.cpp + GENERATED G__DDDigi.cxx + LINK_LIBRARIES DDDigi ) -target_compile_definitions(DDDigiPlugins PUBLIC DD4HEP_USE_TBB) + #---Package installation procedure(s) ---------------------------------------------- -dd4hep_install_files(FILES python/*.py python/*.C DESTINATION python) +file(GLOB DDigi_python python/*.py python/*.C) +install(FILES ${DDigi_python} DESTINATION python) +install(TARGETS DDDigi EXPORT DD4hep DESTINATION lib) diff --git a/DDEve/CMakeLists.txt b/DDEve/CMakeLists.txt index 73ae27a76..d1f6abfb3 100644 --- a/DDEve/CMakeLists.txt +++ b/DDEve/CMakeLists.txt @@ -8,40 +8,53 @@ # For the list of contributors see $DD4hepINSTALL/doc/CREDITS. # #========================================================================== -dd4hep_package( DDEve - USES DDCore [ROOT REQUIRED COMPONENTS Eve Gui Graf3d RGL EG] - INCLUDE_DIRS include - INSTALL_INCLUDES include/DDEve) +# dd4hep_package( DDEve +# USES DDCore [ROOT REQUIRED COMPONENTS Eve Gui Graf3d RGL EG] +# INCLUDE_DIRS include +# INSTALL_INCLUDES include/DDEve) # #---Add Plugin Library----------------------------------------------------- -dd4hep_add_dictionary ( G__DDEve +add_library(DDEve_Interface INTERFACE) +target_include_directories(DDEve_Interface + INTERFACE + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> + $<INSTALL_INTERFACE:include> +) + +new_dd4hep_add_dictionary(G__DDEve SOURCES ${DDCore_INCLUDE_DIRS}/include/ROOT/Warnings.h include/DDEve/*.h EXCLUDE include/DDEve/Utilities.h include/DDEve/ParticleActors.h include/DDEve/HitActors.h include/DDEve/Factories.h LINKDEF ${DDCore_INCLUDE_DIRS}/include/ROOT/LinkDef.h + DEPENDS DDCore ) -# -dd4hep_add_plugin ( DDEvePlugins SOURCES src/*.cpp - GENERATED G__DDEve.cxx - OPTIONAL [LCIO EXTERNAL SOURCES lcio/LCIOEventHandler.cpp] ) + +if(LCIO_FOUND) + SET(DDEVE_LCIO_SOURCES lcio/LCIOEventHandler.cpp) +endif() + +new_dd4hep_add_plugin (DDEvePlugins SOURCES src/*.cpp + GENERATED ${DDEVE_LCIO_SOURCES} G__DDEve.cxx + ) +target_link_libraries(DDEvePlugins DDCore DDEve_Interface ROOT::Eve) if(DD4HEP_USE_GEANT4) - dd4hep_add_dictionary ( G__DDG4IO + new_dd4hep_add_dictionary(G__DDG4IO SOURCES ${DDCore_INCLUDE_DIRS}/include/ROOT/Warnings.h DDEve/DDG4IO.C LINKDEF ${DDCore_INCLUDE_DIRS}/include/ROOT/LinkDef.h - OPTIONAL DDG4 - ) - dd4hep_add_regular_library ( DDG4IO - SOURCES DDEve/IO.cpp - GENERATED G__DDG4IO.cxx - OPTIONAL DDG4 + DEPENDS DDG4 ) + add_library(DDG4IO SHARED DDEve/IO.cpp G__DDG4IO.cxx) + target_link_libraries(DDG4IO DDG4 DDEve_Interface) endif() + #----------------------------------------------------------------------------------- -dd4hep_add_executable( ddeve DDEve/DDEve.cpp ) +add_executable(ddeve DDEve/DDEve.cpp) +target_link_libraries(ddeve DDEve_Interface ROOT::Core) #----------------------------------------------------------------------------------- #---Package installation procedure(s) ------------------------------------- dd4hep_install_dir ( DDEve DESTINATION examples ) +install(TARGETS ddeve RUNTIME DESTINATION bin) \ No newline at end of file diff --git a/DDG4/CMakeLists.txt b/DDG4/CMakeLists.txt index b610abec3..59feb2f2a 100644 --- a/DDG4/CMakeLists.txt +++ b/DDG4/CMakeLists.txt @@ -15,74 +15,7 @@ IF(NOT DD4HEP_USE_GEANT4) ENDIF() find_package(Geant4 10.2.2 REQUIRED COMPONENTS gdml ui_all vis_all) -#include( ${Geant4_USE_FILE} ) # do not use the use file, this is not very considerate... - -IF((NOT ${Geant4_TLS_MODEL} STREQUAL "global-dynamic") AND NOT ${DD4HEP_IGNORE_GEANT4_TLS}) - MESSAGE(FATAL_ERROR "Geant4 was built with ${Geant4_TLS_MODEL}, DD4hep requires 'global-dynamic'! Ignore this ERROR with DD4HEP_IGNORE_GEANT4_TLS=True ") -ENDIF() - -if(Geant4_builtin_clhep_FOUND) - set(CLHEP "") -else() - set(CLHEP CLHEP) -endif() - -MESSAGE(STATUS "Geant4 Libraries ${Geant4_LIBRARIES}") -MESSAGE(STATUS "Geant4 CXX_FLAGS ${Geant4_CXX_FLAGS}") -MESSAGE(STATUS "Geant4 INCL DIRS ${Geant4_INCLUDE_DIRS}") -MESSAGE(STATUS "Geant4_VERSION: ${Geant4_VERSION}" ) - -# Geant4::10.2.2 at least, not in 10.5 (check where it switches) -#Geant4 CXX Flags are a string with quotes, not a list, so we need to convert to a list... -string(REPLACE " " ";" Geant4_Flags ${Geant4_CXX_FLAGS} ${Geant4_CXX_FLAGS_${CMAKE_BUILD_TYPE}}) -SET(Geant4_CXX_FLAGS ${Geant4_Flags}) - -#Geant4_DEFINITIONS already include -D, we jave to get rid of that so we can join things when creating dictionaries -SET(G4_DEF_TEMP "") -foreach(def ${Geant4_DEFINITIONS}) - string(REPLACE "-D" "" def ${def}) - LIST(APPEND G4_DEF_TEMP ${def}) -endforeach() -SET(Geant4_DEFINITIONS ${G4_DEF_TEMP}) -UNSET(G4_DEF_TEMP) - -#get_filename_component(Geant4_LOCATION ${Geant4_INCLUDE_DIRS} DIRECTORY) -SET(Geant4_LOCATION "/cvmfs/ilc.desy.de/sw/x86_64_gcc49_sl6/geant4/10.03.p02/lib64") - -ADD_LIBRARY(Geant4::Interface INTERFACE IMPORTED GLOBAL) - -SET_TARGET_PROPERTIES(Geant4::Interface - PROPERTIES - INTERFACE_COMPILE_OPTIONS "${Geant4_CXX_FLAGS}" - INTERFACE_COMPILE_DEFINITIONS "${Geant4_DEFINITIONS}" - INTERFACE_INCLUDE_DIRECTORIES "${Geant4_INCLUDE_DIRS}" - ) - -IF(CLHEP) - MESSAGE(STATUS "Adding CLHEP to Geant4::Interface Dependencies") - TARGET_LINK_LIBRARIES(Geant4::Interface INTERFACE ${CLHEP}) -ENDIF() - -foreach(LIB ${Geant4_LIBRARIES}) - find_library(G4_LIB_TEMP_${LIB} ${LIB} PATHS ${Geant4_LOCATION}) - ADD_LIBRARY(Geant4::${LIB} SHARED IMPORTED GLOBAL) - MESSAGE(STATUS "Geant4 lib location ${LIB} ${G4_LIB_TEMP_${LIB}}") - SET_TARGET_PROPERTIES(Geant4::${LIB} - PROPERTIES - INTERFACE_COMPILE_OPTIONS "${Geant4_CXX_FLAGS}" - INTERFACE_COMPILE_DEFINITIONS "${Geant4_DEFINITIONS}" - INTERFACE_INCLUDE_DIRECTORIES "${Geant4_INCLUDE_DIRS}" - IMPORTED_LOCATION ${G4_LIB_TEMP_${LIB}} - ) - TARGET_LINK_LIBRARIES(Geant4::Interface INTERFACE Geant4::${LIB}) -endforeach() - -MESSAGE(STATUS "Geant4 Libraries ${Geant4_LIBRARIES};${Geant4_COMPONENT_LIBRARIES}") -MESSAGE(STATUS "Geant4 Location ${Geant4_LOCATION}") -MESSAGE(STATUS "Geant4 Defintitions ${Geant4_DEFINITIONS}") -MESSAGE(STATUS "Geant4 CXX_FLAGS ${Geant4_CXX_FLAGS}") -MESSAGE(STATUS "Geant4 INCL DIRS ${Geant4_INCLUDE_DIRS}") -MESSAGE(STATUS "Geant4_VERSION: ${Geant4_VERSION}" ) +DD4HEP_SETUP_GEANT4_TARGETS() # dd4hep_package( DDG4 # USES [GEANT4 REQUIRED COMPONENTS gdml ui_all vis_all] @@ -100,13 +33,9 @@ add_library(DDG4 SHARED ${DDG4_SOURCES}) target_link_libraries(DDG4 PUBLIC DDCore - #${Geant4_LIBRARIES} - #${Geant4_COMPONENT_LIBRARIES} - ROOT::Interface Geant4::Interface ) - #Ensure our own includes come before those of the system target_include_directories(DDG4 BEFORE PUBLIC @@ -128,8 +57,9 @@ new_dd4hep_add_dictionary( G__DDG4 ) #--------------------------- Plugin library for the simulation framework --------- new_dd4hep_add_plugin(DDG4Plugins - SOURCES plugins/*.cpp G__DDG4.cxx - LINK_LIBRARIES DDG4 + SOURCES plugins/*.cpp + GENERATED G__DDG4.cxx + LINK_LIBRARIES ROOT::Core CLHEP::CLHEP DDG4 ${XML_LIBRARIES} DDParsers ) #--------------------------- Plugin library for the simulation framework --------- @@ -138,7 +68,7 @@ if(PYTHONLIBS_FOUND) MESSAGE(STATUS "Python found, creating DDG4Python Dictionary") new_dd4hep_add_dictionary(G__DDG4Python SOURCES src/python/DDG4Python.C - DEPENDS DDCore DDParsers DDG4 ROOT::Interface + DEPENDS DDCore DDParsers DDG4 ROOT::Core INCLUDES ${Geant4_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} DEFINITIONS ${Geant4_DEFINITIONS} ) @@ -150,7 +80,7 @@ if(PYTHONLIBS_FOUND) #--------------------------- Specialized python plugins -------------------------- MESSAGE(STATUS "ROOT Has Python, creating DDPython library and plugins") add_library(DDPython SHARED G__DDPython.cxx tpython/DDPython.cpp) - target_link_libraries(DDPython DDG4 ROOT::Interface ${PYTHON_LIBRARIES} ROOT::PyROOT) + target_link_libraries(DDPython DDG4 ROOT::Core ${PYTHON_LIBRARIES} ROOT::PyROOT) target_include_directories(DDPython PUBLIC ${PYTHON_INCLUDE_DIRS}) new_dd4hep_add_plugin(DDG4Python SOURCES src/python/*.cpp G__DDG4Python.cxx @@ -158,7 +88,7 @@ if(PYTHONLIBS_FOUND) ) #---Helper to overcome deficiency of the python executable concerning multi-threading add_executable(pyddg4 pyddg4.cpp) - target_link_libraries(pyddg4 PUBLIC DDPython ROOT::Interface ROOT::PyROOT) + target_link_libraries(pyddg4 PUBLIC DDPython ROOT::Core ROOT::PyROOT) INSTALL(TARGETS DDPython EXPORT DD4hep DESTINATION lib) endif() else() @@ -196,3 +126,10 @@ install(PROGRAMS python/DDSim/bin/ddsim DESTINATION bin) dd4hep_install_dir(python/DDSim DESTINATION python) INSTALL(TARGETS DDG4 EXPORT DD4hep DESTINATION lib) +INSTALL(TARGETS DDG4 DDG4Plugins + LIBRARY DESTINATION lib) + +INSTALL(DIRECTORY + include/DDG4 + DESTINATION include + ) diff --git a/DDParsers/CMakeLists.txt b/DDParsers/CMakeLists.txt index 70fb7bbb7..2f5053bda 100644 --- a/DDParsers/CMakeLists.txt +++ b/DDParsers/CMakeLists.txt @@ -29,7 +29,10 @@ if(Boost_FOUND) endif() add_library(DDParsers SHARED ${DDParsers_SOURCES} ${DDParsers_SPIRIT_SOURCES}) -target_compile_definitions(DDParsers PUBLIC BOOST_SPIRIT_USE_PHOENIX_V3) + +target_compile_definitions(DDParsers INTERFACE + $<$<BOOL:Boost_FOUND>:BOOST_SPIRIT_USE_PHOENIX_V3> + ) target_include_directories(DDParsers PUBLIC @@ -40,12 +43,18 @@ target_include_directories(DDParsers target_include_directories(DDParsers SYSTEM PUBLIC - $<BUILD_INTERFACE:${ROOT_INCLUDE_DIRS}> - $<TARGET_PROPERTY:Boost::boost,INTERFACE_INCLUDE_DIRECTORIES> + $<TARGET_PROPERTY:ROOT::Core,INTERFACE_INCLUDE_DIRECTORIES> + $<$<BOOL:Boost_FOUND>:$<TARGET_PROPERTY:Boost::boost,INTERFACE_INCLUDE_DIRECTORIES>> ) target_link_libraries(DDParsers PUBLIC ${XML_LIBRARIES} ) -INSTALL(TARGETS DDParsers EXPORT DD4hep DESTINATION lib) \ No newline at end of file +INSTALL(TARGETS DDParsers EXPORT DD4hep DESTINATION lib) + +INSTALL(DIRECTORY + include/Parsers + include/Evaluator + DESTINATION include + ) diff --git a/DDRec/CMakeLists.txt b/DDRec/CMakeLists.txt index d582b4b31..9b0863eec 100644 --- a/DDRec/CMakeLists.txt +++ b/DDRec/CMakeLists.txt @@ -80,6 +80,12 @@ else() endif() endif() -# dd4hep_install_files(FILES python/*.py DESTINATION python) +dd4hep_install_files(FILES python/*.py DESTINATION python) -INSTALL(TARGETS DDRec EXPORT DD4hep DESTINATION lib) \ No newline at end of file +INSTALL(DIRECTORY + include/DDRec + DESTINATION include + ) + +INSTALL(TARGETS DDRec EXPORT DD4hep DESTINATION lib) +INSTALL(TARGETS DDRecPlugins DESTINATION lib) diff --git a/DDTest/CMakeLists.txt b/DDTest/CMakeLists.txt index 70920158c..479e24fcd 100644 --- a/DDTest/CMakeLists.txt +++ b/DDTest/CMakeLists.txt @@ -8,36 +8,52 @@ # For the list of contributors see $DD4hepINSTALL/doc/CREDITS. # #================================================================================= -if (DD4HEP_USE_GEANT4) - dd4hep_package( DDTest - USES DDCore DDRec - OPTIONAL DDG4 - INCLUDE_DIRS include - INSTALL_INCLUDES include/DD4hep ) -else() - dd4hep_package( DDTest - USES DDCore DDRec - INCLUDE_DIRS include - INSTALL_INCLUDES include/DD4hep ) -endif() -dd4hep_add_test_reg ( test_example BUILD_EXEC REGEX_FAIL "TEST_FAILED" ) -dd4hep_add_test_reg ( test_units BUILD_EXEC REGEX_FAIL "TEST_FAILED" - EXEC_ARGS file:${CMAKE_CURRENT_SOURCE_DIR}/units.xml ) -dd4hep_add_test_reg ( test_surface BUILD_EXEC REGEX_FAIL "TEST_FAILED" - EXEC_ARGS file:${CMAKE_CURRENT_SOURCE_DIR}/units.xml ) +foreach(TEST_NAME + test_example + test_bitfield64 + test_bitfieldcoder + test_DetType + test_PolarGridRPhi2 + test_cellDimensions + test_cellDimensionsRPhi2 + test_segmentationHandles + ) + add_executable(${TEST_NAME} src/${TEST_NAME}.cc) + target_link_libraries(${TEST_NAME} DDCore DDRec) + target_include_directories(${TEST_NAME} PRIVATE ./include) + install(TARGETS ${TEST_NAME} DESTINATION bin) -dd4hep_add_test_reg ( test_bitfield64 BUILD_EXEC REGEX_FAIL "TEST_FAILED" ) -dd4hep_add_test_reg ( test_bitfieldcoder BUILD_EXEC REGEX_FAIL "TEST_FAILED" ) -dd4hep_add_test_reg ( test_DetType BUILD_EXEC REGEX_FAIL "TEST_FAILED" ) -dd4hep_add_test_reg ( test_PolarGridRPhi2 BUILD_EXEC REGEX_FAIL "TEST_FAILED" ) -dd4hep_add_test_reg ( test_cellDimensions BUILD_EXEC REGEX_FAIL "TEST_FAILED" ) -dd4hep_add_test_reg ( test_cellDimensionsRPhi2 BUILD_EXEC REGEX_FAIL "TEST_FAILED" ) -dd4hep_add_test_reg ( test_segmentationHandles BUILD_EXEC REGEX_FAIL "TEST_FAILED" ) + set(cmd ${CMAKE_INSTALL_PREFIX}/bin/run_test.sh ${TEST_NAME}) + add_test(NAME t_${TEST_NAME} COMMAND ${cmd} ${TEST_NAME}) + set_tests_properties(t_${TEST_NAME} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST_FAILED") +endforeach() + +foreach(TEST_NAME + test_units + test_surface + ) + add_executable(${TEST_NAME} src/${TEST_NAME}.cc) + target_link_libraries(${TEST_NAME} DDCore DDRec) + target_include_directories(${TEST_NAME} PRIVATE ./include) + install(TARGETS ${TEST_NAME} DESTINATION bin) + add_test(NAME t_${TEST_NAME} + COMMAND ${CMAKE_INSTALL_PREFIX}/bin/run_test.sh ${TEST_NAME} file:${CMAKE_CURRENT_SOURCE_DIR}/units.xml) + set_tests_properties(t_${TEST_NAME} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST_FAILED") +endforeach() if (DD4HEP_USE_GEANT4) - dd4hep_add_test_reg ( test_EventReaders BUILD_EXEC REGEX_FAIL "TEST_FAILED" - EXEC_ARGS ${CMAKE_CURRENT_SOURCE_DIR} ) + foreach(TEST_NAME + test_EventReaders + ) + add_executable(${TEST_NAME} src/${TEST_NAME}.cc) + target_link_libraries(${TEST_NAME} DDCore DDRec DDG4) + target_include_directories(${TEST_NAME} PRIVATE ./include) + install(TARGETS ${TEST_NAME} DESTINATION bin) + + add_test(NAME t_${TEST_NAME} COMMAND ${CMAKE_INSTALL_PREFIX}/bin/run_test.sh ${TEST_NAME} ${CMAKE_CURRENT_SOURCE_DIR}) + set_tests_properties(t_${TEST_NAME} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST_FAILED") + endforeach(TEST_NAME) ADD_TEST( test_ddsim "${CMAKE_INSTALL_PREFIX}/bin/run_test.sh" ddsim --compactFile=${CMAKE_INSTALL_PREFIX}/DDDetectors/compact/SiD.xml --runType=batch -G -N=2 --outputFile=testSid.root diff --git a/UtilityApps/CMakeLists.txt b/UtilityApps/CMakeLists.txt index 976b670bf..d6e894795 100644 --- a/UtilityApps/CMakeLists.txt +++ b/UtilityApps/CMakeLists.txt @@ -8,66 +8,83 @@ # For the list of contributors see $DD4hepINSTALL/doc/CREDITS. # #========================================================================== -dd4hep_package(UtilityApps - USES DDCore - [ROOT REQUIRED COMPONENTS Geom] - ) -#----------------------------------------------------------------------------------- -dd4hep_add_executable( geoDisplay src/display.cpp ) +# dd4hep_package(UtilityApps +# USES DDCore +# [ROOT REQUIRED COMPONENTS Geom] +# ) #----------------------------------------------------------------------------------- -dd4hep_add_executable( geoConverter src/converter.cpp ) +add_executable(geoDisplay src/display.cpp) +target_link_libraries(geoDisplay DDCore) #----------------------------------------------------------------------------------- -dd4hep_add_executable( geoPluginRun src/plugin_runner.cpp ) +add_executable(geoConverter src/converter.cpp) +target_link_libraries(geoConverter DDCore) #----------------------------------------------------------------------------------- -dd4hep_add_executable( dumpBfield src/dumpBfield.cpp ) +add_executable(geoPluginRun src/plugin_runner.cpp) +target_link_libraries(geoPluginRun DDCore) #----------------------------------------------------------------------------------- -dd4hep_add_executable( print_materials src/print_materials.cpp USES DDRec ) +add_executable(dumpBfield src/dumpBfield.cpp) +target_link_libraries(dumpBfield DDCore) #----------------------------------------------------------------------------------- -dd4hep_add_executable( materialScan src/materialScan.cpp USES DDRec ) +add_executable(print_materials src/print_materials.cpp) +target_link_libraries(print_materials DDCore DDRec) #----------------------------------------------------------------------------------- -dd4hep_add_executable( materialBudget src/materialBudget.cpp USES DDRec ROOT ) +add_executable(materialScan src/materialScan.cpp) +target_link_libraries(materialScan ROOT::Core ROOT::Geom DDRec) #----------------------------------------------------------------------------------- -dd4hep_add_executable( graphicalScan src/graphicalScan.cpp USES DDRec ROOT ) +add_executable(materialBudget src/materialBudget.cpp) +target_link_libraries(materialBudget ROOT::Core ROOT::Geom DDRec) #----------------------------------------------------------------------------------- -#dd4hep_add_executable( pydd4hep -# USES [ROOT REQUIRED COMPONENTS PyROOT] -# OPTIONAL [PYTHON REQUIRED SOURCES src/DD4hep_python.cpp]) -#----------------------------------------------------------------------------------- -dd4hep_add_executable( dumpdetector - USES DDRec - OPTIONAL [GEANT4 REQUIRED SOURCES src/dumpdetector.cpp]) +add_executable(graphicalScan src/graphicalScan.cpp) +target_link_libraries(graphicalScan ROOT::Core ROOT::Geom DDRec) #----------------------------------------------------------------------------------- + + +if(TARGET Geant4::Interface) + add_executable(dumpdetector src/dumpdetector.cpp) + target_link_libraries(dumpdetector Geant4::Interface DDCore DDRec) +endif() + +# #----------------------------------------------------------------------------------- if(BUILD_TESTING) - dd4hep_add_executable(test_surfaces - USES DDRec DDTest - OPTIONAL [LCIO REQUIRED SOURCES src/test_surfaces.cpp]) - #----------------------------------------------------------------------------------- - dd4hep_add_executable(test_cellid_position_converter - USES DDRec DDTest - OPTIONAL [LCIO REQUIRED SOURCES src/test_cellid_position_converter.cpp]) + if(DD4HEP_USE_LCIO) + add_executable(test_surfaces src/test_surfaces.cpp) + target_link_libraries(test_surfaces DDRec DDTest LCIO::LCIO) + + add_executable(test_cellid_position_converter src/test_cellid_position_converter.cpp) + target_link_libraries(test_cellid_position_converter DDRec DDTest LCIO::LCIO) + endif() #----------------------------------------------------------------------------------- endif() -dd4hep_add_dictionary( G__eve +new_dd4hep_add_dictionary( G__eve SOURCES src/EvNavHandler.h - LINKDEF src/LinkDef.h ) + LINKDEF src/LinkDef.h + DEPENDS DDCore ROOT::Geom + ) -#----------------------------------------------------------------------------------- -if ( ${DD4HEP_USE_LCIO} ) - dd4hep_add_dictionary( G__eve1 +# #----------------------------------------------------------------------------------- +if (DD4HEP_USE_LCIO) + new_dd4hep_add_dictionary( G__eve1 SOURCES src/EvNavHandler.h - LINKDEF src/LinkDef.h ) - dd4hep_add_executable( teveLCIO - USES [ROOT REQUIRED COMPONENTS Eve Gui Graf3d RGL] - [LCIO REQUIRED] - DDRec - GENERATED G__eve1.cxx - SOURCES src/teve_display.cpp src/next_event_lcio.cpp - ) + LINKDEF src/LinkDef.h + DEPENDS DDCore ROOT::Geom + ) + add_executable(teveLCIO G__eve1.cxx src/teve_display.cpp src/next_event_lcio.cpp) + target_link_libraries(teveLCIO DDRec LCIO::LCIO ROOT::Core ROOT::Eve ROOT::Gui ROOT::Graf3d ROOT::RGL) endif() -#----------------------------------------------------------------------------------- -dd4hep_add_executable( teveDisplay - USES [ROOT REQUIRED COMPONENTS Eve Gui Graf3d RGL] DDRec - GENERATED G__eve.cxx - SOURCES src/teve_display.cpp src/next_event_dummy.cpp -) +# #----------------------------------------------------------------------------------- +add_executable(teveDisplay src/teve_display.cpp src/next_event_dummy.cpp G__eve.cxx) +target_link_libraries(teveDisplay DDRec ROOT::Core ROOT::Eve ROOT::Gui ROOT::Graf3d ROOT::RGL ) + +INSTALL(TARGETS geoDisplay + geoConverter + geoPluginRun + dumpBfield + print_materials + materialScan + materialBudget + graphicalScan + dumpdetector + teveDisplay + RUNTIME DESTINATION bin + ) \ No newline at end of file diff --git a/cmake/DD4hepConfig.cmake.in b/cmake/DD4hepConfig.cmake.in index 97c0a58a4..a676b21aa 100644 --- a/cmake/DD4hepConfig.cmake.in +++ b/cmake/DD4hepConfig.cmake.in @@ -30,23 +30,19 @@ set ( DD4HEP_USE_XERCESC "@DD4HEP_USE_XERCESC@" ) set ( DD4hep_BUILD_CXX_STANDARD @CMAKE_CXX_STANDARD@ ) # figure out if including build has compatible standard set -if("${CMAKE_CXX_STANDARD}" STREQUAL "") - set ( CMAKE_CXX_STANDARD "${DD4hep_BUILD_CXX_STANDARD}" ) -else() - if (NOT "${CMAKE_CXX_STANDARD}" EQUAL "${DD4hep_BUILD_CXX_STANDARD}") - message( SEND_ERROR "CMAKE_CXX_STANDARD is set to C++${CMAKE_CXX_STANDARD}\ - but C++${DD4hep_BUILD_CXX_STANDARD} is required for DD4hep.") - endif() +if (NOT "${CMAKE_CXX_STANDARD}" EQUAL "${DD4hep_BUILD_CXX_STANDARD}") + message( SEND_ERROR "CMAKE_CXX_STANDARD is set to C++${CMAKE_CXX_STANDARD} but C++${DD4hep_BUILD_CXX_STANDARD} is required for DD4hep.") endif() + -set ( CMAKE_CXX_STANDARD_REQUIRED ON ) -set ( CMAKE_CXX_EXTENSIONS OFF ) -set ( Geant4_DIR "@Geant4_DIR@" ) -set ( GEANT4_USE_CLHEP "@GEANT4_USE_CLHEP@" ) +# set ( CMAKE_CXX_STANDARD_REQUIRED ON ) +# set ( CMAKE_CXX_EXTENSIONS OFF ) +# set ( Geant4_DIR "@Geant4_DIR@" ) +# set ( GEANT4_USE_CLHEP "@GEANT4_USE_CLHEP@" ) -set ( ROOTSYS "$ENV{ROOTSYS}" ) -set ( ROOT_DIR "$ENV{ROOTSYS}/cmake" ) -set ( ROOT_VERSION "@ROOT_VERSION@" ) +# set ( ROOTSYS "$ENV{ROOTSYS}" ) +# set ( ROOT_DIR "$ENV{ROOTSYS}/cmake" ) +# set ( ROOT_VERSION "@ROOT_VERSION@" ) include ( ${DD4hep_DIR}/cmake/DD4hep.cmake ) @@ -54,45 +50,64 @@ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${DD4hep_DIR}/cmake ) # ---------- include dirs ----------------------------------------------------- # do not store find results in cache -set( DD4hep_INCLUDE_DIRS DD4hep_INCLUDE_DIRS-NOTFOUND ) - -mark_as_advanced( DD4hep_INCLUDE_DIRS ) - -find_path( DD4hep_INCLUDE_DIRS - NAMES DD4hep/DetElement.h - PATHS ${DD4hep_DIR}/include - NO_DEFAULT_PATH -) +set(DD4hep_INCLUDE_DIRS "") # ---------- default build type -------------------------------------------------------- if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "One of: None Debug Release RelWithDebInfo MinSizeRel." FORCE) endif() + +FIND_PACKAGE(Boost REQUIRED) +SET_TARGET_PROPERTIES(Boost::boost + PROPERTIES + INTERFACE_COMPILE_DEFINITIONS BOOST_SPIRIT_USE_PHOENIX_V3 + ) + +FIND_PACKAGE(ROOT REQUIRED) +DD4HEP_SETUP_ROOT_TARGETS() + +find_package(Geant4 10.2.2 REQUIRED COMPONENTS gdml ui_all vis_all) +DD4HEP_SETUP_GEANT4_TARGETS() + +if(NOT CMAKE_PROJECT_NAME STREQUAL DD4hep) + include("${DD4hep_ROOT}/lib/DD4hepConfig-targets.cmake") +endif() + +# ---------- include dirs ----------------------------------------------------- +# do not store find results in cache +GET_TARGET_PROPERTY(DD4hep_INCLUDE_DIRS DD4hep::DDCore INTERFACE_INCLUDE_DIRECTORIES) +MESSAGE(STATUS "include dirs ${DD4hep_INCLUDE_DIRS}") + + +#---------------------------------------------------------------------------- +# Setup components and options +set(_dd4hep_options ) + +foreach(_opt ${_root_options}) + set(DD4hep_${_opt}_FOUND TRUE) +endforeach() + + + # ---------- libraries -------------------------------------------------------- # do not store find results in cache -set( DD4hep_LIBRARY_DIRS ${DD4hep_DIR}/lib ) -set( DD4hep_LIBRARIES DD4hep_LIBRARIES-NOTFOUND ) -mark_as_advanced( DD4hep_LIBRARY_DIRS DD4hep_LIBRARIES ) +#set( DD4hep_LIBRARY_DIRS ${DD4hep_DIR}/lib ) +#set( DD4hep_LIBRARIES DD4hep_LIBRARIES-NOTFOUND ) +#mark_as_advanced( DD4hep_LIBRARY_DIRS DD4hep_LIBRARIES ) + +set(DD4hep_LIBRARIES DD4hep::DDParsers DD4hep::DDCore DD4hep::DDRec) include( ${DD4hep_DIR}/cmake/DD4hepMacros.cmake ) # only standard libraries should be passed as arguments to CHECK_PACKAGE_LIBS # additional components are set by cmake in variable PKG_FIND_COMPONENTS # first argument should be the package name -if ( ${DD4HEP_USE_GEANT4} ) - #--- if geant 4 was built with CLHEP we need to export this to client packages - if( ${GEANT4_USE_CLHEP} ) - set( GEANT4_USE_CLHEP 1 ) - endif() - set(Geant4_DIR ${Geant4_DIR} ) -endif() CHECK_PACKAGE_LIBS(DD4hep DDCore) IF(DD4hep_FIND_COMPONENTS) dd4hep_print( "|++> DD4hep: Looking for Components: ${DD4hep_FIND_COMPONENTS}" ) - FOREACH(comp ${DD4hep_FIND_COMPONENTS}) #CHECK_PACKAGE_LIBS is looking for components too, just need to check if they were found, if requested STRING( TOUPPER ${comp} _ulibname ) diff --git a/cmake/DD4hep_XML_setup.cmake b/cmake/DD4hep_XML_setup.cmake index b9a10f79c..633855ca8 100644 --- a/cmake/DD4hep_XML_setup.cmake +++ b/cmake/DD4hep_XML_setup.cmake @@ -7,7 +7,9 @@ if(DD4HEP_USE_XERCESC) ) set(XML_LIBRARIES XercesC::XercesC) else() - set ( DD4HEP_USE_XERCESC OFF ) - add_definitions(-DDD4HEP_USE_TINYXML) - set(XML_LIBRARIES) + set(DD4HEP_USE_XERCESC OFF) + ADD_LIBRARY(TinyXML INTERFACE) + TARGET_COMPILE_DEFINITIONS(TinyXML INTERFACE DD4HEP_USE_TINYXML) + set(XML_LIBRARIES TinyXML) + INSTALL(TARGETS TinyXML EXPORT DD4hep DESTINATION lib) endif() -- GitLab