From 41d57d01aca6297a7d71b1dffce5cb7b5c20346c Mon Sep 17 00:00:00 2001 From: Ruben Brandhofer Date: Mon, 2 Jun 2025 11:31:08 +0200 Subject: [PATCH] Fix SYSTEMC_UNITY_BUILD for static builds with custom main() When building SystemC as a static library with SYSTEMC_UNITY_BUILD=ON, linking fails if the user defines their own main() (e.g., in a test) because the internal sc_main.cpp object is included in the unity build and conflicts with the custom main(). This patch excludes sc_main.cpp from unity builds to restore expected behavior for static linking scenarios with external main() definitions. Signed-off-by: Ruben Brandhofer --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c1b94ce9..bb6798ca4 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -129,6 +129,7 @@ function(add_systemc_library libName scBuildDefine) if(SYSTEMC_UNITY_BUILD) message(STATUS "Enable SystemC unity build") set_target_properties(${libName} PROPERTIES UNITY_BUILD ON) + set_source_files_properties(sysc/kernel/sc_main.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) set_source_files_properties(sysc/utils/sc_utils_ids.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) else() message(STATUS "Disable SystemC unity build")