From bb37a44b500879f23b6126b6bb94e35c2182f726 Mon Sep 17 00:00:00 2001 From: Matthew Ballance Date: Fri, 20 Feb 2026 15:29:03 +0000 Subject: [PATCH] CMake: detect PCH include flag for GCC/Clang in verilated.mk Without this, CFG_CXXFLAGS_PCH_I was left empty in CMake builds, causing GCC to treat the PCH filename as a linker input instead of applying it as a -include flag, breaking compilation of any model that uses PCH. This is a general CMake build fix (not funccov-specific); the same bug exists in upstream CMakeLists.txt. It is included here because funccov's cross-coverage tests expose the issue. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64f9f8f6f..d375fe970 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,6 +121,20 @@ set(PACKAGE_VERSION ${PROJECT_VERSION}) set(CXX ${CMAKE_CXX_COMPILER}) set(AR ${CMAKE_AR}) +# Detect precompiled header include flag (matches configure.ac logic) +execute_process(COMMAND ${CMAKE_CXX_COMPILER} --help + OUTPUT_VARIABLE _cxx_help OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET) +if(_cxx_help MATCHES "include-pch") + # clang + set(CFG_CXXFLAGS_PCH_I "-include-pch") + set(CFG_GCH_IF_CLANG ".gch") +else() + # GCC + set(CFG_CXXFLAGS_PCH_I "-include") + set(CFG_GCH_IF_CLANG "") +endif() + configure_file(include/verilated_config.h.in include/verilated_config.h @ONLY) configure_file(include/verilated.mk.in include/verilated.mk @ONLY)