-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
94 lines (67 loc) · 2.52 KB
/
CMakeLists.txt
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
82
83
84
85
86
87
88
89
90
91
92
93
94
cmake_minimum_required(VERSION 3.10)
project(mycodetest)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include_directories(include)
add_subdirectory(thirdlib/googletest)
set(SOURCE_FILES
src/main.cpp
include/sample_head.cpp
include/vector_process.cpp
include/multi_physics_simulator.cpp
include/Components/RobotComponent.cpp
include/Components/RobotArm.cpp
include/Components/Joint.cpp
include/Components/EndEffector.cpp
)
set(HEADER_FILES
include/sample_head.h
include/vector_process.h
include/multi_physics_simulator.h
include/Components/RobotComponent.h
include/Components/RobotArm.h
include/Components/Joint.h
include/Components/EndEffector.h
)
# add_executable(main ${SOURCE_FILES})
########################### cppcheck ###########################
set(CPPCHECK_EXECUTABLE "${CMAKE_SOURCE_DIR}/thirdlib/cppcheck/cppcheck.exe")
if(NOT EXISTS "${CPPCHECK_EXECUTABLE}")
message(FATAL_ERROR "Cppcheck executable not found: ${CPPCHECK_EXECUTABLE}")
endif()
set(CPPCHECK_RESULTS_FILE "cppcheck_results.txt")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}")
add_custom_command(
OUTPUT ${CPPCHECK_RESULTS_FILE}
COMMAND ${CPPCHECK_EXECUTABLE} --enable=all --verbose ${CMAKE_SOURCE_DIR}
COMMAND echo "Running cppcheck" > ${CPPCHECK_RESULTS_FILE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(cppcheck DEPENDS ${CPPCHECK_RESULTS_FILE})
# add_dependencies(main cppcheck)
########################### test Code ###########################
set(TEST_SOURCE_FILES
# tests/sample_head_test.cpp
tests/components_test.cpp
)
add_executable(runTests ${TEST_SOURCE_FILES} ${SOURCE_FILES})
target_link_libraries(runTests gtest_main)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
enable_testing()
add_test(NAME AllTests COMMAND runTests)
set(TEST_OUTPUT_FILE "test_output.txt")
add_custom_command(
OUTPUT ${TEST_OUTPUT_FILE}
COMMAND $<TARGET_FILE:runTests> > "${TEST_OUTPUT_FILE}"
DEPENDS runTests
)
add_custom_target(runTestsAndSaveOutput
DEPENDS ${TEST_OUTPUT_FILE}
)
add_custom_command(TARGET runTestsAndSaveOutput POST_BUILD
COMMAND $<TARGET_FILE:runTests> > "${TEST_OUTPUT_FILE}"
)
add_dependencies(runTestsAndSaveOutput cppcheck)
# 打印测试可执行文件路径
message(STATUS "Test executable path: $<TARGET_FILE:runTests>")