Skip to content

Commit

Permalink
use precompiled headers to speed up compile time (GPSBabel#851)
Browse files Browse the repository at this point in the history
* speed up compiles with precompiled headers.

* workaround QTBUG with precompiled headers and clang.

* avoid including QtCore.

* add ability to turn off precompiled headers.
  • Loading branch information
tsteven4 authored Feb 18, 2022
1 parent 35ea9f6 commit a5980a4
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ CMakeFiles/
*.swp
/tmp/
/mkcapabilities
/gpsbabel.gch/
/gpsbabel.rc
/autogen/
/makedoc
Expand Down
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ if(${QT_VERSION_MAJOR} EQUAL "6")
list(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::Core5Compat)
endif()

option(GPSBABEL_ENABLE_PCH "enable precompiled headers." ON)
if (GPSBABEL_ENABLE_PCH)
target_precompile_headers(gpsbabel PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:<algorithm$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<cmath$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<cstdarg$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<cstddef$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<cstdint$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<cstdio$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<ctime$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<optional$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<utility$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<QDebug$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<QList$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<QScopedPointer$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<QString$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<QTextCodec$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<QVector$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<Qt$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<QtGlobal$<ANGLE-R>>"
)
endif()

# RESOURCES
set(RESOURCES gpsbabel.qrc)

Expand Down
9 changes: 9 additions & 0 deletions GPSBabel.pro
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ CONFIG += console
CONFIG -= app_bundle
CONFIG += c++17
CONFIG += link_pkgconfig
!disable_pch {
# avoid QTBUG-72404, QTBUG-79694 which were fixed in 5.14.0
versionAtLeast(QT_VERSION, 5.14.0) | !contains(QMAKE_CXX, .*clang.*) {
CONFIG += precompile_header
PRECOMPILED_HEADER = precompiled_headers.h
} else {
message("Not using precompiled headers due to QTBUG.")
}
}

TEMPLATE = app

Expand Down
2 changes: 1 addition & 1 deletion mynav.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <QStringList>
#include <QtGlobal>

#include <src/core/textstream.h>
#include "src/core/textstream.h"

#include "mynav.h"

Expand Down
41 changes: 41 additions & 0 deletions precompiled_headers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright (C) 2002-2014 Robert Lipe, [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

// This list is from defs.h. Adding other commonly used headers doesn't help.

#if defined __cplusplus
#include <algorithm> // for sort, stable_sort
#include <cmath> // for M_PI
#include <cstdarg> // for va_list
#include <cstddef> // for NULL, nullptr_t, size_t
#include <cstdint> // for int32_t, uint32_t
#include <cstdio> // for NULL, fprintf, FILE, stdout
#include <ctime> // for time_t
#include <optional> // for optional
#include <utility> // for move

#include <QDebug> // for QDebug
#include <QList> // for QList, QList<>::const_reverse_iterator, QList<>::reverse_iterator
#include <QScopedPointer> // for QScopedPointer
#include <QString> // for QString
#include <QTextCodec> // for QTextCodec
#include <QVector> // for QVector
#include <Qt> // for CaseInsensitive
#include <QtGlobal> // for foreach
#endif
2 changes: 1 addition & 1 deletion src/core/codecdevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*/

#include <cassert> // for assert
#include <cstring> // for memcpy
#include <algorithm> // for min

#include <QByteArray> // for QByteArray
#include <QChar> // for QChar
#include <QFile> // for QFile
#include <QFlags> // for QFlags

#include "defs.h" // for list_codecs, warning
Expand Down
3 changes: 2 additions & 1 deletion src/core/codecdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
*/

#include <QIODevice> // for QIODevice
#include <QIODeviceBase> // for QIODeviceBase::OpenMode
#include <QString> // for QString
#include <QTextCodec> // for QTextCodec
#include <QTextDecoder> // for QTextDecoder
#include <QTextEncoder> // for QTextEncoder
#include <QtCore> // for qint64, QIODeviceBase::OpenMode
#include <QtGlobal> // for qint64

#include "src/core/file.h" // for File

Expand Down
2 changes: 1 addition & 1 deletion src/core/textstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/


#include <QtCore> // for qint64, QT_VERSION, QT_VERSION_CHECK
#include <QtGlobal> // for qint64, QT_VERSION, QT_VERSION_CHECK

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
#include <QByteArrayView> // for QByteArrayView
Expand Down

0 comments on commit a5980a4

Please sign in to comment.