Skip to content

Commit

Permalink
CMake: add settings DD4HEP_BUILD_PACKAGES to chose which packages to …
Browse files Browse the repository at this point in the history
…build, DD4HEP_BUILD_EXAMPLES to build examples

it will be the responsible of the user to chose a working combination and order of packages
Use DD4hep::<Package> so that cmake will fail if required package was not enabled
  • Loading branch information
andresailer committed Aug 30, 2019
1 parent 89a7f3f commit 58b74a1
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 71 deletions.
39 changes: 24 additions & 15 deletions CMakeLists.txt
Expand Up @@ -52,6 +52,8 @@ set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard used for compiling")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

SET(DD4hep_DIR ${CMAKE_SOURCE_DIR} CACHE STRING "DD4hep directory")

IF(${CMAKE_CXX_STANDARD} LESS 14)
MESSAGE(FATAL_ERROR "DD4hep requires at least CXX Standard 14 to compile")
ENDIF()
Expand All @@ -67,6 +69,13 @@ option(DD4HEP_USE_GEAR "Build gear wrapper for backward compatibility" OFF)
option(DD4HEP_USE_LCIO "Build lcio extensions" OFF)
option(BUILD_TESTING "Enable and build tests" ON)
option(CMAKE_MACOSX_RPATH "Build with rpath on macos" ON)
SET(DD4HEP_BUILD_PACKAGES "DDRec DDDetectors DDCond DDAlign DDDigi DDG4 DDEve UtilityApps"
CACHE STRING "List of DD4hep packages to build")
SEPARATE_ARGUMENTS(DD4HEP_BUILD_PACKAGES)
MESSAGE(STATUS "Will be building these packages: ${DD4HEP_BUILD_PACKAGES}")

OPTION(DD4HEP_BUILD_EXAMPLES "Build all the examples" OFF)
OPTION(DD4HEP_DEBUG_CMAKE "Print debugging information for DD4hep CMAKE" OFF)

#####################
# Configure version #
Expand Down Expand Up @@ -124,9 +133,6 @@ dd4hep_set_compiler_flags()
####################
# Include packages #
####################

add_subdirectory ( GaudiPluginService )

include(DD4hep)
include(DD4hepMacros)

Expand All @@ -135,23 +141,26 @@ if( DEFINED DD4HEP_WITH_GEANT4 OR DEFINED DD4HEP_WITH_GEAR )
endif()

include(DD4hep_XML_setup)
add_subdirectory(DDParsers)
add_subdirectory(DDCore)
add_subdirectory(DDRec)
add_subdirectory(DDDetectors)
add_subdirectory(DDCond)
add_subdirectory(DDAlign)
add_subdirectory(DDDigi)
add_subdirectory(DDG4)

# Note the order: DDEve partially depends on variables from DDG4!
add_subdirectory(DDEve)

#These pacakges are mandatory
FOREACH(DDPackage GaudiPluginService DDParsers DDCore)
dd4hep_print("|> Building ${DDPackage}")
add_subdirectory(${DDPackage})
ENDFOREACH()

FOREACH(DDPackage IN LISTS DD4HEP_BUILD_PACKAGES)
dd4hep_print("|> Building ${DDPackage}")
add_subdirectory(${DDPackage})
ENDFOREACH()

if(BUILD_TESTING)
dd4hep_enable_tests()
add_subdirectory(DDTest)
endif()
add_subdirectory(UtilityApps)

