From 7051848d10946566afe280b38a03f11492b3b588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Reitb=C3=B6ck?= Date: Sun, 21 Sep 2025 16:04:59 +0200 Subject: [PATCH] Import: use CMake to generate precompiled headers on all platforms "Professional CMake" book suggest the following: "Targets should build successfully with or without compiler support for precompiled headers. It should be considered an optimization, not a requirement. In particular, do not explicitly include a precompile header (e.g. stdafx.h) in the source code, let CMake force-include an automatically generated precompile header on the compiler command line instead. This is more portable across the major compilers and is likely to be easier to maintain. It will also avoid warnings being generated from certain code checking tools like iwyu (include what you use)." Therefore, removed the "#include " from sources, also there is no need for the "#ifdef _PreComp_" anymore --- src/Mod/Import/App/AppImport.cpp | 1 - src/Mod/Import/App/AppImportPy.cpp | 4 +--- src/Mod/Import/App/CMakeLists.txt | 8 +++++++- src/Mod/Import/App/ExportOCAF.cpp | 4 +--- src/Mod/Import/App/ExportOCAF2.cpp | 4 +--- src/Mod/Import/App/ImportOCAF.cpp | 4 +--- src/Mod/Import/App/ImportOCAF2.cpp | 4 +--- src/Mod/Import/App/ImportOCAFAssembly.cpp | 4 +--- src/Mod/Import/App/PreCompiled.cpp | 24 ----------------------- src/Mod/Import/App/PreCompiled.h | 5 ----- src/Mod/Import/App/ReaderGltf.cpp | 3 --- src/Mod/Import/App/ReaderIges.cpp | 4 +--- src/Mod/Import/App/ReaderStep.cpp | 4 +--- src/Mod/Import/App/SketchExportHelper.cpp | 5 +---- src/Mod/Import/App/StepShape.cpp | 4 +--- src/Mod/Import/App/StepShapePyImp.cpp | 1 - src/Mod/Import/App/Tools.cpp | 4 +--- src/Mod/Import/App/WriterGltf.cpp | 3 --- src/Mod/Import/App/WriterIges.cpp | 4 +--- src/Mod/Import/App/WriterStep.cpp | 4 +--- src/Mod/Import/App/dxf/ImpExpDxf.cpp | 3 --- src/Mod/Import/App/dxf/dxf.cpp | 1 - src/Mod/Import/Gui/AppImportGui.cpp | 1 - src/Mod/Import/Gui/AppImportGuiPy.cpp | 4 +--- src/Mod/Import/Gui/CMakeLists.txt | 8 +++++++- src/Mod/Import/Gui/Command.cpp | 1 - src/Mod/Import/Gui/ExportOCAFGui.cpp | 2 -- src/Mod/Import/Gui/ImportOCAFGui.cpp | 2 -- src/Mod/Import/Gui/OCAFBrowser.cpp | 4 +--- src/Mod/Import/Gui/PreCompiled.cpp | 24 ----------------------- src/Mod/Import/Gui/PreCompiled.h | 13 +----------- src/Mod/Import/Gui/Workbench.cpp | 1 - src/Mod/Import/Gui/dxf/ImpExpDxfGui.cpp | 4 ++-- 33 files changed, 32 insertions(+), 134 deletions(-) delete mode 100644 src/Mod/Import/App/PreCompiled.cpp delete mode 100644 src/Mod/Import/Gui/PreCompiled.cpp diff --git a/src/Mod/Import/App/AppImport.cpp b/src/Mod/Import/App/AppImport.cpp index de5b5f3f78..21fa624372 100644 --- a/src/Mod/Import/App/AppImport.cpp +++ b/src/Mod/Import/App/AppImport.cpp @@ -21,7 +21,6 @@ * * ***************************************************************************/ -#include "PreCompiled.h" #include #include diff --git a/src/Mod/Import/App/AppImportPy.cpp b/src/Mod/Import/App/AppImportPy.cpp index 362700b83c..da6bc79b26 100644 --- a/src/Mod/Import/App/AppImportPy.cpp +++ b/src/Mod/Import/App/AppImportPy.cpp @@ -20,11 +20,10 @@ * * ***************************************************************************/ -#include "PreCompiled.h" #if defined(__MINGW32__) #define WNT // avoid conflict with GUID #endif -#ifndef _PreComp_ + #include #include #if defined(__clang__) @@ -46,7 +45,6 @@ #if defined(__clang__) #pragma clang diagnostic pop #endif -#endif #include #include "dxf/ImpExpDxf.h" diff --git a/src/Mod/Import/App/CMakeLists.txt b/src/Mod/Import/App/CMakeLists.txt index 1235bc5bf1..b9e1f9cf77 100644 --- a/src/Mod/Import/App/CMakeLists.txt +++ b/src/Mod/Import/App/CMakeLists.txt @@ -27,7 +27,6 @@ SET(Import_SRCS StepShape.h StepShape.cpp StepShapePyImp.cpp - PreCompiled.cpp PreCompiled.h Tools.cpp Tools.h @@ -73,6 +72,13 @@ SOURCE_GROUP("SCL" FILES ${SCL_Resources}) generate_from_py(StepShape) add_library(Import SHARED ${Import_SRCS}) + +if(FREECAD_USE_PCH) + target_precompile_headers(Import PRIVATE + $<$:"${CMAKE_CURRENT_LIST_DIR}/PreCompiled.h"> + ) +endif(FREECAD_USE_PCH) + target_include_directories( Import PRIVATE diff --git a/src/Mod/Import/App/ExportOCAF.cpp b/src/Mod/Import/App/ExportOCAF.cpp index 814140ce64..b48ef161c3 100644 --- a/src/Mod/Import/App/ExportOCAF.cpp +++ b/src/Mod/Import/App/ExportOCAF.cpp @@ -20,11 +20,9 @@ * * ***************************************************************************/ -#include "PreCompiled.h" #if defined(__MINGW32__) #define WNT // avoid conflict with GUID #endif -#ifndef _PreComp_ #include #include #include @@ -40,7 +38,7 @@ #include #include // for Precision::Confusion() #include -#endif + #include #include diff --git a/src/Mod/Import/App/ExportOCAF2.cpp b/src/Mod/Import/App/ExportOCAF2.cpp index cb5ffabb92..ea8ce61dd6 100644 --- a/src/Mod/Import/App/ExportOCAF2.cpp +++ b/src/Mod/Import/App/ExportOCAF2.cpp @@ -20,11 +20,9 @@ * * ****************************************************************************/ -#include "PreCompiled.h" #if defined(__MINGW32__) #define WNT // avoid conflict with GUID #endif -#ifndef _PreComp_ #include #include #include @@ -35,7 +33,7 @@ #include #include #include -#endif + #include diff --git a/src/Mod/Import/App/ImportOCAF.cpp b/src/Mod/Import/App/ImportOCAF.cpp index 65d92029a1..0321d6de8c 100644 --- a/src/Mod/Import/App/ImportOCAF.cpp +++ b/src/Mod/Import/App/ImportOCAF.cpp @@ -20,11 +20,9 @@ * * ***************************************************************************/ -#include "PreCompiled.h" #if defined(__MINGW32__) #define WNT // avoid conflict with GUID #endif -#ifndef _PreComp_ #include #include #include @@ -44,7 +42,7 @@ #include #include // for Precision::Confusion() #include -#endif + #include #include diff --git a/src/Mod/Import/App/ImportOCAF2.cpp b/src/Mod/Import/App/ImportOCAF2.cpp index f4f32f8b5f..8ffc0f8ca8 100644 --- a/src/Mod/Import/App/ImportOCAF2.cpp +++ b/src/Mod/Import/App/ImportOCAF2.cpp @@ -20,11 +20,9 @@ * * ****************************************************************************/ -#include "PreCompiled.h" #if defined(__MINGW32__) #define WNT // avoid conflict with GUID #endif -#ifndef _PreComp_ #include #include #include @@ -38,7 +36,7 @@ #include #include #include -#endif + #include #include diff --git a/src/Mod/Import/App/ImportOCAFAssembly.cpp b/src/Mod/Import/App/ImportOCAFAssembly.cpp index 742e89f4f7..3d536828ac 100644 --- a/src/Mod/Import/App/ImportOCAFAssembly.cpp +++ b/src/Mod/Import/App/ImportOCAFAssembly.cpp @@ -20,11 +20,9 @@ * * ***************************************************************************/ -#include "PreCompiled.h" #if defined(__MINGW32__) #define WNT // avoid conflict with GUID #endif -#ifndef _PreComp_ #include #include #include @@ -38,7 +36,7 @@ #include #include #include -#endif + #include #include diff --git a/src/Mod/Import/App/PreCompiled.cpp b/src/Mod/Import/App/PreCompiled.cpp deleted file mode 100644 index 7b200a1bf2..0000000000 --- a/src/Mod/Import/App/PreCompiled.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2002 Jürgen Riegel * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" diff --git a/src/Mod/Import/App/PreCompiled.h b/src/Mod/Import/App/PreCompiled.h index 157b9e6fd8..f9a9f76261 100644 --- a/src/Mod/Import/App/PreCompiled.h +++ b/src/Mod/Import/App/PreCompiled.h @@ -26,13 +26,10 @@ #include -#ifdef _PreComp_ - // standard #include #include #include -#include #include #include #include @@ -48,6 +45,4 @@ // Base #include -#endif //_PreComp_ - #endif diff --git a/src/Mod/Import/App/ReaderGltf.cpp b/src/Mod/Import/App/ReaderGltf.cpp index 2671c62359..478e161af0 100644 --- a/src/Mod/Import/App/ReaderGltf.cpp +++ b/src/Mod/Import/App/ReaderGltf.cpp @@ -22,8 +22,6 @@ **************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ #include #include #include @@ -37,7 +35,6 @@ #include #include #include -#endif #include "ReaderGltf.h" #include "Tools.h" diff --git a/src/Mod/Import/App/ReaderIges.cpp b/src/Mod/Import/App/ReaderIges.cpp index 31a9b56fff..ee76754c1b 100644 --- a/src/Mod/Import/App/ReaderIges.cpp +++ b/src/Mod/Import/App/ReaderIges.cpp @@ -22,8 +22,6 @@ **************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ #include #include #include @@ -33,7 +31,7 @@ #include #include #include -#endif + #include "ReaderIges.h" #include diff --git a/src/Mod/Import/App/ReaderStep.cpp b/src/Mod/Import/App/ReaderStep.cpp index 45eee35219..75bdac60a4 100644 --- a/src/Mod/Import/App/ReaderStep.cpp +++ b/src/Mod/Import/App/ReaderStep.cpp @@ -22,14 +22,12 @@ **************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ #include #include #include #include #include -#endif + #include "ReaderStep.h" #include diff --git a/src/Mod/Import/App/SketchExportHelper.cpp b/src/Mod/Import/App/SketchExportHelper.cpp index 08f2305b20..a9a73acdd5 100644 --- a/src/Mod/Import/App/SketchExportHelper.cpp +++ b/src/Mod/Import/App/SketchExportHelper.cpp @@ -23,15 +23,12 @@ //! a class to assist with exporting sketches to dxf -#include "PreCompiled.h" - -#ifndef _PreComp_ #include #include #include #include #include -#endif + #include #include diff --git a/src/Mod/Import/App/StepShape.cpp b/src/Mod/Import/App/StepShape.cpp index a09798cbb4..528932d61b 100644 --- a/src/Mod/Import/App/StepShape.cpp +++ b/src/Mod/Import/App/StepShape.cpp @@ -20,10 +20,8 @@ * * ***************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ #include -#endif + #include #include diff --git a/src/Mod/Import/App/StepShapePyImp.cpp b/src/Mod/Import/App/StepShapePyImp.cpp index f1e7f04913..58f9d2ed65 100644 --- a/src/Mod/Import/App/StepShapePyImp.cpp +++ b/src/Mod/Import/App/StepShapePyImp.cpp @@ -20,7 +20,6 @@ * * ***************************************************************************/ -#include "PreCompiled.h" // clang-format off // inclusion of the generated files (generated out of StepShapePy.xml) diff --git a/src/Mod/Import/App/Tools.cpp b/src/Mod/Import/App/Tools.cpp index 5888e6cacf..6382de10f6 100644 --- a/src/Mod/Import/App/Tools.cpp +++ b/src/Mod/Import/App/Tools.cpp @@ -21,12 +21,10 @@ ****************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ #include #include #include -#endif + #include #include diff --git a/src/Mod/Import/App/WriterGltf.cpp b/src/Mod/Import/App/WriterGltf.cpp index eb12e3417e..d22e17098a 100644 --- a/src/Mod/Import/App/WriterGltf.cpp +++ b/src/Mod/Import/App/WriterGltf.cpp @@ -22,14 +22,11 @@ **************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ #include #include #include #include #include -#endif #include "WriterGltf.h" #include diff --git a/src/Mod/Import/App/WriterIges.cpp b/src/Mod/Import/App/WriterIges.cpp index 37fe3e367f..a70c15580a 100644 --- a/src/Mod/Import/App/WriterIges.cpp +++ b/src/Mod/Import/App/WriterIges.cpp @@ -22,14 +22,12 @@ **************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ #include #include #include #include #include -#endif + #include "WriterIges.h" #include diff --git a/src/Mod/Import/App/WriterStep.cpp b/src/Mod/Import/App/WriterStep.cpp index 31165b2cd2..df7d9f966b 100644 --- a/src/Mod/Import/App/WriterStep.cpp +++ b/src/Mod/Import/App/WriterStep.cpp @@ -22,12 +22,10 @@ **************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ #include #include #include -#endif + #include "WriterStep.h" #include diff --git a/src/Mod/Import/App/dxf/ImpExpDxf.cpp b/src/Mod/Import/App/dxf/ImpExpDxf.cpp index 62ab50ca6c..0cbb575308 100644 --- a/src/Mod/Import/App/dxf/ImpExpDxf.cpp +++ b/src/Mod/Import/App/dxf/ImpExpDxf.cpp @@ -20,9 +20,7 @@ * * ***************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ #include #if OCC_VERSION_HEX < 0x070600 #include @@ -61,7 +59,6 @@ #include #include #include -#endif #include #include diff --git a/src/Mod/Import/App/dxf/dxf.cpp b/src/Mod/Import/App/dxf/dxf.cpp index 5511ab8feb..c3a88bddf3 100644 --- a/src/Mod/Import/App/dxf/dxf.cpp +++ b/src/Mod/Import/App/dxf/dxf.cpp @@ -3,7 +3,6 @@ // This program is released under the BSD license. See the file COPYING for details. // modified 2018 wandererfan -#include "PreCompiled.h" #include #include diff --git a/src/Mod/Import/Gui/AppImportGui.cpp b/src/Mod/Import/Gui/AppImportGui.cpp index 516727fbd2..454bd8aa94 100644 --- a/src/Mod/Import/Gui/AppImportGui.cpp +++ b/src/Mod/Import/Gui/AppImportGui.cpp @@ -21,7 +21,6 @@ * * ***************************************************************************/ -#include "PreCompiled.h" #include #include diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index 7654f1d4e7..7ed24b118e 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -20,11 +20,10 @@ * * ***************************************************************************/ -#include "PreCompiled.h" #if defined(__MINGW32__) #define WNT // avoid conflict with GUID #endif -#ifndef _PreComp_ + #include #include @@ -44,7 +43,6 @@ #if defined(__clang__) #pragma clang diagnostic pop #endif -#endif #include #include "ExportOCAFGui.h" diff --git a/src/Mod/Import/Gui/CMakeLists.txt b/src/Mod/Import/Gui/CMakeLists.txt index 14c83b10b1..16231e68e2 100644 --- a/src/Mod/Import/Gui/CMakeLists.txt +++ b/src/Mod/Import/Gui/CMakeLists.txt @@ -18,13 +18,19 @@ SET(ImportGui_SRCS ImportOCAFGui.h OCAFBrowser.cpp OCAFBrowser.h - PreCompiled.cpp PreCompiled.h Workbench.cpp Workbench.h ) add_library(ImportGui SHARED ${ImportGui_SRCS}) + +if(FREECAD_USE_PCH) + target_precompile_headers(ImportGui PRIVATE + $<$:"${CMAKE_CURRENT_LIST_DIR}/PreCompiled.h"> + ) +endif(FREECAD_USE_PCH) + target_include_directories( ImportGui PRIVATE diff --git a/src/Mod/Import/Gui/Command.cpp b/src/Mod/Import/Gui/Command.cpp index 9f83693807..c5d928ef16 100644 --- a/src/Mod/Import/Gui/Command.cpp +++ b/src/Mod/Import/Gui/Command.cpp @@ -20,7 +20,6 @@ * * ***************************************************************************/ -#include "PreCompiled.h" #include #include diff --git a/src/Mod/Import/Gui/ExportOCAFGui.cpp b/src/Mod/Import/Gui/ExportOCAFGui.cpp index e08ecc1544..a640e3808a 100644 --- a/src/Mod/Import/Gui/ExportOCAFGui.cpp +++ b/src/Mod/Import/Gui/ExportOCAFGui.cpp @@ -22,8 +22,6 @@ **************************************************************************/ -#include "PreCompiled.h" - #include "ExportOCAFGui.h" #include #include diff --git a/src/Mod/Import/Gui/ImportOCAFGui.cpp b/src/Mod/Import/Gui/ImportOCAFGui.cpp index a5cba4c2db..5b9a5fe5ef 100644 --- a/src/Mod/Import/Gui/ImportOCAFGui.cpp +++ b/src/Mod/Import/Gui/ImportOCAFGui.cpp @@ -23,8 +23,6 @@ **************************************************************************/ -#include "PreCompiled.h" - #include "ImportOCAFGui.h" #include #include diff --git a/src/Mod/Import/Gui/OCAFBrowser.cpp b/src/Mod/Import/Gui/OCAFBrowser.cpp index 7a56c5eaed..c485b94d2f 100644 --- a/src/Mod/Import/Gui/OCAFBrowser.cpp +++ b/src/Mod/Import/Gui/OCAFBrowser.cpp @@ -22,8 +22,6 @@ **************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ #include #include #include @@ -56,7 +54,7 @@ #include #include #include -#endif + #include "OCAFBrowser.h" #include diff --git a/src/Mod/Import/Gui/PreCompiled.cpp b/src/Mod/Import/Gui/PreCompiled.cpp deleted file mode 100644 index 7b200a1bf2..0000000000 --- a/src/Mod/Import/Gui/PreCompiled.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2002 Jürgen Riegel * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" diff --git a/src/Mod/Import/Gui/PreCompiled.h b/src/Mod/Import/Gui/PreCompiled.h index 6584813a0c..e5fa0530e4 100644 --- a/src/Mod/Import/Gui/PreCompiled.h +++ b/src/Mod/Import/Gui/PreCompiled.h @@ -26,8 +26,6 @@ #include -#ifdef _PreComp_ - // standard #include #include @@ -39,7 +37,7 @@ #include #include -#ifndef FC_OS_WIN32 +#ifdef FC_OS_WIN32 #include #endif @@ -73,16 +71,7 @@ #include #include -#ifndef FC_OS_WIN32 -#include -#else -#include -#endif - // Qt Toolkit #include - -#endif //_PreComp_ - #endif // __PRECOMPILED_GUI__ diff --git a/src/Mod/Import/Gui/Workbench.cpp b/src/Mod/Import/Gui/Workbench.cpp index ebdbbf7e7d..5faf397bce 100644 --- a/src/Mod/Import/Gui/Workbench.cpp +++ b/src/Mod/Import/Gui/Workbench.cpp @@ -20,7 +20,6 @@ * * ***************************************************************************/ -#include "PreCompiled.h" #include diff --git a/src/Mod/Import/Gui/dxf/ImpExpDxfGui.cpp b/src/Mod/Import/Gui/dxf/ImpExpDxfGui.cpp index f6c2597425..0d13f40ec4 100644 --- a/src/Mod/Import/Gui/dxf/ImpExpDxfGui.cpp +++ b/src/Mod/Import/Gui/dxf/ImpExpDxfGui.cpp @@ -21,7 +21,7 @@ ***************************************************************************/ #include -#ifndef _PreComp_ + #include #if OCC_VERSION_HEX < 0x070600 #include @@ -49,7 +49,7 @@ #include #include #include -#endif + #include #include