-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
87 lines (72 loc) · 2.61 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
cmake_minimum_required(VERSION 3.6)
project(rptree C)
set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Install path prefix")
set(src rptree.c rpshell.c procfs.c cJSON.c libxopt.c)
add_compile_options(-Wall)
add_compile_options(-fstack-protector)
add_compile_options(-Werror)
add_compile_options(-Wfatal-errors)
add_compile_options(-Wno-unused-result)
add_compile_options(-Wsign-compare)
if (NOT DEFINED VERSION)
set(SCMVERSION "")
execute_process(
COMMAND cat .scmversion
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
ERROR_QUIET
OUTPUT_VARIABLE SCMVERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git describe --tags
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
ERROR_QUIET
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git rev-parse --short=20 HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
ERROR_QUIET
OUTPUT_VARIABLE GIT_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (SCMVERSION)
set(VERSION "${SCMVERSION}")
message(STATUS "scmversion: ${VERSION}")
elseif(GIT_VERSION)
set(VERSION "${GIT_VERSION}")
message(STATUS "Auto generated version: ${VERSION}")
else()
set(VERSION "${GIT_COMMIT}")
message(STATUS "Auto generated commit version: ${VERSION}")
endif()
endif()
add_compile_options(-DRPTREE_VERSION="${VERSION}")
option(DEBUG "Compile in debug mode" OFF)
if (DEBUG)
add_compile_options(-O0)
add_compile_options(-g)
else()
add_compile_options(-O2)
endif()
add_executable(rptree ${src})
install(TARGETS rptree RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
# Add test functions
enable_testing()
function(add_rptree_shell_test TEST_NAME)
find_program(BASH_PROGRAM bash)
if (BASH_PROGRAM)
add_test(
NAME ${TEST_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_NAME}
COMMAND ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/tests/test.sh ${TEST_NAME}
)
set_property(
TEST ${TEST_NAME}
PROPERTY ENVIRONMENT
"CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
)
endif()
endfunction()
add_rptree_shell_test(smart)