Newer
Older
file ( GLOB sources ${ARG_SOURCES} )
list ( APPEND sources ${optional_sources} )
if ( NOT "${ARG_GENERATED}" STREQUAL "" )
#
# root-cint produces warnings of type 'unused-function' disable them on generated files
foreach ( f in ${ARG_GENERATED} )
set_source_files_properties( ${f} PROPERTIES COMPILE_FLAGS -Wno-unused-function GENERATED TRUE )
endforeach()
list ( APPEND sources ${ARG_GENERATED} )
#
if ( NOT "${sources}" STREQUAL "" )
dd4hep_make_unique_list ( sources VALUES ${sources} )
dd4hep_debug( "${tag} ${sources}")
#
dd4hep_include_directories( "${pkg_incs}" )
add_definitions ( ${pkg_defs} )
#
add_library ( ${binary} SHARED ${sources} )
target_link_libraries ( ${binary} ${pkg_libs} )
if ( "${${pkg}_VERSION}" STREQUAL "" OR "${${pkg}_SOVERSION}" STREQUAL "" )
dd4hep_fatal ( "BAD Package versions: VERSION[${pkg}_VERSION] ${${pkg}_VERSION} SOVERSION[${pkg}_SOVERSION] ${${pkg}_SOVERSION} " )
##dd4hep_print ( "set_target_properties ( ${binary} PROPERTIES VERSION ${${pkg}_VERSION} SOVERSION ${${pkg}_SOVERSION})")
set_target_properties ( ${binary} PROPERTIES VERSION ${${pkg}_VERSION} SOVERSION ${${pkg}_SOVERSION})
#
install ( TARGETS ${binary}
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
set ( building_binary "ON" )
else()
dd4hep_print ( "|++> ${tag} Skipped. No sources to be compiled [Use constraint]" )
endif()
endif()
set ( ${building} ${building_binary} PARENT_SCOPE )
endfunction(dd4hep_add_library)
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
#---------------------------------------------------------------------------------------------------
# dd4hep_add_regular_library
#
# Arguments -> See function dd4hep_add_library
#
# \author M.Frank
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
function( dd4hep_add_regular_library library )
dd4hep_package_properties( pkg PKG enabled )
set ( tag "Package library[${pkg}] -> ${library}" )
if ( "${enabled}" STREQUAL "OFF" )
dd4hep_skipmsg ( "${tag} DISBALED -- package is not built!" )
else()
dd4hep_add_library( ${library} building ${ARGN} PRINT ${tag} )
if ( "${building}" STREQUAL "ON" )
dd4hep_debug ( "add_package_library -> ${library} ${PKG}_LIBRARIES:${pkg_libs}" )
else()
dd4hep_fatal ( "Package library[${pkg}] -> ${binary} Cannot be built! This is an ERROR condition." )
endif()
endif()
endfunction(dd4hep_add_regular_library)
#---------------------------------------------------------------------------------------------------
# dd4hep_add_package_library
#
# Package libraries are automatically added to the package's link libraries.
# Package plugins and plugins depending on a package automically link against
# these libraries.
#
# Arguments -> See function dd4hep_add_library
#
# \author M.Frank
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
function( dd4hep_add_package_library library )
dd4hep_package_properties( pkg PKG enabled )
set ( tag "Package library[${pkg}] -> ${library}" )
if ( "${enabled}" STREQUAL "OFF" )
dd4hep_skipmsg ( "${tag} DISBALED -- package is not built!" )
dd4hep_add_library( ${library} building ${ARGN} PRINT ${tag} )
if ( "${building}" STREQUAL "ON" )
get_property(pkg_libs GLOBAL PROPERTY PROPERTY ${PKG}_LIBRARIES )
dd4hep_make_unique_list ( pkg_libs VALUES ${pkg_libs} ${library} )
set_property(GLOBAL PROPERTY ${PKG}_LIBRARIES ${pkg_libs} )
# Test and print if correct
get_property(pkg_libs GLOBAL PROPERTY PROPERTY ${PKG}_LIBRARIES )
dd4hep_debug ( "add_package_library -> ${library} ${PKG}_LIBRARIES:${pkg_libs}" )
else()
dd4hep_fatal ( "Package library[${pkg}] -> ${binary} Cannot be built! This is an ERROR condition." )
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
endif()
endfunction(dd4hep_add_package_library)
#---------------------------------------------------------------------------------------------------
#
# dd4hep_add_plugin
#
# Arguments
# ---------
# binary -> plugin name
# SOURCES -> list of source files. Will be expanded to absolute names
#
# The following variables EXTEND the package defaults
# INCLUDE_DIRS -> Additional include directories need to compile the binary
# LINK_LIBRARIES -> Additional libraries needed to link the binary
# USES -> Required package dependencies
# OPTIONAL -> Optional package dependency
# if required e.g. [LCIO REQUIRED SOURCES aaa.cpp] the plugin will NOT be built
# else e.g. [LCIO SOURCES aaa.cpp] the plugin will be built, but
# the source files will be omitted.
# DEFINITIONS -> Optional compiler definitions to compile the sources
#
# \author M.Frank
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
function( dd4hep_add_plugin binary )
dd4hep_package_properties( pkg PKG enabled )
set ( tag "Plugin[${pkg}] -> ${binary}" )
if ( "${enabled}" STREQUAL "OFF" )
dd4hep_skipmsg ( "${tag} DISBALED -- package is not built!" )
else()
cmake_parse_arguments(ARG "" "" "SOURCES;GENERATED;LINK_LIBRARIES;INCLUDE_DIRS;USES;OPTIONAL;DEFINITIONS" ${ARGN})
get_property(pkg_lib GLOBAL PROPERTY ${PKG}_LIBRARIES )
dd4hep_add_library( ${binary} building
PRINT ${tag}
SOURCES ${ARG_SOURCES}
GENERATED ${ARG_GENERATED}
LINK_LIBRARIES ${ARG_LINK_LIBRARIES} ${pkg_lib}
INCLUDE_DIRS ${ARG_INCLUDE_DIRS}
USES ${ARG_USES}
OPTIONAL "${ARG_OPTIONAL}"
DEFINITIONS ${ARG_DEFINITIONS} )
#
# Generate ROOTMAP if the plugin will be built:
if ( "${building}" STREQUAL "ON" )
dd4hep_generate_rootmap( ${binary} )
endif()
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
endif()
endfunction(dd4hep_add_plugin)
#---------------------------------------------------------------------------------------------------
# dd4hep_add_executable
#
# Arguments
# ---------
# binary -> plugin name
# SOURCES -> list of source files. Will be expanded to absolute names
#
# The following variables EXTEND the package defaults
# INCLUDE_DIRS -> Additional include directories need to compile the binary
# LINK_LIBRARIES -> Additional libraries needed to link the binary
# USES -> Required package dependencies
# OPTIONAL -> Optional package dependency
# if required e.g. [LCIO REQUIRED SOURCES aaa.cpp] the plugin will NOT be built
# else e.g. [LCIO SOURCES aaa.cpp] the plugin will be built, but
# the source files will be omitted.
# DEFINITIONS -> Optional compiler definitions to compile the sources
#
# \author M.Frank
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
function ( dd4hep_add_executable binary )
set ( tag "Executable[${pkg}] -> ${binary}" )
dd4hep_skipmsg ( "${tag} DISBALED -- package is not built!" )
cmake_parse_arguments ( ARG "" "" "SOURCES;GENERATED;LINK_LIBRARIES;INCLUDE_DIRS;USES;OPTIONAL" ${ARGN})
dd4hep_debug( "+------------------------------------------- <<<< EXECUTABLE ${pkg}:${binary} >>>> Version: ${${pkg}_VERSION}" )
if ( NOT "${ARG_OPTIONAL}" STREQUAL "" )
dd4hep_handle_optional_sources ( ${tag} "${ARG_OPTIONAL}" optional_missing optional_uses optional_sources )
endif()
#
if ( NOT "${optional_missing}" STREQUAL "" )
dd4hep_print ( "|++> ${tag} SKIPPED. Missing optional dependencies: ${optional_missing}" )
else()
set ( uses ${ARG_USES} ${optional_uses} )
dd4hep_use_package ( ${tag} PACKAGE LOCAL
USES "${uses}"
OPTIONAL "${ARG_OPTIONAL}" )
if ( "${LOCAL_MISSING}" STREQUAL "" )
dd4hep_debug ( "${tag} Executable uses: ${ARG_USES} -- ${uses}" )
dd4hep_debug ( "${tag} Executable optional: ${ARG_OPTIONAL}" )
#
get_property ( pkg_library GLOBAL PROPERTY ${PKG}_LIBRARIES )
#
# Sources may also be supplied without argument tag:
if( "${ARG_SOURCES}" STREQUAL "")
set ( ARG_SOURCES ${ARG_UNPARSED_ARGUMENTS} )
endif()
# Prepare flags for cint generated sources:
foreach ( f in ${ARG_GENERATED} )
set_source_files_properties( ${f} PROPERTIES COMPILE_FLAGS -Wno-unused-function GENERATED TRUE )
endforeach()
#
set ( sources ${ARG_GENERATED} ${ARG_SOURCES} ${optional_sources} )
if( NOT "${sources}" STREQUAL "")
set (incs ${LOCAL_INCLUDE_DIRS} ${ARG_INCLUDE_DIRS} )
set (libs ${pkg_library} ${LOCAL_LINK_LIBRARIES} ${ARG_LINK_LIBRARIES} )
dd4hep_make_unique_list ( incs VALUES ${incs} )
dd4hep_make_unique_list ( libs VALUES ${libs} )
dd4hep_make_unique_list ( sources VALUES ${sources} )
#
dd4hep_debug ( "${tag} Libs:${libs}" )
dd4hep_include_directories( "${incs}" )
add_executable( ${binary} ${sources} )
target_link_libraries( ${binary} ${libs} )
#
# Install the binary to the destination directory
install(TARGETS ${binary}
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin )
else()
dd4hep_print ( "|++> ${tag} SKIPPED. No sources to build [Use constraint]" )
dd4hep_fatal ( "${tag} SKIPPED. Missing dependencies: ${LOCAL_MISSING}" )
endif()
endif()
endif()
endfunction(dd4hep_add_executable)
#---------------------------------------------------------------------------------------------------
# dd4hep_add_dictionary
#
#
# \author M.Frank
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
function( dd4hep_add_dictionary dictionary )
set ( tag "Dictionary[${pkg}] -> ${dictionary}" )
dd4hep_skipmsg ( "${tag} DISBALED -- package is not built!" )
cmake_parse_arguments(ARG "" "" "SOURCES;EXCLUDE;LINKDEF;OPTIONS;OPTIONAL;INCLUDES" ${ARGN} )
dd4hep_print ( "|++> ${tag} Building dictionary ..." )
if("${ARG_LINKDEF}" STREQUAL "")
set(ARG_LINKDEF "${CMAKE_SOURCE_DIR}/DDCore/include/ROOT/LinkDef.h")
endif()
#
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
if ( NOT "${ARG_OPTIONAL}" STREQUAL "" )
dd4hep_handle_optional_sources ( ${tag} "${ARG_OPTIONAL}" optional_missing optional_uses optional_sources )
endif()
#
if ( NOT "${optional_missing}" STREQUAL "" )
dd4hep_print ( "|++> ${tag} SKIPPED. Missing optional dependencies: ${optional_missing}" )
else()
set ( uses ${ARG_USES} ${optional_uses} )
dd4hep_use_package ( ${tag} PACKAGE LOCAL
USES "${uses}"
OPTIONAL "${ARG_OPTIONAL}" )
endif()
if ( NOT "${LOCAL_MISSING}" STREQUAL "" )
dd4hep_print ( "|++> ${tag} skipped. Missing dependency: ${missing} --> FATAL ERROR. Build should fail!" )
endif()
#
get_property(incs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY PACKAGE_INCLUDE_DIRS)
get_property(defs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS)
get_property(opts DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_OPTIONS)
dd4hep_make_unique_list( incs VALUES ${LOCAL_INCLUDE_DIRS} ${incs} )
dd4hep_make_unique_list( defs VALUES ${LOCAL_DEFINITIONS} ${defs} )
#
file( GLOB headers ${ARG_SOURCES} )
file( GLOB excl_headers ${ARG_EXCLUDE} )
foreach( f ${excl_headers} )
list( REMOVE_ITEM headers ${f} )
endforeach()
#
set ( inc_dirs -I${CMAKE_CURRENT_SOURCE_DIR}/include )
foreach ( inc ${ARG_INCLUDES} )
set ( inc_dirs ${inc_dirs} -I${inc} )
endforeach()
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
foreach ( inc ${incs} )
file ( GLOB inc ${inc} )
set ( inc_dirs ${inc_dirs} -I${inc} )
endforeach()
#
file ( GLOB linkdefs ${ARG_LINKDEF} )
#
set ( comp_defs )
foreach ( def ${defs} )
set ( comp_defs ${comp_defs} -D${def} )
endforeach()
#
dd4hep_make_unique_list ( sources VALUES ${headers} )
dd4hep_make_unique_list ( linkdefs VALUES ${linkdefs} )
dd4hep_make_unique_list ( inc_dirs VALUES ${inc_dirs} )
dd4hep_make_unique_list ( comp_defs VALUES ${comp_defs} )
#
dd4hep_debug ( "${tag} Linkdef: '${linkdefs}'" )
dd4hep_debug ( "${tag} Compile: '${comp_defs};${inc_dirs}'" )
dd4hep_debug ( "${tag} Files: '${headers}'" )
dd4hep_debug ( "${tag} Unparsed:'${ARG_UNPARSED_ARGUMENTS}'" )
dd4hep_debug ( "${tag} Sources: '${CMAKE_CURRENT_SOURCE_DIR}'" )
#
Marko Petric
committed
add_custom_command(OUTPUT ${dictionary}.cxx
COMMAND ${ROOT_rootcling_CMD} -cint -f ${dictionary}.cxx
-s ${CMAKE_CURRENT_BINARY_DIR}/../lib/${dictionary} -inlineInputHeader -c -p ${ARG_OPTIONS} ${comp_defs} -std=c++${DD4HEP_USE_STDCXX} ${inc_dirs} ${headers} ${linkdefs}
DEPENDS ${headers} ${linkdefs} )
# Install the binary to the destination directory
#set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/../lib/${dictionary}_rdict.pcm PROPERTIES GENERATED TRUE )
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/../lib/${dictionary}_rdict.pcm DESTINATION lib)
#set_source_files_properties( ${dictionary}.h ${dictionary}.cxx PROPERTIES GENERATED TRUE )
endfunction()
#---------------------------------------------------------------------------------------------------
#
# \author M.Frank
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
macro( dd4hep_enable_tests )
cmake_parse_arguments(MACRO_ARG "" "" "" ${ARGV} )
if (BUILD_TESTING)
set ( BUILDNAME "${CMAKE_SYSTEM}-${CMAKE_CXX_COMPILER}-${CMAKE_BUILD_TYPE}" CACHE STRING "set build string for cdash")
dd4hep_list_to_string( _dir_entries PREFIX "DIRS:" ENTRIES ${MACRO_ARG_UNPARSED_ARGUMENTS} )
dd4hep_print ( "|++> Enable CTest environment....BUILD:${BUILD_TESTING} ${_dir_entries}" )
include(CTest)
enable_testing ()
if ( NOT "${MACRO_ARG_UNPARSED_ARGUMENTS}" STREQUAL "" )
foreach ( _dir ${MACRO_ARG_UNPARSED_ARGUMENTS} )
add_subdirectory ( ${_dir} )
endforeach()
endif()
endif()
endmacro( dd4hep_enable_tests )
#---------------------------------------------------------------------------------------------------
macro ( dd4hep_configure_scripts _pkg )
cmake_parse_arguments(MACRO_ARG "DEFAULT_SETUP;WITH_TESTS" "RUN_SCRIPT" "" ${ARGV} )
# PackageName is a variable required by existing LC build scripts.
# Set it here and unset it at the end of the scope...
set( PackageName ${_pkg} )
dd4hep_list_to_string( _dir_entries PREFIX "DIRS:" ENTRIES ${MACRO_ARG_UNPARSED_ARGUMENTS} )
dd4hep_print ( "|++> Setting up test environment for ${PackageName}: Testing:${BUILD_TESTING} Setup:${MACRO_ARG_DEFAULT_SETUP} With Tests(${MACRO_ARG_WITH_TESTS}): ${_dir_entries}" )
if ( (NOT "${MACRO_ARG_DEFAULT_SETUP}" STREQUAL "") OR (NOT "${_pkg}" STREQUAL "") )
configure_file( ${DD4hep_DIR}/cmake/run_test_package.sh ${EXECUTABLE_OUTPUT_PATH}/run_test_${_pkg}.sh @ONLY)
INSTALL(PROGRAMS ${EXECUTABLE_OUTPUT_PATH}/run_test_${_pkg}.sh DESTINATION bin )
#---- configure run environment ---------------
configure_file( ${DD4hep_DIR}/cmake/thisdd4hep_package.sh.in ${EXECUTABLE_OUTPUT_PATH}/this${_pkg}.sh @ONLY)
install(PROGRAMS ${EXECUTABLE_OUTPUT_PATH}/this${_pkg}.sh DESTINATION bin )
#--- install target-------------------------------------
if ( IS_DIRECTORY scripts )
dd4hep_install_dir ( compact scripts DESTINATION examples/${_pkg} )
endif()
if ( IS_DIRECTORY compact )
dd4hep_install_dir ( compact DESTINATION examples/${_pkg} )
endif()
endif()
dd4hep_enable_tests ( ${MACRO_ARG_UPARSED_ARGUMENTS} )
unset( PackageName )
endmacro( dd4hep_configure_scripts )
#---------------------------------------------------------------------------------------------------
# dd4hep_add_test_reg
#
# Add test with regular expression output parsing.
# BUILD_EXEC: Add and build executable with the same name as the test (Default NONE)
# OUTPUT Output file of the test (Default: empty)
# COMMAND Command to execute
# EXEC_ARGS Arguments to the command
# REGEX_PASS Regular expression to indicate that the test succeeded
# REGEX_FAIL Regular expression to indicate that the test failed
#
# \author M.Frank
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
function ( dd4hep_add_test_reg test_name )
cmake_parse_arguments(ARG "BUILD_EXEC" "OUTPUT" "COMMAND;EXEC_ARGS;REGEX_PASS;REGEX_PASSED;REGEX_FAIL;REGEX_FAILED;REQUIRES" ${ARGN} )
set ( missing )
set ( use_test 1 )
#foreach(opt ${ARG_REQUIRES} )
# dd4hep_unpack_package_opts ( USE ${opt} )
# dd4hep_find_package( ${USE_NAME} pkg_found
# ARGS ${USE_REQUIRED} ${USE_COMPONENT} ${USE_COMPONENTS}
# TYPE ${USE_TYPE} )
# if ( "${pkg_found}" STREQUAL "OFF" )
# set( missing ${missing} ${USE_NAME} )
# unset ( use_test )
# endif()
#endforeach()
dd4hep_print ( "*** Will not build/execute test ${test_name}. Missing dependencies: ${missing} ")
#dd4hep_print ( "Building executable: ${test_name} SOURCES src/${test_name}.cc")
dd4hep_add_executable ( ${test_name} SOURCES src/${test_name}.cc )
endif()
set ( cmd ${ARG_COMMAND} )
if ( "${cmd}" STREQUAL "" )
set ( cmd ${CMAKE_INSTALL_PREFIX}/bin/run_test.sh ${test_name} )
endif()
set ( passed ${ARG_REGEX_PASS} ${ARG_REGEX_PASSED} )
if ( "${passed}" STREQUAL "NONE" )
unset ( passed )
elseif ( "${passed}" STREQUAL "" )
set ( passed "TEST_PASSED" )
endif()
set ( failed ${ARG_REGEX_FAIL} ${ARG_REGEX_FAILED} )
if ( "${failed}" STREQUAL "NONE" )
unset ( failed )
endif()
set ( output ${ARG_OUTPUT} )
set ( args ${ARG_EXEC_ARGS} )
if ( "${args}" STREQUAL "" )
set ( args ${test_name} )
endif()
add_test(NAME t_${test_name} COMMAND ${cmd} ${output} ${args} ${output} )
if ( NOT "${passed}" STREQUAL "" )
set_tests_properties( t_${test_name} PROPERTIES PASS_REGULAR_EXPRESSION "${passed}" )
endif()
if ( NOT "${failed}" STREQUAL "" )
set_tests_properties( t_${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "${failed}" )
endif()
endif()
endfunction()
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
#---------------------------------------------------------------------------------------------------
# fill_dd4hep_library_path
#
#
# \author M.Petric
# \version 1.0
#
#---------------------------------------------------------------------------------------------------
function ( fill_dd4hep_library_path )
string(REGEX REPLACE "/lib/libCore.*" "" ROOT_ROOT ${ROOT_Core_LIBRARY})
SET( ENV{DD4HEP_LIBRARY_PATH} ${ROOT_ROOT}/lib )
if ( ${DD4HEP_USE_GEANT4} )
string(REGEX REPLACE "/lib/Geant4.*" "" Geant4_ROOT ${Geant4_DIR})
SET( ENV{DD4HEP_LIBRARY_PATH} ${Geant4_ROOT}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
endif()
if(${DD4HEP_USE_LCIO})
SET( ENV{DD4HEP_LIBRARY_PATH} ${LCIO_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
endif()
SET( ENV{DD4HEP_LIBRARY_PATH} ${CLHEP_ROOT_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
if(${DD4HEP_USE_XERCESC})
SET( ENV{DD4HEP_LIBRARY_PATH} ${XERCESC_ROOT_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
endif()
SET( ENV{DD4HEP_LIBRARY_PATH} ${CMAKE_BINARY_DIR}/lib:$ENV{DD4HEP_LIBRARY_PATH} )
endfunction()