From a79a3c10ac89db14a18552ee33bdf9577692953e Mon Sep 17 00:00:00 2001 From: Juan Miguel Carceller Date: Mon, 9 Feb 2026 13:54:10 +0100 Subject: [PATCH] Add support for Unity builds --- CMakeLists.txt | 9 +++++++++ src/cpp/CMakeLists.txt | 3 +++ src/cpp/include/UTIL/LCStdHepRdrNew.h | 6 +++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f81422d7..ccd8fb7d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,6 +180,15 @@ IF( NOT SIO_FOUND ) FetchContent_MakeAvailable(sio_extern) + # Unity builds break the bundled zlib used by SIO because several of zlib's + # internal headers are intentionally unguarded and assume a single translation + # unit per source file. + foreach(_lcio_no_unity_tgt IN ITEMS ZLIB zlib zlibstatic zlibshared) + if(TARGET ${_lcio_no_unity_tgt}) + set_property(TARGET ${_lcio_no_unity_tgt} PROPERTY UNITY_BUILD OFF) + endif() + endforeach() + get_target_property(SIO_VERSION SIO::sio VERSION) get_target_property(SIO_INCLUDE_DIRS SIO::sio INCLUDE_DIRECTORIES) ENDIF() diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index f6733d237..6c304cb38 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -375,6 +375,9 @@ IF( BUILD_ROOTDICT ) INCLUDE_DIRECTORIES( SYSTEM "${ROOT_INCLUDE_DIRS}" ) ADD_SHARED_LIBRARY( lcioDict ${lcio_rootdict_sources} ) + # ROOT dictionaries generate multiple translation units with many identical + # helper symbol names + set_property(TARGET lcioDict PROPERTY UNITY_BUILD OFF) TARGET_LINK_LIBRARIES( lcioDict ${ROOT_LIBRARIES} LCIO::lcio SIO::sio) IF( APPLE ) diff --git a/src/cpp/include/UTIL/LCStdHepRdrNew.h b/src/cpp/include/UTIL/LCStdHepRdrNew.h index 16b1afa21..5d217d7ba 100644 --- a/src/cpp/include/UTIL/LCStdHepRdrNew.h +++ b/src/cpp/include/UTIL/LCStdHepRdrNew.h @@ -1,5 +1,5 @@ -#ifndef UTIL_LCStdHepRdr_H -#define UTIL_LCStdHepRdr_H 1 +#ifndef UTIL_LCStdHepRdrNew_H +#define UTIL_LCStdHepRdrNew_H 1 #include "IMPL/LCCollectionVec.h" #include "UTIL/lStdHep.hh" @@ -89,4 +89,4 @@ namespace UTIL{ } // namespace UTIL -#endif /* ifndef UTIL_LCStdHepRdr_H */ +#endif /* ifndef UTIL_LCStdHepRdrNew_H */