-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
56 lines (50 loc) · 1.72 KB
/
Copy pathCMakeLists.txt
File metadata and controls
56 lines (50 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
cmake_minimum_required(VERSION 3.16)
project(instrument-hooks-example C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
# Define the instrument_hooks library
add_library(
instrument_hooks
STATIC
${CMAKE_CURRENT_SOURCE_DIR}/instrument-hooks/dist/core.c
)
target_include_directories(
instrument_hooks
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/instrument-hooks/includes>
$<INSTALL_INTERFACE:includes>
)
# Suppress warnings for the instrument_hooks library
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(
instrument_hooks
PRIVATE
-Wno-maybe-uninitialized
-Wno-unused-variable
-Wno-unused-parameter
-Wno-unused-but-set-variable
-Wno-type-limits
-Wno-format
-Wno-format-security
)
elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
target_compile_options(
instrument_hooks
PRIVATE
/wd4101 # unreferenced local variable (equivalent to -Wno-unused-variable)
/wd4189 # local variable is initialized but not referenced (equivalent to -Wno-unused-but-set-variable)
/wd4100 # unreferenced formal parameter (equivalent to -Wno-unused-parameter)
/wd4245 # signed/unsigned mismatch
/wd4132 # const object should be initialized
/wd4146 # unary minus operator applied to unsigned type
)
endif()
# Example executable
add_executable(example main.c)
target_link_libraries(example instrument_hooks)
# Treat warnings as errors for the example
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(example PRIVATE -Wall -Wextra -Werror)
elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
target_compile_options(example PRIVATE /W4 /WX)
endif()