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>
This commit is contained in:
Matthew Ballance 2026-02-20 15:29:03 +00:00
parent ab6424313e
commit bb37a44b50
1 changed files with 14 additions and 0 deletions

View File

@ -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)