-
Notifications
You must be signed in to change notification settings - Fork 33
/
CMakeLists.txt
120 lines (97 loc) · 3.8 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
116
117
118
119
120
cmake_minimum_required(VERSION 3.13)
#######################################################
# VERSION
#######################################################
# this is the source of truth for semver version
project(visor VERSION 4.5.0)
# for main line release, this is empty
# for development release, this is "-develop"
# for release candidate, this is "-rc"
set(VISOR_PRERELEASE "-develop")
#######################################################
# if develop or rc build, add git hash
# note this only updates on cmake reconfigure, not every git commit
# so it's mainly useful for GitHub CI, not developers
if(VISOR_PRERELEASE STREQUAL "-develop" OR VISOR_PRERELEASE STREQUAL "-rc")
execute_process(
COMMAND
git rev-parse --short HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE
SHORT_HASH_RESULT
OUTPUT_VARIABLE
SHORT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if ("${SHORT_HASH}" STREQUAL "")
message(FATAL "Unable to get current git hash for develop/rc version")
endif ()
string(APPEND VISOR_PRERELEASE "-${SHORT_HASH}")
endif()
# these are computed
set(VISOR_VERSION_NUM "${PROJECT_VERSION}${VISOR_PRERELEASE}")
set(VISOR_VERSION "pktvisor ${PROJECT_VERSION}${VISOR_PRERELEASE}")
# used in CI
file(WRITE ${CMAKE_BINARY_DIR}/VERSION ${VISOR_VERSION_NUM})
# golang version
configure_file(golang/pkg/client/version.go.in ${PROJECT_SOURCE_DIR}/golang/pkg/client/version.go)
####### end version code #######
if(NOT DEFINED ENV{VERSION_ONLY})
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 ")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
#set(CMAKE_VERBOSE_MAKEFILE ON)
if(NOT MSVC)
add_compile_options(-Wall -pedantic -W -Wextra -Wno-unknown-pragmas)
endif()
# Conan setup
include(conan)
conan_cmake_autodetect(CONAN_SETTINGS)
message(STATUS "Detected conan settings: ${CONAN_SETTINGS}")
set(PKTVISOR_CONAN_INIT ON CACHE BOOL "Create new Conan environment for the build.")
set(PKTVISOR_CONAN_BUILD "missing" CACHE STRING "Specify conan packages to build from source. Values are separated by semicolon.")
set(PKTVISOR_CONAN_BUILD_PROFILE "" CACHE STRING "Profile for the build environment.")
set(PKTVISOR_CONAN_HOST_PROFILE "" CACHE STRING "Profile for the host environment.")
if(PKTVISOR_CONAN_INIT)
message(STATUS "Using new Conan environment")
set(ENV{CONAN_USER_HOME} ${CMAKE_BINARY_DIR}/conan_home)
set(ENV{CONAN_REVISIONS_ENABLED} 1)
endif()
if(WIN32)
set(CUSTOM_CMAKE_OPTIONS docopt.cpp:boost_regex=True)
endif()
conan_cmake_install(
PATH_OR_REFERENCE ${PROJECT_SOURCE_DIR}
BUILD ${PKTVISOR_CONAN_BUILD}
PROFILE_BUILD ${PKTVISOR_CONAN_BUILD_PROFILE}
PROFILE_HOST ${PKTVISOR_CONAN_HOST_PROFILE}
GENERATOR cmake
SETTINGS ${CONAN_SETTINGS}
OPTIONS ${CUSTOM_CMAKE_OPTIONS}
INSTALL_FOLDER ${CMAKE_BINARY_DIR})
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(Corrade REQUIRED PluginManager)
include(sanitizer)
if(CODE_COVERAGE)
include(CodeCoverage)
append_coverage_compiler_flags()
setup_target_for_coverage_lcov(
NAME coverage
EXECUTABLE ctest
EXCLUDE "3rd/*" "cmd/*" "libs/*" "${PROJECT_BINARY_DIR}/*")
endif()
set(VISOR_STATIC_PLUGINS)
enable_testing()
message(STATUS "Building pktvisor version ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH}${VISOR_PRERELEASE}")
add_subdirectory(3rd)
add_subdirectory(libs)
add_subdirectory(src)
add_subdirectory(cmd)
if(NOT WIN32)
add_subdirectory(integration_tests)
endif()
endif()