-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathmvsim_cmake_functions.cmake
82 lines (70 loc) · 2.58 KB
/
mvsim_cmake_functions.cmake
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
71
72
73
74
75
76
77
78
79
80
81
# -----------------------------------------------------------------------------
# mvsim_set_target_build_options(target)
#
# Set defaults for each MVSIM cmake target
# -----------------------------------------------------------------------------
function(mvsim_set_target_build_options TARGETNAME)
# Build for C++17
# Not needed, automatically imported from mrpt targets.
# Warning level:
if (MSVC)
# msvc:
target_compile_options(${TARGETNAME} PRIVATE /W3)
target_compile_definitions(${TARGETNAME} PRIVATE
_CRT_SECURE_NO_DEPRECATE
_CRT_NONSTDC_NO_DEPRECATE
_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
)
else()
# gcc & clang:
target_compile_options(${TARGETNAME} PRIVATE
-Wall -Wextra -Wshadow
-Werror=return-type # error on missing return();
-Wtype-limits -Wcast-align -Wparentheses
-fPIC
)
endif()
# Optimization:
# -------------------------
if((NOT MSVC) AND (NOT CMAKE_CROSSCOMPILING))
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${TARGETNAME} PRIVATE -O3)
endif()
endif()
endfunction()
# -----------------------------------------------------------------------------
# mvsim_add_test(
# TARGET name
# SOURCES ${SRC_FILES}
# [LINK_LIBRARIES lib1 lib2]
# )
#
# Defines a MVSIM unit test
# -----------------------------------------------------------------------------
function(mvsim_add_test)
set(oneValueArgs TARGET)
set(multiValueArgs SOURCES LINK_LIBRARIES)
cmake_parse_arguments(mvsim_add_test "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
add_executable(${mvsim_add_test_TARGET}
${mvsim_add_test_SOURCES}
)
# Define common flags:
mvsim_set_target_build_options(${mvsim_add_test_TARGET})
# lib Dependencies:
if (mvsim_add_test_LINK_LIBRARIES)
target_link_libraries(
${mvsim_add_test_TARGET}
${mvsim_add_test_LINK_LIBRARIES}
)
endif()
# Macro for source dir path:
target_compile_definitions(${mvsim_add_test_TARGET} PRIVATE
MVSIM_TEST_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"
)
# Run it:
add_custom_target(run_${mvsim_add_test_TARGET} COMMAND $<TARGET_FILE:${mvsim_add_test_TARGET}>)
add_test(${mvsim_add_test_TARGET}_build "${CMAKE_COMMAND}" --build ${CMAKE_CURRENT_BINARY_DIR} --target ${mvsim_add_test_TARGET})
add_test(run_${mvsim_add_test_TARGET} ${EXECUTABLE_OUTPUT_PATH}/${mvsim_add_test_TARGET})
set_tests_properties(run_${mvsim_add_test_TARGET} PROPERTIES DEPENDS ${mvsim_add_test_TARGET}_build)
add_dependencies(run_${mvsim_add_test_TARGET} ${mvsim_add_test_TARGET})
endfunction()