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