Skip to content

Commit

Permalink
add KDBINDINGS_ENABLE_WARN_UNUSED as a cmake option
Browse files Browse the repository at this point in the history
  • Loading branch information
phyBrackets authored and LeonMatthesKDAB committed Jun 4, 2024
1 parent 7f948f0 commit c0c23c8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
10 changes: 10 additions & 0 deletions cmake/KDBindingsConfig.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

// Check if KDBINDINGS_ENABLE_WARN_UNUSED option is set
#cmakedefine KDBINDINGS_ENABLE_WARN_UNUSED

#ifdef KDBINDINGS_ENABLE_WARN_UNUSED
#define KDBINDINGS_WARN_UNUSED [[nodiscard]]
#else
#define KDBINDINGS_WARN_UNUSED
#endif
8 changes: 8 additions & 0 deletions src/kdbindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
# Contact KDAB at <info@kdab.com> for commercial licensing options.
#

option(KDBINDINGS_ENABLE_WARN_UNUSED "Enable warnings for unused ConnectionHandles" OFF)

configure_file(
"${PROJECT_SOURCE_DIR}/cmake/KDBindingsConfig.h.in"
"${CMAKE_BINARY_DIR}/include/KDBindingsConfig.h"
)

set(HEADERS
binding.h
binding_evaluator.h
Expand Down Expand Up @@ -36,6 +43,7 @@ set_target_properties(KDBindings PROPERTIES
target_include_directories(KDBindings INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include> # Include the build directory for the configured header
)
if(KDBindings_ERROR_ON_WARNING)
if(MSVC)
Expand Down
7 changes: 2 additions & 5 deletions src/kdbindings/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@

#pragma once

// Enables compiler warnings for unused ConnectionHandle results.
#ifndef KDBINDINGS_WARN_UNUSED
#define KDBINDINGS_WARN_UNUSED [[nodiscard]]
#endif

#include <assert.h>
#include <memory>
#include <stdexcept>
Expand All @@ -26,6 +21,8 @@
#include <kdbindings/genindex_array.h>
#include <kdbindings/utils.h>

#include <KDBindingsConfig.h>

/**
* @brief The main namespace of the KDBindings library.
*
Expand Down

0 comments on commit c0c23c8

Please sign in to comment.