Skip to content

Commit 75a827e

Browse files
committed
Add hedley to C exe projects to disable cast-qual
This warning is raised, because the destroy_library calls free on a const char* pointer, but the pointer must be cast to void* first.
1 parent 042cc80 commit 75a827e

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

cmake-init/templates/c/executable/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ target_include_directories(
2929
target_compile_features({= name =}_lib PUBLIC c_std_{= std =}){% if pm %}
3030

3131
find_package(json-c REQUIRED)
32-
target_link_libraries({= name =}_lib PRIVATE json-c::json-c){% end %}
32+
target_link_libraries({= name =}_lib PRIVATE json-c::json-c)
33+
34+
find_path(HEDLEY_INCLUDE_DIR hedley.h)
35+
if(NOT HEDLEY_INCLUDE_DIR)
36+
message(FATAL_ERROR "Couldn't find hedley.h (${HEDLEY_INCLUDE_DIR})")
37+
endif()
38+
target_include_directories(
39+
{= name =}_lib SYSTEM
40+
PRIVATE "${HEDLEY_INCLUDE_DIR}"
41+
){% end %}
3342

3443
# ---- Declare executable ----
3544

cmake-init/templates/c/executable/source/lib.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "lib.h"{% if pm %}
22

3+
#include <hedley.h>
34
#include <json-c/json_object.h>
45
#include <json-c/json_tokener.h>
56
#include <stddef.h>
@@ -57,7 +58,10 @@ library create_library()
5758
return lib;
5859
}{% if pm %}
5960

61+
HEDLEY_DIAGNOSTIC_PUSH
62+
HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
6063
void destroy_library(library* lib)
6164
{
6265
free((void*)lib->name);
63-
}{% end %}
66+
}
67+
HEDLEY_DIAGNOSTIC_POP{% end %}

cmake-init/templates/common/conanfile.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[requires]
2-
{% if c %}json-c/0.15{% else %}fmt/8.1.1{% end %}
2+
{% if c %}{% if exe %}hedley/15
3+
{% end %}json-c/0.15{% else %}fmt/8.1.1{% end %}
34

45
# Testing only dependencies below
56
catch2/2.13.8

cmake-init/templates/common/vcpkg.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
{
66
"name": "{% if c %}json-c{% else %}fmt{% end %}",
77
"version>=": "{% if c %}2019-09-10{% else %}8.1.1{% end %}"
8-
}
8+
}{% if c and exe %},
9+
{
10+
"name": "hedley",
11+
"version>=": "15"
12+
}{% end %}
913
],
1014
"default-features": [],
1115
"features": {

0 commit comments

Comments
 (0)