From 550786e6b0f3d7f006e1cf4287888cf9f27c87bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Reitb=C3=B6ck?= Date: Sun, 21 Sep 2025 17:17:29 +0200 Subject: [PATCH] Cloud: 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/Cloud/App/AppCloud.cpp | 6 +- src/Mod/Cloud/App/AppCloud.h | 2 + src/Mod/Cloud/App/CMakeLists.txt | 7 +- src/Mod/Cloud/App/PreCompiled.h | 10 --- .../{App/PreCompiled.cpp => CloudGlobal.h} | 71 ++++++++++++------- src/Mod/Cloud/Gui/AppCloudGui.cpp | 1 - src/Mod/Cloud/Gui/CMakeLists.txt | 7 +- src/Mod/Cloud/Gui/Command.cpp | 1 - src/Mod/Cloud/Gui/PreCompiled.cpp | 24 ------- src/Mod/Cloud/Gui/PreCompiled.h | 13 ---- src/Mod/Cloud/Gui/Workbench.cpp | 1 - 11 files changed, 63 insertions(+), 80 deletions(-) rename src/Mod/Cloud/{App/PreCompiled.cpp => CloudGlobal.h} (75%) delete mode 100644 src/Mod/Cloud/Gui/PreCompiled.cpp diff --git a/src/Mod/Cloud/App/AppCloud.cpp b/src/Mod/Cloud/App/AppCloud.cpp index e2b7956b73..55ed2cdc7e 100644 --- a/src/Mod/Cloud/App/AppCloud.cpp +++ b/src/Mod/Cloud/App/AppCloud.cpp @@ -20,12 +20,10 @@ * * ***************************************************************************/ -#include "PreCompiled.h" +#include + -#ifndef _PreComp_ #include -#endif - #if defined(FC_OS_WIN32) #include diff --git a/src/Mod/Cloud/App/AppCloud.h b/src/Mod/Cloud/App/AppCloud.h index e9cc8712ce..b8be72202a 100644 --- a/src/Mod/Cloud/App/AppCloud.h +++ b/src/Mod/Cloud/App/AppCloud.h @@ -27,6 +27,8 @@ #include #include +#include + #include #include #include diff --git a/src/Mod/Cloud/App/CMakeLists.txt b/src/Mod/Cloud/App/CMakeLists.txt index 88e1ee186c..6819da6891 100644 --- a/src/Mod/Cloud/App/CMakeLists.txt +++ b/src/Mod/Cloud/App/CMakeLists.txt @@ -19,13 +19,18 @@ set(Cloud_LIBS SET(Cloud_SRCS AppCloud.cpp - PreCompiled.cpp PreCompiled.h ) add_library(Cloud SHARED ${Cloud_SRCS}) target_link_libraries(Cloud ${Cloud_LIBS}) +if(FREECAD_USE_PCH) + target_precompile_headers(Cloud PRIVATE + $<$:"${CMAKE_CURRENT_LIST_DIR}/PreCompiled.h"> + ) +endif(FREECAD_USE_PCH) + SET_BIN_DIR(Cloud Cloud /Mod/Cloud) SET_PYTHON_PREFIX_SUFFIX(Cloud) diff --git a/src/Mod/Cloud/App/PreCompiled.h b/src/Mod/Cloud/App/PreCompiled.h index 2c093f3fc3..73a65a5d93 100644 --- a/src/Mod/Cloud/App/PreCompiled.h +++ b/src/Mod/Cloud/App/PreCompiled.h @@ -26,14 +26,6 @@ #include -// Exporting of App classes -#ifdef FC_OS_WIN32 -#define CloudAppExport __declspec(dllexport) -#else // for Linux -#define CloudAppExport -#endif - -#ifdef _PreComp_ // standard #include @@ -55,6 +47,4 @@ // Xerces #include -#endif //_PreComp_ - #endif diff --git a/src/Mod/Cloud/App/PreCompiled.cpp b/src/Mod/Cloud/CloudGlobal.h similarity index 75% rename from src/Mod/Cloud/App/PreCompiled.cpp rename to src/Mod/Cloud/CloudGlobal.h index d282e9a7d7..caaf18d77e 100644 --- a/src/Mod/Cloud/App/PreCompiled.cpp +++ b/src/Mod/Cloud/CloudGlobal.h @@ -1,24 +1,47 @@ -/*************************************************************************** - * Copyright (c) 2019 Jean-Marie Verdun jmverdun3@gmail.com * - * * - * 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" +/*************************************************************************** + * Copyright (c) 2021 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 * + * * + ***************************************************************************/ + +#ifndef CLOUD_GLOBAL_H +#define CLOUD_GLOBAL_H + +#include + +// Cloud +#ifndef CloudAppExport +#ifdef CloudApp_EXPORTS +#define CloudAppExport FREECAD_DECL_EXPORT +#else +#define CloudAppExport FREECAD_DECL_IMPORT +#endif +#endif + +// Cloud +#ifndef CloudGuiExport +#ifdef CloudGui_EXPORTS +#define CloudGuiExport FREECAD_DECL_EXPORT +#else +#define CloudGuiExport FREECAD_DECL_IMPORT +#endif +#endif + + +#endif // CLOUD_GLOBAL_H diff --git a/src/Mod/Cloud/Gui/AppCloudGui.cpp b/src/Mod/Cloud/Gui/AppCloudGui.cpp index f74d1a1a8d..10c14a59fd 100644 --- a/src/Mod/Cloud/Gui/AppCloudGui.cpp +++ b/src/Mod/Cloud/Gui/AppCloudGui.cpp @@ -20,7 +20,6 @@ * * ***************************************************************************/ -#include "PreCompiled.h" #include #include diff --git a/src/Mod/Cloud/Gui/CMakeLists.txt b/src/Mod/Cloud/Gui/CMakeLists.txt index c773ea7df3..73907c8152 100644 --- a/src/Mod/Cloud/Gui/CMakeLists.txt +++ b/src/Mod/Cloud/Gui/CMakeLists.txt @@ -15,7 +15,6 @@ SET(CloudGui_SRCS ${Cloud_QRC_SRCS} AppCloudGui.cpp Command.cpp - PreCompiled.cpp PreCompiled.h Workbench.cpp Workbench.h @@ -28,6 +27,12 @@ SET(Cloud_SVG add_library(CloudGui SHARED ${CloudGui_SRCS} ${Cloud_SVG}) target_link_libraries(CloudGui ${CloudGui_LIBS}) +if(FREECAD_USE_PCH) + target_precompile_headers(CloudGui PRIVATE + $<$:"${CMAKE_CURRENT_LIST_DIR}/PreCompiled.h"> + ) +endif(FREECAD_USE_PCH) + fc_copy_sources(CloudGui "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/Cloud" ${Cloud_SVG}) SET_BIN_DIR(CloudGui CloudGui /Mod/Cloud) diff --git a/src/Mod/Cloud/Gui/Command.cpp b/src/Mod/Cloud/Gui/Command.cpp index ae8f107ed5..787e2927ed 100644 --- a/src/Mod/Cloud/Gui/Command.cpp +++ b/src/Mod/Cloud/Gui/Command.cpp @@ -20,7 +20,6 @@ * * ***************************************************************************/ -#include "PreCompiled.h" #include #include diff --git a/src/Mod/Cloud/Gui/PreCompiled.cpp b/src/Mod/Cloud/Gui/PreCompiled.cpp deleted file mode 100644 index 3e276ae6b8..0000000000 --- a/src/Mod/Cloud/Gui/PreCompiled.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2019 Jean-Marie Verdun jmverdun3@gmail.com * - * * - * 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/Cloud/Gui/PreCompiled.h b/src/Mod/Cloud/Gui/PreCompiled.h index b531f3bdb1..eccac6c52a 100644 --- a/src/Mod/Cloud/Gui/PreCompiled.h +++ b/src/Mod/Cloud/Gui/PreCompiled.h @@ -26,17 +26,6 @@ #include -// Importing of App classes -#ifdef FC_OS_WIN32 -#define CloudAppExport __declspec(dllimport) -#define CloudGuiExport __declspec(dllexport) -#else // for Linux -#define CloudAppExport -#define CloudGuiExport -#endif - -#ifdef _PreComp_ - // standard #include #include @@ -60,6 +49,4 @@ // Qt Toolkit #include -#endif //_PreComp_ - #endif // GUI_PRECOMPILED_H diff --git a/src/Mod/Cloud/Gui/Workbench.cpp b/src/Mod/Cloud/Gui/Workbench.cpp index eb864c57fd..073d8f417a 100644 --- a/src/Mod/Cloud/Gui/Workbench.cpp +++ b/src/Mod/Cloud/Gui/Workbench.cpp @@ -20,7 +20,6 @@ * * ***************************************************************************/ -#include "PreCompiled.h" #include "Workbench.h" #include