-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
90 lines (77 loc) · 2.29 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
cmake_minimum_required(VERSION 2.4.0)
enable_testing()
project(c_example)
set(CMAKE_VERBOSE_MAKEFILE ON)
# Set the option to compile the executable file
option(IS_EXECUTE "Compile the executable file" ON)
# set output directory
if(IS_EXECUTE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
else()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/uc_sgsim/c_core")
endif()
include_directories(${CMAKE_SOURCE_DIR})
# run CMakeLists in uc_sgsim folder
add_subdirectory(uc_sgsim)
# compile and install executable file
if(IS_EXECUTE)
add_executable(c_example c_example.c)
target_link_libraries(c_example uc_sgsim)
if(WIN32)
set_target_properties(c_example PROPERTIES SUFFIX ".exe")
else()
set_target_properties(c_example PROPERTIES SUFFIX ".out")
endif()
# make sure example can run
add_test(
c_example
${CMAKE_COMMAND}
--build ${CMAKE_BINARY_DIR}
--target c_example
)
# memory check (valgrind)
find_program(VALGRIND "valgrind")
if(VALGRIND)
add_custom_target(
memcheck
COMMAND ${VALGRIND}
--tool=memcheck
--leak-check=full
--track-origins=yes
--show-reachable=yes
--error-exitcode=1
$<TARGET_FILE:c_example>
)
endif()
endif()
# unittest
if(IS_EXECUTE)
project(unittest)
include(Dart)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CTEST_COVERAGE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/coverage")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/test)
set(CTEST_COVERAGE_EXCLUDE
'/usr/include/*' # Exclude system headers
'${CMAKE_CURRENT_SOURCE_DIR}/test/utest.h' # Exclude a specific file
'${CMAKE_CURRENT_SOURCE_DIR}/src/c_array.c'
'${CMAKE_CURRENT_SOURCE_DIR}/src/c_array_mt.c'
'${CMAKE_CURRENT_SOURCE_DIR}/include/c_array.h'
)
add_custom_target(
coverage
COMMAND ctest -T Coverage
)
add_subdirectory(uc_sgsim)
add_executable(
unittest
uc_sgsim/c_core/tests/sgsim_test.c
)
target_link_libraries(unittest uc_sgsim)
add_test(
unittest
${CMAKE_COMMAND}
--build ${CMAKE_BINARY_DIR}
--target unittest
)
endif()