From 5b3d4fc91d9f2152199fb9173e948b7612d84fc7 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 30 Jul 2025 17:04:06 -0700 Subject: [PATCH] Put PCH behind a cmake flag Allows developers to turn it off if they don't like/don't want it --- CMakeLists.txt | 4 +++ common/CMakeLists.txt | 76 ++++++++++++++++++++++------------------ common/build_version.cpp | 7 ++++ eeschema/CMakeLists.txt | 24 +++++++------ pcbnew/CMakeLists.txt | 2 +- 5 files changed, 66 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7720645811..97d3097cb9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -233,6 +233,10 @@ cmake_dependent_option( KICAD_WIN32_LTCG OFF "WIN32" OFF ) +option( KICAD_USE_PCH + "Enable precompiled header support" + ON ) + # Advanced option to make link maps (only available on linux) cmake_dependent_option( KICAD_MAKE_LINK_MAPS "Create link maps for artifacts" diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 92d278086a..153afcffc1 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -239,18 +239,20 @@ add_library( kicommon SHARED ${KICOMMON_SRCS} ) -target_precompile_headers( kicommon - PRIVATE - - - - - - - - - - ) +if( KICAD_USE_PCH ) + target_precompile_headers( kicommon + PRIVATE + + + + + + + + + + ) +endif() set_target_properties(kicommon PROPERTIES CXX_VISIBILITY_PRESET hidden) @@ -750,18 +752,20 @@ add_library( common STATIC ${COMMON_SRCS} ) -target_precompile_headers( kicommon - PRIVATE - - - - - - - - - - ) +if( KICAD_USE_PCH ) + target_precompile_headers( kicommon + PRIVATE + + + + + + + + + + ) +endif() add_dependencies( common version_header ) add_dependencies( common compoundfilereader ) # used by altium_parser.cpp @@ -929,17 +933,19 @@ set( PCB_COMMON_SRCS add_library( pcbcommon STATIC ${PCB_COMMON_SRCS} ) -target_precompile_headers( pcbcommon - PRIVATE - - - - - - - - - ) +if( KICAD_USE_PCH ) + target_precompile_headers( pcbcommon + PRIVATE + + + + + + + + + ) +endif() target_compile_definitions(pcbcommon PRIVATE PCBNEW) diff --git a/common/build_version.cpp b/common/build_version.cpp index cef7fd092e..535eeff29e 100644 --- a/common/build_version.cpp +++ b/common/build_version.cpp @@ -317,6 +317,13 @@ wxString GetVersionInfoData( const wxString& aTitle, bool aHtml, bool aBrief ) aMsg << indent4 << "KICAD_IPC_API=" << OFF; #endif + aMsg << indent4 << "KICAD_USE_PCH="; +#ifdef KICAD_USE_PCH + aMsg << ON; +#else + aMsg << OFF; +#endif + #ifndef NDEBUG aMsg << indent4 << "KICAD_STDLIB_DEBUG="; #ifdef KICAD_STDLIB_DEBUG diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 0ef7b15ae8..96342b23f7 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -576,17 +576,19 @@ add_library( eeschema_kiface_objects OBJECT ${EESCHEMA_COMMON_SRCS} ) -target_precompile_headers( eeschema_kiface_objects - PRIVATE - - - - - - - - - ) +if( KICAD_USE_PCH ) + target_precompile_headers( eeschema_kiface_objects + PRIVATE + + + + + + + + + ) +endif() target_include_directories( eeschema_kiface_objects PUBLIC diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 28dfa67528..15e8aeaf27 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -720,7 +720,7 @@ add_library( pcbnew_kiface_objects OBJECT ${PCBNEW_SCRIPTING_SRCS} ) -if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) +if( KICAD_USE_PCH AND CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) target_precompile_headers( pcbnew_kiface_objects PRIVATE