aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: a7d99c1e59605715f59fc29f2d5fa8b1e41ab551 (plain) (blame)
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
cmake_minimum_required(VERSION 3.15...4.0)

project(dir_monitor
    LANGUAGES C
)

# Although C11 would be sufficient, be safe to set this minimum in order to
# prevent errors from unbeknown features, used to and assuming to be there longer...
set (CMAKE_C_STANDARD 17)

add_compile_options(-Wall -Wextra -Wformat -Wformat=2 -Wconversion -Wimplicit-fallthrough -Werror=format-security
    -Wbidi-chars=any -Werror=implicit -Werror=incompatible-pointer-types -Werror=int-conversion
    -fno-delete-null-pointer-checks -fstack-clash-protection -fstack-protector-strong -fstrict-flex-arrays=3)

set(SOURCE_DM src/dir_monitor.c src/data_management.c  src/options.c  src/output.c)

add_executable(dir_monitor_debug ${SOURCE_DM})
target_include_directories(dir_monitor_debug PRIVATE include)
target_compile_options(dir_monitor_debug PUBLIC -g -DDEBUGBUILD -Werror)

add_executable(dir_monitor_debug_asan ${SOURCE_DM})
target_include_directories(dir_monitor_debug_asan PRIVATE include)
target_compile_options(dir_monitor_debug_asan PUBLIC -g -DDEBUGBUILD -fsanitize=address -Werror)
target_link_libraries(dir_monitor_debug_asan asan)

add_executable(dir_monitor_asan ${SOURCE_DM})
target_include_directories(dir_monitor_asan PRIVATE include)
target_compile_options(dir_monitor_asan PUBLIC -fsanitize=address)
target_link_libraries(dir_monitor_asan asan)

add_executable(dir_monitor ${SOURCE_DM})
target_include_directories(dir_monitor PRIVATE include)
target_compile_options(dir_monitor PUBLIC -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -FPIE -pie -Wl,-z,noexecstack -Wl,--as-needed -Wl,--no-copy-dt-needed-entries)


# The man page generation...

find_program(ASCIIDOC_EXEC NAMES asciidoc)
if (NOT ASCIIDOC_EXEC)
    message(WARNING "Can't find asciidoc, skip manpage generation")
    return()
endif()

find_program(XMLTO_EXEC NAMES xmlto)
if (NOT XMLTO_EXEC)
    message(WARNING "Can't find xmlto, skip manpage generation")
    return()
endif()

find_program(COMPRESS_EXEC NAMES gzip)
if (NOT COMPRESS_EXEC)
    message(WARNING "Can't find gzip, skip manpage generation")
    return()
endif()


set(MANPAGE dir_monitor.1)
set(ASCIIDOC_GENMAN ${ASCIIDOC_EXEC} -b docbook -d manpage)

add_custom_command(
    OUTPUT ${MANPAGE}.xml
    COMMAND ${ASCIIDOC_GENMAN} -o ${MANPAGE}.xml ${CMAKE_CURRENT_SOURCE_DIR}/man/${MANPAGE}.adoc
    COMMENT "Create DocBook XML ${MANPAGE}.xml ..."
)

set(XMLTO_GENMAN ${XMLTO_EXEC} man)
add_custom_command(
    OUTPUT ${MANPAGE}
    COMMAND ${XMLTO_GENMAN} ${MANPAGE}.xml
    DEPENDS ${MANPAGE}.xml
    COMMENT "Create man page from DocBook XML ${MANPAGE}.xml ..."
)

add_custom_command(
    OUTPUT ${MANPAGE}.gz
    COMMAND ${COMPRESS_EXEC} -f -9 ${MANPAGE}
    DEPENDS ${MANPAGE}
    COMMENT "Compressing the manpage via gzip..."
)

add_custom_target(man ALL
    DEPENDS ${MANPAGE}.gz
)