/
CMakeLists.txt
115 lines (92 loc) · 4.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Copyright (C) 2014 Leandro Lisboa Penz <lpenz@lpenz.org>
# This file is subject to the terms and conditions defined in
# file 'LICENSE', which is part of this source code package.
cmake_minimum_required (VERSION 2.6)
project (execpermfix)
include(GNUInstallDirs)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -W")
endif(CMAKE_COMPILER_IS_GNUCXX)
# Main targets
include_directories(include)
add_executable(execpermfix src/execpermfix.c src/execpermfix_main.c)
# Manual
add_custom_command(
OUTPUT execpermfix.1.gz
DEPENDS execpermfix.1
COMMAND gzip -9kc
${CMAKE_CURRENT_SOURCE_DIR}/execpermfix.1 >
${CMAKE_CURRENT_BINARY_DIR}/execpermfix.1.gz
)
add_custom_target(manual ALL DEPENDS execpermfix.1.gz)
# Install
install (
TARGETS execpermfix
DESTINATION bin/
)
install (
FILES ${CMAKE_CURRENT_BINARY_DIR}/execpermfix.1.gz
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1/
)
install (
FILES README.md LICENSE AUTHORS
DESTINATION ${CMAKE_INSTALL_DOCDIR}/
)
# cpack deb
set(CPACK_GENERATOR DEB)
set(CPACK_PACKAGE_CONTACT "Leandro Lisboa Penz <lpenz@lpenz.org>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Fixes executable permissions")
set(CPACK_DEBIAN_PACKAGE_SECTION utils)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
execute_process(COMMAND git describe --tags
OUTPUT_VARIABLE GIT_DESCRIBE)
string(REGEX REPLACE "-g[0-9a-f]+\n$" "" CPACK_PACKAGE_VERSION "${GIT_DESCRIBE}")
set(CPACK_PACKAGE_FILE_NAME "execpermfix-${CPACK_PACKAGE_VERSION}")
include(CPack)
# Tests
include(CTest)
add_executable(testhelper test/testhelper.c src/execpermfix.c)
add_test (NAME test_execpermfix_help
COMMAND execpermfix -h)
set_tests_properties(test_execpermfix_help PROPERTIES PASS_REGULAR_EXPRESSION "Usage:")
add_test (NAME test_execpermfix_help2
COMMAND execpermfix -?)
set_tests_properties(test_execpermfix_help2 PROPERTIES WILL_FAIL true)
add_test (NAME test_execpermfix_version
COMMAND execpermfix -V)
add_test (NAME test_execpermfix_invalid
COMMAND execpermfix -?)
set_tests_properties(test_execpermfix_invalid PROPERTIES WILL_FAIL true)
add_test (NAME test_execpermfix_null
COMMAND execpermfix /dev/null)
add_test (NAME test_execpermfix_notfound
COMMAND execpermfix /notfound)
set_tests_properties(test_execpermfix_notfound PROPERTIES WILL_FAIL true)
execute_process(COMMAND mkdir -p _tmp/dir)
execute_process(COMMAND printf \#!/bin/sh\n\n OUTPUT_FILE _tmp/script)
execute_process(COMMAND printf bin/sh\n\n OUTPUT_FILE _tmp/none)
execute_process(COMMAND cp -L /bin/ls _tmp OUTPUT_FILE _tmp/ls)
add_test (NAME test_execpermfix_script_setU COMMAND ./testhelper _tmp/script 0600 0700)
add_test (NAME test_execpermfix_script_setG COMMAND ./testhelper _tmp/script 0640 0750)
add_test (NAME test_execpermfix_script_setO COMMAND ./testhelper _tmp/script 0644 0755)
add_test (NAME test_execpermfix_script_keeU COMMAND ./testhelper _tmp/script 0700 0700)
add_test (NAME test_execpermfix_script_keeG COMMAND ./testhelper _tmp/script 0750 0750)
add_test (NAME test_execpermfix_script_keeO COMMAND ./testhelper _tmp/script 0755 0755)
add_test (NAME test_execpermfix_binary_setU COMMAND ./testhelper _tmp/ls 0600 0700)
add_test (NAME test_execpermfix_binary_setG COMMAND ./testhelper _tmp/ls 0640 0750)
add_test (NAME test_execpermfix_binary_setO COMMAND ./testhelper _tmp/ls 0644 0755)
add_test (NAME test_execpermfix_binary_keeU COMMAND ./testhelper _tmp/ls 0700 0700)
add_test (NAME test_execpermfix_binary_keeG COMMAND ./testhelper _tmp/ls 0750 0750)
add_test (NAME test_execpermfix_binary_keeO COMMAND ./testhelper _tmp/ls 0755 0755)
add_test (NAME test_execpermfix_directory_setU COMMAND ./testhelper _tmp/dir 0600 0700)
add_test (NAME test_execpermfix_directory_setG COMMAND ./testhelper _tmp/dir 0640 0750)
add_test (NAME test_execpermfix_directory_setO COMMAND ./testhelper _tmp/dir 0644 0755)
add_test (NAME test_execpermfix_directory_keeU COMMAND ./testhelper _tmp/dir 0700 0700)
add_test (NAME test_execpermfix_directory_keeG COMMAND ./testhelper _tmp/dir 0750 0750)
add_test (NAME test_execpermfix_directory_keeO COMMAND ./testhelper _tmp/dir 0755 0755)
add_test (NAME test_execpermfix_none_clearU COMMAND ./testhelper _tmp/none 0700 0600)
add_test (NAME test_execpermfix_none_clearG COMMAND ./testhelper _tmp/none 0750 0640)
add_test (NAME test_execpermfix_none_clearO COMMAND ./testhelper _tmp/none 0755 0644)
add_test (NAME test_execpermfix_none_keepU COMMAND ./testhelper _tmp/none 0600 0600)
add_test (NAME test_execpermfix_none_keepG COMMAND ./testhelper _tmp/none 0640 0640)
add_test (NAME test_execpermfix_none_keepO COMMAND ./testhelper _tmp/none 0644 0644)