-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeMacro.cmake
More file actions
70 lines (59 loc) · 2.05 KB
/
CMakeMacro.cmake
File metadata and controls
70 lines (59 loc) · 2.05 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright © 2025 Chee Bin HOH. All rights reserved.
#
# This defines reusable CMake macro
#
# This macro builds a test executable and add the test to ctest run
macro(ADD_TEST_EXECUTABLE ...)
foreach (arg ${ARGN})
message("adding test executable ${arg}")
add_executable(${arg}
${arg}.cpp)
target_include_directories(${arg}
PRIVATE
${PROJECT_SOURCE_DIR}/include)
target_compile_options(${arg}
PRIVATE
-Wall -Wextra -Wpedantic)
target_link_libraries(${arg}
PRIVATE
gtest_main
gtest
dmn
protobuf::libprotobuf
)
add_test(NAME ${arg} COMMAND ${arg})
set_tests_properties(${arg} PROPERTIES LABELS "dmn")
endforeach()
endmacro()
# This macro run valgrind with the list of applications as unit test
macro(ADD_TEST_VALGRIND ...)
foreach (arg ${ARGN})
message(STATUS "adding test executable ${arg} for valgrind")
add_test(
NAME valgrind-${arg}
COMMAND
${VALGRIND_EXECUTABLE}
--quiet
--error-exitcode=42
--leak-check=full
--show-leak-kinds=all
--track-origins=yes
$<TARGET_FILE:${arg}>
)
set_tests_properties(valgrind-${arg} PROPERTIES LABELS "valgrind")
endforeach()
endmacro()
# This macro run protoc to generate *.pb.cc and *.pb.h from a
# proto definition file
macro(GENERATE_PROTOBUF ...)
foreach(arg ${ARGN})
target_include_directories(${ARGV0} PRIVATE
${CMAKE_CURRENT_BINARY_DIR})
protobuf_generate(TARGET ${ARGV0}
PROTOS ${CMAKE_CURRENT_SOURCE_DIR}/proto/${arg}
LANGUAGE cpp
OUT_VAR PROTOBUF_GENERATED_FILES
PROTOC_OPTIONS "-I${protobuf_SOURCE_DIR}/src"
PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
endforeach()
endmacro()