if(DD4HEP_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

#######################
# Treatment for Apple #
Expand Down
1 change: 1 addition & 0 deletions DDAlign/CMakeLists.txt
Expand Up @@ -13,6 +13,7 @@ SET_PROPERTY(DIRECTORY . PROPERTY PACKAGE_NAME DDAlign)
file(GLOB DDAlign_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)

add_library(DDAlign SHARED ${DDAlign_SOURCES})
add_library(DD4hep::DDAlign ALIAS DDAlign)

target_include_directories(DDAlign
PUBLIC
Expand Down
7 changes: 4 additions & 3 deletions DDCond/CMakeLists.txt
Expand Up @@ -13,24 +13,25 @@ SET_PROPERTY(DIRECTORY . PROPERTY PACKAGE_NAME DDCond)
dd4hep_add_dictionary(G__DDCond
SOURCES ../DDCore/include/ROOT/Warnings.h src/ConditionsDictionary.h
LINKDEF ../DDCore/include/ROOT/LinkDef.h
USES DDCore DDParsers
USES DD4hep::DDCore DD4hep::DDParsers
)

file(GLOB DDCond_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)

add_library(DDCond SHARED ${DDCond_SOURCES} G__DDCond.cxx)
add_library(DD4hep::DDCond ALIAS DDCond)

target_include_directories(DDCond
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:include>
)

target_link_libraries(DDCond PUBLIC DDCore)
target_link_libraries(DDCond PUBLIC DD4hep::DDCore)

dd4hep_add_plugin(DDCondPlugins
SOURCES src/plugins/*.cpp src/Type1/*.cpp
USES DDCond
USES DD4hep::DDCond
)

set_target_properties(DDCond DDCondPlugins PROPERTIES VERSION ${DD4hep_VERSION} SOVERSION ${DD4hep_SOVERSION})
Expand Down
7 changes: 4 additions & 3 deletions DDCore/CMakeLists.txt
Expand Up @@ -64,6 +64,7 @@ add_library(DDCore SHARED ${DDCore_SOURCES} ${DDCore_BOOST_SOURCES}
G__DD4hepProperties.cxx
G__DD4hepGeo.cxx
)
add_library(DD4hep::DDCore ALIAS DDCore)

target_include_directories(DDCore
PUBLIC
Expand All @@ -73,8 +74,8 @@ target_include_directories(DDCore

target_link_libraries(DDCore
PUBLIC
DD4hepGaudiPluginMgr
DDParsers
DD4hep::DD4hepGaudiPluginMgr
DD4hep::DDParsers
ROOT::Core ROOT::Rint ROOT::Tree ROOT::Physics ROOT::Geom ROOT::GenVector
${XML_LIBRARIES}
)
Expand All @@ -94,7 +95,7 @@ IF(TARGET ROOT::Gdml)
dd4hep_print("|++> Found Root::GDML: Creating DDGDMLPlugins")
dd4hep_add_plugin(DDGDMLPlugins
SOURCES src/gdml/*.cpp
USES DDCore ROOT::Core ROOT::Gdml
USES DD4hep::DDCore ROOT::Core ROOT::Gdml
)
set_target_properties(DDGDMLPlugins PROPERTIES VERSION ${DD4hep_VERSION} SOVERSION ${DD4hep_SOVERSION})
install(TARGETS DDGDMLPlugins EXPORT DD4hep LIBRARY DESTINATION lib)
Expand Down
2 changes: 1 addition & 1 deletion DDDetectors/CMakeLists.txt
Expand Up @@ -20,7 +20,7 @@ SET_PROPERTY(DIRECTORY . PROPERTY PACKAGE_NAME DDDetectors)

dd4hep_add_plugin(DDDetectors
SOURCES src/*.cpp
USES DDRec
USES DD4hep::DDRec
INCLUDES $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

Expand Down
7 changes: 4 additions & 3 deletions DDDigi/CMakeLists.txt
Expand Up @@ -11,9 +11,10 @@
SET_PROPERTY(DIRECTORY . PROPERTY PACKAGE_NAME DDDigi)
file(GLOB DDDigi_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
add_library(DDDigi SHARED ${DDDigi_SOURCES})
add_library(DD4hep::DDDigi ALIAS DDDigi)

target_link_libraries(DDDigi PUBLIC
DDCore Boost::boost ROOT::Core ROOT::Geom ROOT::GenVector ROOT::RIO)
DD4hep::DDCore Boost::boost ROOT::Core ROOT::Geom ROOT::GenVector ROOT::RIO)

target_include_directories(DDDigi
PUBLIC
Expand All @@ -37,13 +38,13 @@ endif()
dd4hep_add_dictionary(G__DDDigi
SOURCES ../DDCore/include/ROOT/Warnings.h python/DDDigiDict.C
LINKDEF ../DDCore/include/ROOT/LinkDef.h
USES DDCore ROOT::Core ROOT::Geom ROOT::GenVector ROOT::RIO Boost::boost
USES DD4hep::DDCore ROOT::Core ROOT::Geom ROOT::GenVector ROOT::RIO Boost::boost
)
#--------------------------- Plugin library for the digitization framework -------
dd4hep_add_plugin(DDDigiPlugins
SOURCES plugins/*.cpp
GENERATED G__DDDigi.cxx
USES DDDigi
USES DD4hep::DDDigi
)

#---Package installation procedure(s) ----------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions DDEve/CMakeLists.txt
Expand Up @@ -11,6 +11,7 @@
SET_PROPERTY(DIRECTORY . PROPERTY PACKAGE_NAME DDEve)

add_library(DDEve_Interface INTERFACE)
add_library(DD4hep::DDEve_Interface ALIAS DDEve_Interface)
target_include_directories(DDEve_Interface
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand All @@ -25,7 +26,7 @@ dd4hep_add_dictionary(G__DDEve
include/DDEve/HitActors.h
include/DDEve/Factories.h
LINKDEF ../DDCore/include/ROOT/LinkDef.h
USES DDCore
USES DD4hep::DDCore
)

if(TARGET LCIO::LCIO)
Expand All @@ -35,17 +36,17 @@ endif()

dd4hep_add_plugin(DDEvePlugins SOURCES src/*.cpp ${DDEVE_LCIO_SOURCES}
GENERATED G__DDEve.cxx
USES DDCore DDEve_Interface ${DDEVE_LCIO_LINK}
USES DD4hep::DDCore DD4hep::DDEve_Interface ${DDEVE_LCIO_LINK}
)

if(DD4HEP_USE_GEANT4)
dd4hep_add_dictionary(G__DDG4IO
SOURCES ../DDCore/include/ROOT/Warnings.h DDEve/DDG4IO.C
LINKDEF ../DDCore/include/ROOT/LinkDef.h
USES DDG4
USES DD4hep::DDG4
)
add_library(DDG4IO SHARED DDEve/IO.cpp G__DDG4IO.cxx)
target_link_libraries(DDG4IO DDG4 DDEve_Interface)
target_link_libraries(DDG4IO DD4hep::DDG4 DD4hep::DDEve_Interface)
set_target_properties(DDG4IO PROPERTIES VERSION ${DD4hep_VERSION} SOVERSION ${DD4hep_SOVERSION})
install(TARGETS DDG4IO EXPORT DD4hep LIBRARY DESTINATION lib)
endif()
Expand Down
20 changes: 11 additions & 9 deletions DDG4/CMakeLists.txt
Expand Up @@ -12,17 +12,18 @@ SET_PROPERTY(DIRECTORY . PROPERTY PACKAGE_NAME DDG4)

# configure Geant4
IF(NOT DD4HEP_USE_GEANT4)
dd4hep_print("Not Using geant4, not building DDG4")
dd4hep_print("|++> Not Using geant4, not building DDG4")
RETURN()
ENDIF()

#---Add Library---------------------------------------------------------------------
file(GLOB DDG4_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
add_library(DDG4 SHARED ${DDG4_SOURCES})
add_library(DD4hep::DDG4 ALIAS DDG4)

target_link_libraries(DDG4
PUBLIC
DDCore
DD4hep::DDCore
Geant4::Interface
)

Expand All @@ -38,13 +39,13 @@ dd4hep_add_plugin(DDG4Legacy SOURCES legacy/*.cpp USES DDG4)
#-----------------------------------------------------------------------------------
dd4hep_add_dictionary( G__DDG4
SOURCES python/DDG4Dict.C
USES DDCore DDParsers DDG4 Geant4::Interface
USES DD4hep::DDCore DD4hep::DDParsers DD4hep::DDG4 Geant4::Interface
)
#--------------------------- Plugin library for the simulation framework ---------
dd4hep_add_plugin(DDG4Plugins
SOURCES plugins/*.cpp
GENERATED G__DDG4.cxx
USES ROOT::Core ${CLHEP} DDG4 ${XML_LIBRARIES} DDParsers
USES DD4hep::DDG4 DD4hep::DDParsers ${XML_LIBRARIES} ROOT::Core ${CLHEP}
)
#--------------------------- Plugin library for the simulation framework ---------

Expand All @@ -54,7 +55,7 @@ if(TARGET Python2::Python)
dd4hep_print("|++> Python found, creating DDG4Python Dictionary")
dd4hep_add_dictionary(G__DDG4Python
SOURCES src/python/DDG4Python.C
USES DDCore DDParsers DDG4 ROOT::Core Geant4::Interface
USES DD4hep::DDCore DD4hep::DDParsers DD4hep::DDG4 ROOT::Core Geant4::Interface
)
dd4hep_add_dictionary(G__DDPython
SOURCES tpython/DDPython.C
Expand All @@ -64,19 +65,20 @@ if(TARGET Python2::Python)
#--------------------------- Specialized python plugins --------------------------
dd4hep_print("|++> ROOT Has Python, creating DDPython library and plugins")
add_library(DDPython SHARED G__DDPython.cxx tpython/DDPython.cpp)
target_link_libraries(DDPython DDG4 ROOT::Core Python2::Python ROOT::PyROOT)
add_library(DD4hep::DDPython ALIAS DDPython)
target_link_libraries(DDPython DD4hep::DDG4 ROOT::Core Python2::Python ROOT::PyROOT)
IF(${CMAKE_CXX_STANDARD} GREATER 16)
# python header not cxx17 compatible, gives error in clang
target_compile_options(DDPython PUBLIC -Wno-register)
ENDIF()
dd4hep_add_plugin(DDG4Python
SOURCES src/python/*.cpp
GENERATED G__DDG4Python.cxx
USES DDG4 DDPython
USES DD4hep::DDG4 DD4hep::DDPython
)
#---Helper to overcome deficiency of the python executable concerning multi-threading
add_executable(pyddg4 pyddg4.cpp)
target_link_libraries(pyddg4 PUBLIC DDPython ROOT::Core ROOT::PyROOT)
target_link_libraries(pyddg4 PUBLIC DD4hep::DDPython ROOT::Core ROOT::PyROOT)

# install these libraries
set_target_properties(DDPython DDG4Python PROPERTIES VERSION ${DD4hep_VERSION} SOVERSION ${DD4hep_SOVERSION})
Expand All @@ -93,7 +95,7 @@ endif()
IF(TARGET LCIO::LCIO)
dd4hep_add_plugin(DDG4LCIO
SOURCES lcio/*.cpp
USES DDG4 LCIO::LCIO
USES DD4hep::DDG4 LCIO::LCIO
)
install(TARGETS DDG4LCIO EXPORT DD4hep LIBRARY DESTINATION lib)
set_target_properties(DDG4LCIO PROPERTIES VERSION ${DD4hep_VERSION} SOVERSION ${DD4hep_SOVERSION})
Expand Down
1 change: 1 addition & 0 deletions DDParsers/CMakeLists.txt
Expand Up @@ -16,6 +16,7 @@ file(GLOB DDParsers_SOURCES src/Parsers/*.cpp src/Evaluator/*.cpp)
file(GLOB DDParsers_SPIRIT_SOURCES src/Spirit/*.cpp)

add_library(DDParsers SHARED ${DDParsers_SOURCES} ${DDParsers_SPIRIT_SOURCES})
add_library(DD4hep::DDParsers ALIAS DDParsers)

target_compile_definitions(DDParsers INTERFACE BOOST_SPIRIT_USE_PHOENIX_V3)

Expand Down
1 change: 1 addition & 0 deletions DDRec/CMakeLists.txt
Expand Up @@ -32,6 +32,7 @@ ADD_LIBRARY(DDRec SHARED
${GEAR_SOURCE_FILE}
G__DDRec.cxx
)
ADD_LIBRARY(DD4hep::DDRec ALIAS DDRec)

TARGET_INCLUDE_DIRECTORIES(DDRec
PUBLIC
Expand Down
8 changes: 5 additions & 3 deletions DDTest/CMakeLists.txt
Expand Up @@ -10,6 +10,8 @@
#=================================================================================

add_library(DDTest INTERFACE)
add_library(DD4hep::DDTest ALIAS DDTest)

target_include_directories(DDTest INTERFACE include)

foreach(TEST_NAME
Expand All @@ -23,7 +25,7 @@ foreach(TEST_NAME
test_segmentationHandles
)
add_executable(${TEST_NAME} src/${TEST_NAME}.cc)
target_link_libraries(${TEST_NAME} DDCore DDRec DDTest)
target_link_libraries(${TEST_NAME} DD4hep::DDCore DD4hep::DDRec DD4hep::DDTest)
install(TARGETS ${TEST_NAME} RUNTIME DESTINATION bin)

set(cmd ${CMAKE_INSTALL_PREFIX}/bin/run_test.sh ${TEST_NAME})
Expand All @@ -36,7 +38,7 @@ foreach(TEST_NAME
test_surface
)
add_executable(${TEST_NAME} src/${TEST_NAME}.cc)
target_link_libraries(${TEST_NAME} DDCore DDRec DDTest)
target_link_libraries(${TEST_NAME} DD4hep::DDCore DD4hep::DDRec DD4hep::DDTest)
install(TARGETS ${TEST_NAME} RUNTIME 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)
Expand All @@ -48,7 +50,7 @@ if (DD4HEP_USE_GEANT4)
test_EventReaders
)
add_executable(${TEST_NAME} src/${TEST_NAME}.cc)
target_link_libraries(${TEST_NAME} DDCore DDRec DDG4)
target_link_libraries(${TEST_NAME} DD4hep::DDCore DD4hep::DDRec DD4hep::DDG4)
target_include_directories(${TEST_NAME} PRIVATE ./include)
install(TARGETS ${TEST_NAME} DESTINATION bin)

Expand Down
2 changes: 2 additions & 0 deletions GaudiPluginService/CMakeLists.txt
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

project(GaudiPluginService)
add_library(DD4hepGaudiPluginMgr SHARED src/PluginServiceV1.cpp src/PluginServiceV2.cpp interface/DD4hepV1.cpp interface/DD4hepV2.cpp)
add_library(DD4hep::DD4hepGaudiPluginMgr ALIAS DD4hepGaudiPluginMgr)

target_compile_definitions(DD4hepGaudiPluginMgr PUBLIC Gaudi=DD4hep_Flavor)

target_include_directories(DD4hepGaudiPluginMgr PUBLIC
Expand Down

0 comments on commit 58b74a1

Please sign in to comment.