@@ -25,27 +25,67 @@ include_guard()
2525# The installed JSON file will be named <executable-name>.json and installed
2626# under share/dpl directory
2727#
28+ # With WORKFLOW_PLUGIN, the sources are compiled into the DPL workflow plugin
29+ # <Name>, in libO2Physics<Name>Plugin, which o2-dpl-run can load with
30+ # --workflow-plugin, and the executable is only a main() linking it. <Name> is
31+ # the CamelCase of the executable name without o2-.
32+ #
2833
2934function (o2physics_add_dpl_workflow baseTargetName )
30- cmake_parse_arguments (PARSE_ARGV 1 A "" "COMPONENT_NAME;TARGETVARNAME;REUSE_FROM"
35+ cmake_parse_arguments (PARSE_ARGV 1 A "WORKFLOW_PLUGIN " "COMPONENT_NAME;TARGETVARNAME;REUSE_FROM"
3136 "SOURCES;PUBLIC_LINK_LIBRARIES" )
3237
3338 if (A_UNPARSED_ARGUMENTS)
3439 message (FATAL_ERROR "Got trailing arguments ${A_UNPARSED_ARGUMENTS} " )
3540 endif ()
3641
37- o2physics_add_executable (${baseTargetName}
38- COMPONENT_NAME ${A_COMPONENT_NAME} TARGETVARNAME targetExeName
39- SOURCES ${A_SOURCES}
40- PUBLIC_LINK_LIBRARIES O2::Framework ${A_PUBLIC_LINK_LIBRARIES} )
42+ set (compileTarget "" )
43+ if (A_WORKFLOW_PLUGIN)
44+ if (NOT TARGET O2PhysicsWorkflowMain)
45+ file (CONFIGURE OUTPUT ${CMAKE_BINARY_DIR } /O2PhysicsWorkflowMain.cxx CONTENT [[
46+ extern "C" int dpl_workflow_main(int argc, char** argv);
47+ int main(int argc, char** argv) { return dpl_workflow_main(argc, argv); }
48+ ]] )
49+ add_library (O2PhysicsWorkflowMain OBJECT ${CMAKE_BINARY_DIR } /O2PhysicsWorkflowMain.cxx )
50+ endif ()
51+ # Callers may pass JOB_POOL among the sources, for o2physics_add_executable.
52+ cmake_parse_arguments (S "" "JOB_POOL" "" ${A_SOURCES} )
53+ o2physics_add_executable (${baseTargetName}
54+ COMPONENT_NAME ${A_COMPONENT_NAME} TARGETVARNAME targetExeName
55+ SOURCES $<TARGET_OBJECTS :O2PhysicsWorkflowMain >
56+ PUBLIC_LINK_LIBRARIES O2::Framework ${A_PUBLIC_LINK_LIBRARIES} )
57+ get_target_property (name ${targetExeName} OUTPUT_NAME )
58+ string (REGEX REPLACE "^o2-" "" name ${name} )
59+ string (REPLACE "-" ";" parts ${name} )
60+ set (name "" )
61+ foreach (part IN LISTS parts)
62+ string (SUBSTRING ${part} 0 1 first)
63+ string (SUBSTRING ${part} 1 -1 rest)
64+ string (TOUPPER ${first} first)
65+ string (APPEND name ${first}${rest} )
66+ endforeach ()
67+ string (MAKE_C_IDENTIFIER ${name} name)
68+ set (compileTarget O2Physics${name} Plugin)
69+ add_library (${compileTarget} SHARED ${S_UNPARSED_ARGUMENTS} )
70+ target_link_libraries (${compileTarget} PUBLIC O2::Framework ${A_PUBLIC_LINK_LIBRARIES} )
71+ target_compile_definitions (${compileTarget} PRIVATE DPL_WORKFLOW_PLUGIN_NAME=${name} )
72+ target_link_libraries (${targetExeName} PUBLIC ${compileTarget} )
73+ install (TARGETS ${compileTarget} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
74+ else ()
75+ o2physics_add_executable (${baseTargetName}
76+ COMPONENT_NAME ${A_COMPONENT_NAME} TARGETVARNAME targetExeName
77+ SOURCES ${A_SOURCES}
78+ PUBLIC_LINK_LIBRARIES O2::Framework ${A_PUBLIC_LINK_LIBRARIES} )
79+ set (compileTarget ${targetExeName} )
80+ endif ()
4181
4282 if (A_TARGETVARNAME)
4383 set (${A_TARGETVARNAME}
4484 ${targetExeName}
4585 PARENT_SCOPE )
4686 endif ()
47- set_property (TARGET ${targetExeName } PROPERTY JOB_POOL_COMPILE analysis)
48- set_property (TARGET ${targetExeName} PROPERTY JOB_POOL_LINK analysis)
87+ set_property (TARGET ${compileTarget } PROPERTY JOB_POOL_COMPILE analysis)
88+ set_property (TARGET ${compileTarget} ${ targetExeName} PROPERTY JOB_POOL_LINK analysis)
4989
5090 # Reuse a precompiled header. Without an explicit REUSE_FROM, fall back to the
5191 # shared AnalysisPCH (Common/Core): a workflow translation unit spends most of
@@ -63,7 +103,7 @@ function(o2physics_add_dpl_workflow baseTargetName)
63103 endif ()
64104 # A target cannot reuse its own PCH, and the carrier is not built when recc
65105 # is caching compilations remotely instead.
66- if (_pch AND NOT _pch STREQUAL targetExeName AND NOT DEFINED ENV{USE_RECC})
106+ if (_pch AND NOT _pch STREQUAL compileTarget AND NOT DEFINED ENV{USE_RECC})
67107 # GCC refuses a PCH built with a different preprocessor state than the
68108 # consumer's, and -Werror turns that refusal into a build failure:
69109 # cmake_pch.hxx.gch: not used because `RANS_ENABLE_JSON' not defined
@@ -87,8 +127,8 @@ function(o2physics_add_dpl_workflow baseTargetName)
87127 # preprocessor state the carrier compiled with, and that state is exactly
88128 # what GCC compares, rather than one property of it at a time.
89129 # Requires CMake >= 3.27.
90- target_link_libraries (${targetExeName } PRIVATE $<COMPILE_ONLY :${_pch} >)
91- target_precompile_headers (${targetExeName } REUSE_FROM ${_pch} )
130+ target_link_libraries (${compileTarget } PRIVATE $<COMPILE_ONLY :${_pch} >)
131+ target_precompile_headers (${compileTarget } REUSE_FROM ${_pch} )
92132 endif ()
93133
94134 set (jsonFile $<TARGET_FILE_BASE_NAME :${targetExeName} >.json)
0 commit comments