-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
134 lines (117 loc) · 3.82 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
cmake_minimum_required(VERSION 3.14)
project(TracertAs)
set(RELEASE_PATH "${CMAKE_CURRENT_BINARY_DIR}/tracertas")
set(GEN_COVERAGE OFF)
find_program(GCOV_FIND_RESULT gcov)
if(NOT ${GCOV_FIND_RESULT} STREQUAL GCOV_FIND_RESULT-NOTFOUND AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(GEN_COVERAGE ON)
endif()
# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()
# Force the script to use FetchContent and not CPM internally to fetch asio
option(ASIO_USE_CPM "Download Asio with CPM instead of FetchContent" OFF)
option(
ASIO_CPM_FETCHCONTENT_COMPAT
"Should asio be declared with FetchContent functions to be compatible. This doesn't not allow CPM cache to work."
ON
)
# Download this repository
include(FetchContent)
FetchContent_Declare(
asiocmake
GIT_REPOSITORY "https://github.com/OlivierLDff/asio.cmake"
GIT_TAG "main"
)
FetchContent_MakeAvailable(asiocmake)
list(APPEND commonSrc
src/ip_info.cpp
src/address.cpp
src/tracert.cpp
src/protocol_headers.cpp
src/icmp_echo.cpp
src/tracetree.cpp
src/cli.cpp
src/dns.cpp
src/csv.cpp
)
list(APPEND tests
test/address_test.cpp
test/protocol_headers_test.cpp
test/icmp_echo_test.cpp
test/ip_info_test.cpp
test/cli_test.cpp
test/tracetree_test.cpp
test/dns_test.cpp
test/csv_test.cpp
test/prefix_container_test.cpp
test/tracert_test.cpp
)
add_executable(
tracertas_test
${commonSrc}
${tests}
)
target_link_libraries(
tracertas_test
GTest::gtest_main
asio::asio
)
include(GoogleTest)
gtest_discover_tests(tracertas_test WORKING_DIRECTORY ${RELEASE_PATH})
if (GEN_COVERAGE)
target_compile_options(tracertas_test PRIVATE "--coverage")
target_link_libraries(tracertas_test gcov)
endif()
add_executable(
tracertas
${commonSrc}
src/main.cpp
)
target_link_libraries(
tracertas
asio::asio
)
if (MINGW)
target_link_libraries(tracertas ws2_32)
target_link_libraries(tracertas mswsock)
target_link_libraries(tracertas bcrypt)
target_link_libraries(tracertas_test ws2_32)
target_link_libraries(tracertas_test mswsock)
target_link_libraries(tracertas_test bcrypt)
endif()
include(FetchContent)
FetchContent_Declare(
asn-info
GIT_REPOSITORY "https://github.com/ipverse/asn-info"
GIT_TAG "master"
)
FetchContent_MakeAvailable(asn-info)
include(FetchContent)
FetchContent_Declare(
ix-networks
GIT_REPOSITORY "https://github.com/haensen/ix-networks"
GIT_TAG "main"
)
FetchContent_MakeAvailable(ix-networks)
set_target_properties(tracertas PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${RELEASE_PATH})
set_target_properties(tracertas_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${RELEASE_PATH})
set_target_properties(tracertas PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${RELEASE_PATH})
set_target_properties(tracertas_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${RELEASE_PATH})
set_target_properties(tracertas PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${RELEASE_PATH})
set_target_properties(tracertas_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${RELEASE_PATH})
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/_deps/asn-info-src DESTINATION ${RELEASE_PATH})
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/_deps/ix-networks-src DESTINATION ${RELEASE_PATH})
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/asPrefixes.txt)
file(DOWNLOAD https://thyme.apnic.net/current/data-raw-table ${CMAKE_CURRENT_BINARY_DIR}/asPrefixes.txt)
execute_process(COMMAND python3 ${CMAKE_CURRENT_BINARY_DIR}/../txt2bin.py ${CMAKE_CURRENT_BINARY_DIR}/asPrefixes.txt ${RELEASE_PATH}/asPrefixes.bin)
endif()