Start: 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 <PreCompiled.h>" from sources, also
there is no need for the "#ifdef _PreComp_" anymore
This commit is contained in:
Markus Reitböck
2025-09-13 17:27:21 +02:00
parent 05a706697b
commit 412b72d8d6
24 changed files with 23 additions and 114 deletions

View File

@@ -21,7 +21,6 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#include <Base/Interpreter.h>
#include <Base/Tools.h>

View File

@@ -35,7 +35,6 @@ set(Start_SRCS
CustomFolderModel.h
FileUtilities.cpp
FileUtilities.h
PreCompiled.cpp
PreCompiled.h
RecentFilesModel.cpp
RecentFilesModel.h
@@ -43,6 +42,13 @@ set(Start_SRCS
ThumbnailSource.h)
add_library(Start SHARED ${Start_SRCS})
if(FREECAD_USE_PCH)
target_precompile_headers(Start PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:"${CMAKE_CURRENT_LIST_DIR}/PreCompiled.h">
)
endif(FREECAD_USE_PCH)
target_link_libraries(Start ${Start_LIBS})
if (FREECAD_WARN_ERROR)
target_compile_warn_error(Start)

View File

@@ -21,10 +21,7 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QDir>
#endif
#include "CustomFolderModel.h"
#include <App/Application.h>

View File

@@ -21,8 +21,6 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <boost/algorithm/string/predicate.hpp>
#include <QByteArray>
#include <QFileInfo>
@@ -30,7 +28,7 @@
#include <QTimeZone>
#include <QThreadPool>
#include <QUrl>
#endif
#include "DisplayedFilesModel.h"

View File

@@ -21,10 +21,8 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QDir>
#endif
#include "ExamplesModel.h"
#include <App/Application.h>

View File

@@ -21,8 +21,6 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QCryptographicHash>
#include <QDateTime>
#include <QFileInfo>
@@ -30,7 +28,6 @@
#include <QTimeZone>
#include <QUrl>
#include <fmt/format.h>
#endif
#include "FileUtilities.h"
#include <Base/TimeInfo.h>

View File

@@ -1,25 +0,0 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/****************************************************************************
* *
# Copyright (c) 2024 The FreeCAD Project Association AISBL *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#include "PreCompiled.h"

View File

@@ -26,8 +26,6 @@
#include <FCConfig.h>
#ifdef _PreComp_
// standard
#include <cinttypes>
#include <cmath>
@@ -62,5 +60,4 @@
#include <QTimer>
#include <QUrl>
#endif // _PreComp_
#endif // START_PRECOMPILED_H

View File

@@ -21,10 +21,6 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include "RecentFilesModel.h"
#include <App/Application.h>
#include <App/ProjectFile.h>

View File

@@ -21,15 +21,12 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QFile>
#include <QMetaObject>
#include <QMutexLocker>
#include <QObject>
#include <QProcess>
#include <QTimer>
#endif
#include "ThumbnailSource.h"

View File

@@ -21,11 +21,9 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QString>
#include <QTimer>
#endif
#include <Base/Console.h>
#include <Base/Interpreter.h>

View File

@@ -57,7 +57,6 @@ SET(StartGui_SRCS
Manipulator.h
NewFileButton.cpp
NewFileButton.h
PreCompiled.cpp
PreCompiled.h
StartView.cpp
StartView.h
@@ -76,13 +75,6 @@ SET(StartGuiThumbnail_PNG
Resources/thumbnails/Theme_thumbnail_light.png
)
# TODO: Evaluate PCH use with Qt6/QtQuick/Qml
if (FREECAD_USE_PCH)
add_definitions(-D_PreComp_)
GET_MSVC_PRECOMPILED_SOURCE("PreCompiled.cpp" PCH_SRCS ${StartGui_SRCS})
ADD_MSVC_PRECOMPILED_HEADER(StartGui PreCompiled.h PreCompiled.cpp PCH_SRCS)
endif (FREECAD_USE_PCH)
# Add CoreFoundation to StartGui_LIBS on macOS
if (APPLE)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
@@ -99,6 +91,13 @@ add_library(StartGui SHARED
${StartGuiThumbnail_PNG}
)
# TODO: Evaluate PCH use with Qt6/QtQuick/Qml
if(FREECAD_USE_PCH)
target_precompile_headers(StartGui PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:"${CMAKE_CURRENT_LIST_DIR}/PreCompiled.h">
)
endif(FREECAD_USE_PCH)
target_include_directories(
StartGui
PRIVATE

View File

@@ -20,7 +20,6 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#include <Gui/Application.h>

View File

@@ -21,9 +21,6 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QFile>
#include <QFileIconProvider>
#include <QImageReader>
@@ -36,7 +33,6 @@
#include <QPushButton>
#include <QString>
#include <QAbstractItemView>
#endif
#include "FileCardDelegate.h"
#include "../App/DisplayedFilesModel.h"

View File

@@ -21,7 +21,6 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#include "FileCardView.h"
#include <App/Application.h>

View File

@@ -21,9 +21,7 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QGuiApplication>
#include <QHBoxLayout>
#include <QLabel>
@@ -31,7 +29,7 @@
#include <QResizeEvent>
#include <QVBoxLayout>
#include <QWidget>
#endif
#include "FirstStartWidget.h"
#include "ThemeSelectorWidget.h"

View File

@@ -21,7 +21,6 @@
* *
**************************************************************************/
#include "PreCompiled.h"
#include <QWidget>
#include "FlowLayout.h"

View File

@@ -21,8 +21,6 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QApplication>
#include <QComboBox>
#include <QGridLayout>
@@ -31,7 +29,7 @@
#include <QToolButton>
#include <QVBoxLayout>
#include <QWidget>
#endif
#include <algorithm>
#include "GeneralSettingsWidget.h"

View File

@@ -21,12 +21,10 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QCoreApplication>
#include <QCoreApplication>
#include <QLayout>
#endif
#include "Manipulator.h"
#include "StartView.h"

View File

@@ -21,16 +21,12 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QLabel>
#include <QFont>
#include <QIcon>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QString>
#endif
#include "NewFileButton.h"
#include <algorithm>

View File

@@ -1,25 +0,0 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/****************************************************************************
* *
# Copyright (c) 2024 The FreeCAD Project Association AISBL *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#include "PreCompiled.h"

View File

@@ -26,8 +26,6 @@
#include <FCConfig.h>
#ifdef _PreComp_
// standard
#include <cinttypes>
#include <cmath>
@@ -72,5 +70,4 @@
#include <QVBoxLayout>
#include <QWidget>
#endif // _PreComp_
#endif // STARTGUI_PRECOMPILED_H

View File

@@ -21,9 +21,7 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QApplication>
#include <QCheckBox>
#include <QFrame>
@@ -38,7 +36,6 @@
#include <QWidget>
#include <QStackedWidget>
#include <QShowEvent>
#endif
#include "StartView.h"
#include "FileCardDelegate.h"

View File

@@ -21,15 +21,13 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QGuiApplication>
#include <QHBoxLayout>
#include <QLabel>
#include <QString>
#include <QStyleHints>
#include <QToolButton>
#endif
#include "ThemeSelectorWidget.h"
#include <gsl/pointers>
@@ -37,6 +35,8 @@
#include <Gui/Command.h>
#include <Gui/PreferencePackManager.h>
#include <FCConfig.h>
#ifdef FC_OS_MACOSX
#include <CoreFoundation/CoreFoundation.h>
#endif