Skip to content

Commit

Permalink
Generate config-perfparser.h using cmake
Browse files Browse the repository at this point in the history
This allows to use cmakedefine01 and -Werror=undef

Took some more -W flags from extra-cmake-modules while at it
  • Loading branch information
dfaure authored and milianw committed Oct 15, 2023
1 parent b140139 commit 2408135
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,12 @@ add_definitions(-DQT_NO_CAST_FROM_ASCII
-DQT_NO_CAST_TO_ASCII
-DQT_USE_QSTRINGBUILDER
-DQT_NO_FOREACH)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long -Wpointer-arith -Wnon-virtual-dtor -Woverloaded-virtual")
# Make some warnings errors
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type -Werror=init-self -Werror=undef")
endif()

add_subdirectory(app)
add_subdirectory(tests)
6 changes: 4 additions & 2 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ add_qtc_library(perfparser_lib STATIC
if (Zstd_FOUND)
target_include_directories(perfparser_lib PUBLIC ${Zstd_INCLUDE_DIR})
target_link_libraries(perfparser_lib PUBLIC ${Zstd_LIBRARY})
target_compile_definitions(perfparser_lib PUBLIC HAVE_ZSTD)
set(HAVE_ZSTD 1)
endif()

if (HAVE_DWFL_GET_DEBUGINFOD_CLIENT)
target_link_libraries(perfparser_lib PRIVATE elfutils::debuginfod)
target_compile_definitions(perfparser_lib PRIVATE HAVE_DWFL_GET_DEBUGINFOD_CLIENT)
set(HAVE_DWFL_GET_DEBUGINFOD_CLIENT 1)
endif()

configure_file(config-perfparser.h.in config-perfparser.h)

add_qtc_executable(perfparser
DEPENDS
perfparser_lib
Expand Down
21 changes: 21 additions & 0 deletions app/config-perfparser.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/****************************************************************************
**
** Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected], author David Faure <[email protected]>
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Enterprise Perf Profiler Add-on.
**
** GNU General Public License Usage
** This file may be used under the terms of the GNU General Public License
** version 3 as published by the Free Software Foundation and appearing in
** the file LICENSE.GPLv3 included in the packaging of this file. Please
** review the following information to ensure the GNU General Public License
** requirements will be met: https://www.gnu.org/licenses/gpl.html.
**
** If you have questions regarding the use of this file, please use
** contact form at http://www.qt.io/contact-us
**
****************************************************************************/

#cmakedefine01 HAVE_ZSTD
#cmakedefine01 HAVE_DWFL_GET_DEBUGINFOD_CLIENT
4 changes: 2 additions & 2 deletions app/perfdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ PerfData::PerfData(PerfUnwind *destination, const PerfHeader *header, PerfAttrib

PerfData::~PerfData()
{
#ifdef HAVE_ZSTD
#if HAVE_ZSTD
if (m_zstdDstream)
ZSTD_freeDStream(m_zstdDstream);
#endif
Expand Down Expand Up @@ -263,7 +263,7 @@ PerfData::ReadStatus PerfData::processEvents(QDataStream &stream)
break;
}

#ifdef HAVE_ZSTD
#if HAVE_ZSTD
case PERF_RECORD_COMPRESSED: {
if (!m_zstdDstream) {
if (!m_header->hasFeature(PerfHeader::COMPRESSED)) {
Expand Down
6 changes: 4 additions & 2 deletions app/perfdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
#include "perffeatures.h"
#include "perfheader.h"

#include <config-perfparser.h> // generated by cmake

#include <QIODevice>

#ifdef HAVE_ZSTD
#if HAVE_ZSTD
#include <zstd.h>

constexpr bool CAN_DECOMPRESS_ZSTD = true;
Expand Down Expand Up @@ -660,7 +662,7 @@ public slots:
QByteArray m_decompressBuffer;
QByteArray m_compressedBuffer;
int m_remaininingDecompressedDataSize = 0;
#ifdef HAVE_ZSTD
#if HAVE_ZSTD
ZSTD_DStream *m_zstdDstream = nullptr;
#endif

Expand Down
6 changes: 4 additions & 2 deletions app/perfsymboltable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
#include <dwarf.h>
#include <elfutils/libdwelf.h>

#ifdef HAVE_DWFL_GET_DEBUGINFOD_CLIENT
#include <config-perfparser.h> // generated by cmake

#if HAVE_DWFL_GET_DEBUGINFOD_CLIENT
#include <debuginfod.h>
#endif

Expand Down Expand Up @@ -70,7 +72,7 @@ PerfSymbolTable::PerfSymbolTable(qint32 pid, Dwfl_Callbacks *callbacks, PerfUnwi

m_dwfl = dwfl_begin(m_callbacks);

#ifdef HAVE_DWFL_GET_DEBUGINFOD_CLIENT
#if HAVE_DWFL_GET_DEBUGINFOD_CLIENT
auto client = dwfl_get_debuginfod_client(m_dwfl);
debuginfod_set_user_data(client, this);
debuginfod_set_progressfn(client, [](debuginfod_client* client, long numerator, long denominator) {
Expand Down
2 changes: 1 addition & 1 deletion tests/auto/perfdata/tst_perfdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void TestPerfData::testFiles_data()
void TestPerfData::testFiles()
{
QFETCH(QString, dataFile);
#ifndef HAVE_ZSTD
#if !HAVE_ZSTD
if (dataFile.contains(QStringLiteral("zstd")))
QSKIP("zstd support disabled, skipping test");
#endif
Expand Down

0 comments on commit 2408135

Please sign in to comment.