File: CMakeLists.txt

package info (click to toggle)
nfstrace 0.4.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 21,744 kB
  • sloc: cpp: 37,459; ansic: 2,281; sh: 357; makefile: 16
file content (118 lines) | stat: -rw-r--r-- 4,775 bytes parent folder | download | duplicates (2)
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
116
117
118
cmake_minimum_required (VERSION 2.8.12)
project (nfstrace)

# check compiler and packages ==================================================
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
        message (FATAL_ERROR "GCC version must be at least 5.1")
    endif ()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)
        message (FATAL_ERROR "Clang version must be at least 3.5")
    endif ()
else ()
    message (WARNING "Compilation by ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} isn't tested")
endif ()

include(cmake/options.cmake)

find_package(Threads REQUIRED) # POSIX Threads

find_path(PCAP_ROOT_DIR
          NAMES include/pcap.h)

find_library(PCAP_LIBRARY
             NAMES pcap
             HINTS ${PCAP_ROOT_DIR}/lib)

if ("${PCAP_LIBRARY}" STREQUAL "PCAP_LIBRARY-NOTFOUND")
    message (FATAL_ERROR "Could NOT find PCAP")
endif ()

# build application ============================================================
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pedantic -Wall -Werror -Wextra -Wno-invalid-offsetof -Wno-braced-scalar-init -fPIC -fvisibility=hidden")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--export-dynamic")

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND "${INCLUDE_COVERAGE_INFO}")
    set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} --coverage -O0")
endif ()

# Read version string from file
file (STRINGS VERSION NST_VERSION)

string (REPLACE "." ";" VERSION_LIST ${NST_VERSION})
list (GET VERSION_LIST 0 NST_V_MAJOR)
list (GET VERSION_LIST 1 NST_V_MINOR)
list (GET VERSION_LIST 2 NST_V_PATCH)

set (NST_VERSION_FULL "${PROJECT_NAME} ${NST_VERSION} (${CMAKE_BUILD_TYPE})")

if (DEFINED ENV{SOURCE_DATE_EPOCH})
    execute_process(
      COMMAND "date" "-u" "-d" "@$ENV{SOURCE_DATE_EPOCH}" "+%Y-%m-%d"
      OUTPUT_VARIABLE COMPILATION_DATE
      OUTPUT_STRIP_TRAILING_WHITESPACE)
else ()
    string (TIMESTAMP COMPILATION_DATE "%Y-%m-%d")
endif ()

include_directories (src)

# nfstrace executable ==========================================================
file (GLOB_RECURSE SRCS "src/*.cpp")
set (LIBS ${CMAKE_DL_LIBS}          # libdl with dlopen()
          ${CMAKE_THREAD_LIBS_INIT} # libpthread
          ${PCAP_LIBRARY}           # libpcap
          )

configure_file (docs/nfstrace.8.in              ${PROJECT_SOURCE_DIR}/docs/nfstrace.8)
configure_file (src/api/plugin_api.h.in         ${PROJECT_SOURCE_DIR}/src/api/plugin_api.h)
configure_file (src/controller/build_info.h.in  ${PROJECT_SOURCE_DIR}/src/controller/build_info.h)

add_executable (${PROJECT_NAME} ${SRCS})
target_link_libraries (${PROJECT_NAME} ${LIBS})

# analyzer plugins =============================================================
add_subdirectory (analyzers)

# testing ======================================================================
enable_testing ()
add_subdirectory (tests)

# installation of main application =============================================
install (TARGETS "${PROJECT_NAME}" RUNTIME DESTINATION bin)

# installation of api headers ==================================================
file (GLOB headers "src/api/*.h")
install (FILES ${headers} DESTINATION include/nfstrace/api)

# installation of man page =====================================================
install (FILES ${PROJECT_SOURCE_DIR}/docs/nfstrace.8 DESTINATION share/man/man8)

# build packages ===============================================================
include ("cmake/packaging.cmake")

# coverage =====================================================================
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND "${INCLUDE_COVERAGE_INFO}")
    find_program (GCOVR_PATH gcovr)

    if (GCOVR_PATH)
        add_custom_target (coverage
                           COMMAND ${GCOVR_PATH} --xml -r \"${CMAKE_SOURCE_DIR}\" --object-directory \"${CMAKE_BINARY_DIR}\" -o coverage.xml 2>&1 >/dev/null
                           WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
        add_custom_target (coverage-html
                           COMMAND ${GCOVR_PATH} --html --html-details -r \"${CMAKE_SOURCE_DIR}\" --object-directory \"${CMAKE_BINARY_DIR}\" -o coverage.html 2>&1 >/dev/null
                           WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
    else ()
        message (WARNING "'gcovr' executable not found - coverage report is not available.")
    endif ()
endif ()

# documentation ================================================================
add_subdirectory (docs)

# code style ===================================================================
include ("cmake/codeformat.cmake")

# valgrind reports =============================================================
include ("cmake/valgrind.cmake")