From 2150afc47066ef10003b192cc558df18531db418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Reitb=C3=B6ck?= Date: Tue, 23 Sep 2025 19:29:13 +0200 Subject: [PATCH] Sandbox: 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/Sandbox/App/AppSandbox.cpp | 4 +--- src/Mod/Sandbox/App/CMakeLists.txt | 7 +++++- src/Mod/Sandbox/App/DocumentProtector.cpp | 4 +--- src/Mod/Sandbox/App/DocumentProtectorPy.cpp | 4 +--- src/Mod/Sandbox/App/DocumentThread.cpp | 4 +--- src/Mod/Sandbox/App/PreCompiled.cpp | 24 --------------------- src/Mod/Sandbox/App/PreCompiled.h | 13 ----------- src/Mod/Sandbox/Gui/AppSandboxGui.cpp | 4 +--- src/Mod/Sandbox/Gui/CMakeLists.txt | 8 ++++++- src/Mod/Sandbox/Gui/Command.cpp | 4 +--- src/Mod/Sandbox/Gui/GLGraphicsView.cpp | 5 ----- src/Mod/Sandbox/Gui/Overlay.cpp | 4 +--- src/Mod/Sandbox/Gui/PreCompiled.cpp | 24 --------------------- src/Mod/Sandbox/Gui/PreCompiled.h | 21 +----------------- src/Mod/Sandbox/Gui/TaskPanelView.cpp | 1 - src/Mod/Sandbox/Gui/Workbench.cpp | 4 +--- 16 files changed, 22 insertions(+), 113 deletions(-) delete mode 100644 src/Mod/Sandbox/App/PreCompiled.cpp delete mode 100644 src/Mod/Sandbox/Gui/PreCompiled.cpp diff --git a/src/Mod/Sandbox/App/AppSandbox.cpp b/src/Mod/Sandbox/App/AppSandbox.cpp index f74381bb60..a333303e3c 100644 --- a/src/Mod/Sandbox/App/AppSandbox.cpp +++ b/src/Mod/Sandbox/App/AppSandbox.cpp @@ -21,10 +21,8 @@ ***************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ # include -#endif + #include #include diff --git a/src/Mod/Sandbox/App/CMakeLists.txt b/src/Mod/Sandbox/App/CMakeLists.txt index 316faed310..eced5e020f 100644 --- a/src/Mod/Sandbox/App/CMakeLists.txt +++ b/src/Mod/Sandbox/App/CMakeLists.txt @@ -32,7 +32,6 @@ SET(Sandbox_SRCS DocumentProtectorPy.h DocumentThread.cpp DocumentThread.h - PreCompiled.cpp PreCompiled.h ) @@ -45,6 +44,12 @@ add_library(Sandbox SHARED ${Sandbox_SRCS} ${Sandbox_Scripts}) target_link_libraries(Sandbox ${Sandbox_LIBS}) +if(FREECAD_USE_PCH) + target_precompile_headers(Sandbox PRIVATE + $<$:"${CMAKE_CURRENT_LIST_DIR}/PreCompiled.h"> + ) +endif(FREECAD_USE_PCH) + fc_target_copy_resource_flat(Sandbox ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/Mod/Sandbox diff --git a/src/Mod/Sandbox/App/DocumentProtector.cpp b/src/Mod/Sandbox/App/DocumentProtector.cpp index d1ba0f11c7..e79a0e4c76 100644 --- a/src/Mod/Sandbox/App/DocumentProtector.cpp +++ b/src/Mod/Sandbox/App/DocumentProtector.cpp @@ -21,8 +21,6 @@ ***************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ # include # include # include @@ -31,7 +29,7 @@ # include # include # include -#endif + #include "DocumentProtector.h" diff --git a/src/Mod/Sandbox/App/DocumentProtectorPy.cpp b/src/Mod/Sandbox/App/DocumentProtectorPy.cpp index 0c19900e6b..5424d49fc2 100644 --- a/src/Mod/Sandbox/App/DocumentProtectorPy.cpp +++ b/src/Mod/Sandbox/App/DocumentProtectorPy.cpp @@ -21,10 +21,8 @@ ***************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ # include -#endif + #include "DocumentProtectorPy.h" #include "DocumentProtector.h" diff --git a/src/Mod/Sandbox/App/DocumentThread.cpp b/src/Mod/Sandbox/App/DocumentThread.cpp index f3756d8df5..85ee8df15e 100644 --- a/src/Mod/Sandbox/App/DocumentThread.cpp +++ b/src/Mod/Sandbox/App/DocumentThread.cpp @@ -21,10 +21,8 @@ ***************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ # include -#endif + #include "DocumentThread.h" #include "DocumentProtector.h" diff --git a/src/Mod/Sandbox/App/PreCompiled.cpp b/src/Mod/Sandbox/App/PreCompiled.cpp deleted file mode 100644 index c5bd521220..0000000000 --- a/src/Mod/Sandbox/App/PreCompiled.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2009 Werner Mayer * - * * - * 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/Sandbox/App/PreCompiled.h b/src/Mod/Sandbox/App/PreCompiled.h index 4c93443354..f171e895f4 100644 --- a/src/Mod/Sandbox/App/PreCompiled.h +++ b/src/Mod/Sandbox/App/PreCompiled.h @@ -26,17 +26,6 @@ #include -// Exporting of App classes -#ifdef FC_OS_WIN32 -# define SandboxAppExport __declspec(dllexport) -# define MeshExport __declspec(dllimport) -#else // for Linux -# define SandboxAppExport -# define MeshExport -#endif - -#ifdef _PreComp_ - // standard #include #include @@ -67,7 +56,5 @@ #include #include -#endif //_PreComp_ - #endif diff --git a/src/Mod/Sandbox/Gui/AppSandboxGui.cpp b/src/Mod/Sandbox/Gui/AppSandboxGui.cpp index b8f8f8b9c7..ec162b1cae 100644 --- a/src/Mod/Sandbox/Gui/AppSandboxGui.cpp +++ b/src/Mod/Sandbox/Gui/AppSandboxGui.cpp @@ -21,14 +21,12 @@ ***************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ # include # include # include # include # include -#endif + #include #include diff --git a/src/Mod/Sandbox/Gui/CMakeLists.txt b/src/Mod/Sandbox/Gui/CMakeLists.txt index a1c259387c..797b102004 100644 --- a/src/Mod/Sandbox/Gui/CMakeLists.txt +++ b/src/Mod/Sandbox/Gui/CMakeLists.txt @@ -1,5 +1,6 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/Gui ) @@ -42,7 +43,6 @@ SET(SandboxGui_SRCS GLGraphicsView.h Overlay.cpp Overlay.h - PreCompiled.cpp PreCompiled.h TaskPanelView.cpp TaskPanelView.h @@ -62,6 +62,12 @@ if (MSVC) endif() +if(FREECAD_USE_PCH) + target_precompile_headers(SandboxGui PRIVATE + $<$:"${CMAKE_CURRENT_LIST_DIR}/PreCompiled.h"> + ) +endif(FREECAD_USE_PCH) + fc_target_copy_resource_flat(SandboxGui ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/Mod/Sandbox diff --git a/src/Mod/Sandbox/Gui/Command.cpp b/src/Mod/Sandbox/Gui/Command.cpp index 2c6e411ff1..7e08302ea6 100644 --- a/src/Mod/Sandbox/Gui/Command.cpp +++ b/src/Mod/Sandbox/Gui/Command.cpp @@ -20,9 +20,8 @@ * * ***************************************************************************/ +#include -#include "PreCompiled.h" -#ifndef _PreComp_ # ifdef FC_OS_WIN32 # include # endif @@ -55,7 +54,6 @@ # include # include # include -#endif #include #include diff --git a/src/Mod/Sandbox/Gui/GLGraphicsView.cpp b/src/Mod/Sandbox/Gui/GLGraphicsView.cpp index 316dc31aa0..b0f0e2e87f 100644 --- a/src/Mod/Sandbox/Gui/GLGraphicsView.cpp +++ b/src/Mod/Sandbox/Gui/GLGraphicsView.cpp @@ -21,11 +21,6 @@ ***************************************************************************/ -#include "PreCompiled.h" - -#ifndef _PreComp_ -#endif - #include #include #include diff --git a/src/Mod/Sandbox/Gui/Overlay.cpp b/src/Mod/Sandbox/Gui/Overlay.cpp index a41b128e61..0ba775a86a 100644 --- a/src/Mod/Sandbox/Gui/Overlay.cpp +++ b/src/Mod/Sandbox/Gui/Overlay.cpp @@ -21,14 +21,12 @@ ***************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ # include # include # include # include # include -#endif + #include #include diff --git a/src/Mod/Sandbox/Gui/PreCompiled.cpp b/src/Mod/Sandbox/Gui/PreCompiled.cpp deleted file mode 100644 index e6f3cb12fc..0000000000 --- a/src/Mod/Sandbox/Gui/PreCompiled.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2009 Werner Mayer * - * * - * 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/Sandbox/Gui/PreCompiled.h b/src/Mod/Sandbox/Gui/PreCompiled.h index 82ad54f308..55687cfe92 100644 --- a/src/Mod/Sandbox/Gui/PreCompiled.h +++ b/src/Mod/Sandbox/Gui/PreCompiled.h @@ -26,23 +26,6 @@ #include -// Importing of App classes -#ifdef FC_OS_WIN32 -# define SandboxAppExport __declspec(dllimport) -# define SandboxGuiExport __declspec(dllexport) -# define MeshExport __declspec(dllimport) -# define PartExport __declspec(dllimport) -# define AppPartExport __declspec(dllimport) -#else // for Linux -# define SandboxAppExport -# define SandboxGuiExport -# define MeshExport -# define PartExport -# define AppPartExport -#endif - -#ifdef _PreComp_ - // standard #include #include @@ -72,6 +55,4 @@ #include #include -#endif //_PreComp_ - -#endif // GUI_PRECOMPILED_H +#endif // GUI_PRECOMPILED_H diff --git a/src/Mod/Sandbox/Gui/TaskPanelView.cpp b/src/Mod/Sandbox/Gui/TaskPanelView.cpp index 659a89be77..e5910fe497 100644 --- a/src/Mod/Sandbox/Gui/TaskPanelView.cpp +++ b/src/Mod/Sandbox/Gui/TaskPanelView.cpp @@ -21,7 +21,6 @@ ***************************************************************************/ -#include "PreCompiled.h" /// Here the FreeCAD includes sorted by Base,App,Gui...... diff --git a/src/Mod/Sandbox/Gui/Workbench.cpp b/src/Mod/Sandbox/Gui/Workbench.cpp index 2041262465..1bb158c500 100644 --- a/src/Mod/Sandbox/Gui/Workbench.cpp +++ b/src/Mod/Sandbox/Gui/Workbench.cpp @@ -21,9 +21,7 @@ ***************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ # include # include # include @@ -32,7 +30,7 @@ # include # include # include -#endif + #include "Workbench.h" #include