Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CMakeLists.txt - github.com/ambrop72/badvpn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6751e13854ac7c802e4c92f453fd33db7338c2e4 (plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
cmake_minimum_required(VERSION 2.8)
project(BADVPN C)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")

include(GNUInstallDirs)
include(TestBigEndian)
include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckTypeSize)

option(WITH_PLUGIN_LIBS "Build PIC versions of all libraries for use from plugins" OFF)

set(BUILD_COMPONENTS)

macro (build_switch name text default)
    if (BUILD_NOTHING_BY_DEFAULT)
        option(BUILD_${name} "${text}" OFF)
    else ()
        option(BUILD_${name} "${text}" "${default}")
    endif ()
    list(APPEND BUILD_COMPONENTS "${name}")
endmacro ()

# detect Emscripten
if (CMAKE_C_COMPILER MATCHES "/emcc$")
    set(EMSCRIPTEN ON)
else ()
    set(EMSCRIPTEN OFF)
endif ()

if (EMSCRIPTEN)
    set(ON_IF_NOT_EMSCRIPTEN OFF)
else ()
    set(ON_IF_NOT_EMSCRIPTEN ON)
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT EMSCRIPTEN)
    set(ON_IF_LINUX ON)
else ()
    set(ON_IF_LINUX OFF)
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR EMSCRIPTEN)
    set(ON_IF_LINUX_OR_EMSCRIPTEN ON)
else ()
    set(ON_IF_LINUX_OR_EMSCRIPTEN OFF)
endif ()

# define build defaults
build_switch(EXAMPLES "build example programs" ON)
build_switch(TESTS "build some other example programs" ON)
build_switch(SERVER "build badvpn-server" ${ON_IF_NOT_EMSCRIPTEN})
build_switch(CLIENT "build badvpn-client" ${ON_IF_NOT_EMSCRIPTEN})
build_switch(FLOODER "build badvpn-flooder" ${ON_IF_NOT_EMSCRIPTEN})
build_switch(TUN2SOCKS "build badvpn-tun2socks" ${ON_IF_NOT_EMSCRIPTEN})
build_switch(UDPGW "build badvpn-udpgw" ${ON_IF_NOT_EMSCRIPTEN})
build_switch(NCD "build badvpn-ncd" ${ON_IF_LINUX_OR_EMSCRIPTEN})
build_switch(DOSTEST "build dostest-server and dostest-attacker" OFF)

if (BUILD_NCD AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux"))
    message(FATAL_ERROR "NCD is only available on Linux")
endif ()

if (BUILD_CLIENT OR BUILD_SERVER)
    find_package(OpenSSL REQUIRED)
    set(LIBCRYPTO_INCLUDE_DIRS "${OpenSSL_INCLUDE_DIRS}")
    set(LIBCRYPTO_LIBRARY_DIRS "${OpenSSL_LIBRARY_DIRS}")
    set(LIBCRYPTO_LIBRARIES "${OpenSSL_LIBRARIES}")
endif ()

if (BUILD_SERVER OR BUILD_CLIENT OR BUILD_FLOODER)
    find_package(NSPR REQUIRED)
    find_package(NSS REQUIRED)
endif ()

# choose reactor
if (DEFINED BREACTOR_BACKEND)
    if (NOT (BREACTOR_BACKEND STREQUAL "badvpn" OR BREACTOR_BACKEND STREQUAL "glib"))
        message(FATAL_ERROR "unknown reactor backend specified")
    endif ()
else ()
    if (EMSCRIPTEN)
        set(BREACTOR_BACKEND "emscripten")
    else ()
        set(BREACTOR_BACKEND "badvpn")
    endif ()
endif ()

if (BREACTOR_BACKEND STREQUAL "badvpn")
    add_definitions(-DBADVPN_BREACTOR_BADVPN)
elseif (BREACTOR_BACKEND STREQUAL "glib")
    if (NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux"))
        message(FATAL_ERROR "GLib reactor backend is only available on Linux")
    endif ()
    find_package(GLIB2 REQUIRED)
    add_definitions(-DBADVPN_BREACTOR_GLIB)
elseif (BREACTOR_BACKEND STREQUAL "emscripten")
    add_definitions(-DBADVPN_BREACTOR_EMSCRIPTEN)
endif ()

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${LIBCRYPTO_INCLUDE_DIRS}
    ${NSPR_INCLUDE_DIRS}
    ${NSS_INCLUDE_DIRS}
    ${GLIB2_INCLUDE_DIR}
    lwip/custom
    lwip/src/include
    lwip/src/include/ipv4
    lwip/src/include/ipv6
)

link_directories(
    ${LIBCRYPTO_LIBRARY_DIRS}
    ${NSPR_LIBRARY_DIRS}
    ${NSS_LIBRARY_DIRS}
)

test_big_endian(BIG_ENDIAN)

check_type_size(int INT_SIZE)
if (NOT (INT_SIZE GREATER "3"))
    message(FATAL_ERROR "int must be at least 32 bits")
endif ()

check_type_size(size_t SIZE_SIZE)
if (NOT (SIZE_SIZE GREATER INT_SIZE OR SIZE_SIZE EQUAL INT_SIZE))
    message(FATAL_ERROR "size_t must be greater or equal than int")
endif ()

if (MSVC)
    add_definitions(-D_CRT_SECURE_NO_WARNINGS /wd4065 /wd4018 /wd4533 /wd4244 /wd4102 /wd4098 /wd4267 /wd4116)
    add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
else ()
    add_definitions(-std=gnu99 -Wall -Wno-unused-value -Wno-parentheses -Wno-switch -Wredundant-decls -Wshadow)

    if (NOT CMAKE_C_COMPILER_ID STREQUAL "PathScale")
        add_definitions(-Werror=implicit-function-declaration -Wno-switch-enum -Wno-unused-function
                        -Wstrict-aliasing)
    endif ()
    
    if (CMAKE_C_COMPILER_ID MATCHES "^Clang")
        add_definitions(-Wno-initializer-overrides -Wno-tautological-constant-out-of-range-compare)
    endif ()
endif ()

# platform-specific stuff
if (WIN32)
    add_definitions(-DBADVPN_USE_WINAPI -D_WIN32_WINNT=0x600 -DWIN32_LEAN_AND_MEAN)
    add_definitions(-DBADVPN_THREAD_SAFE=0)

    set(CMAKE_REQUIRED_DEFINITIONS "-D_WIN32_WINNT=0x600")
    check_symbol_exists(WSAID_WSASENDMSG "winsock2.h;mswsock.h" HAVE_MSW_1)
    check_symbol_exists(WSAID_WSARECVMSG "winsock2.h;mswsock.h" HAVE_MSW_2)
    check_symbol_exists(WSAID_ACCEPTEX "winsock2.h;mswsock.h" HAVE_MSW_3)
    check_symbol_exists(WSAID_GETACCEPTEXSOCKADDRS "winsock2.h;mswsock.h" HAVE_MSW_4)
    check_symbol_exists(WSAID_CONNECTEX "winsock2.h;mswsock.h" HAVE_MSW_5)
    set(CMAKE_REQUIRED_DEFINITIONS "")
    if (NOT (HAVE_MSW_1 AND HAVE_MSW_2 AND HAVE_MSW_3 AND HAVE_MSW_4 AND HAVE_MSW_5))
        add_definitions(-DBADVPN_USE_SHIPPED_MSWSOCK)
        check_type_size(WSAMSG HAVE_WSAMSG)
        if (NOT HAVE_WSAMSG)
            add_definitions(-DBADVPN_SHIPPED_MSWSOCK_DECLARE_WSAMSG)
        endif ()
    endif ()
else ()
    set(BADVPN_THREADWORK_USE_PTHREAD 1)
    add_definitions(-DBADVPN_THREADWORK_USE_PTHREAD)
    add_definitions(-DBADVPN_THREAD_SAFE=1)

    link_libraries(rt pthread)

    if (EMSCRIPTEN)
        add_definitions(-DBADVPN_EMSCRIPTEN)
        add_definitions(-DBADVPN_NO_PROCESS -DBADVPN_NO_UDEV -DBADVPN_NO_RANDOM)
    elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
        add_definitions(-DBADVPN_LINUX)

        check_include_files(sys/signalfd.h HAVE_SYS_SIGNALFD_H)
        if (HAVE_SYS_SIGNALFD_H)
            add_definitions(-DBADVPN_USE_SIGNALFD)
        else ()
            add_definitions(-DBADVPN_USE_SELFPIPE)
        endif ()

        check_include_files(sys/epoll.h HAVE_SYS_EPOLL_H)
        if (HAVE_SYS_EPOLL_H)
            add_definitions(-DBADVPN_USE_EPOLL)
        else ()
            add_definitions(-DBADVPN_USE_POLL)
        endif ()

        check_include_files(linux/rfkill.h HAVE_LINUX_RFKILL_H)
        if (HAVE_LINUX_RFKILL_H)
            add_definitions(-DBADVPN_USE_LINUX_RFKILL)
            set(BADVPN_USE_LINUX_RFKILL 1)
        endif ()

        check_include_files(linux/input.h HAVE_LINUX_INPUT_H)
        if (HAVE_LINUX_INPUT_H)
            add_definitions(-DBADVPN_USE_LINUX_INPUT)
            set(BADVPN_USE_LINUX_INPUT 1)
        endif ()

        check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H)
        if (HAVE_SYS_INOTIFY_H)
            add_definitions(-DBADVPN_USE_INOTIFY)
            set(BADVPN_USE_INOTIFY 1)
        endif ()
    elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
        add_definitions(-DBADVPN_FREEBSD)

        check_symbol_exists(kqueue "sys/types.h;sys/event.h;sys/time.h" HAVE_KQUEUE)
        if (NOT HAVE_KQUEUE)
            message(FATAL_ERROR "kqueue is required")
        endif ()
        add_definitions(-DBADVPN_USE_KEVENT)
    endif ()

    if (NOT DEFINED BADVPN_WITHOUT_CRYPTODEV)
        check_include_files(crypto/cryptodev.h HAVE_CRYPTO_CRYPTODEV_H)
        if (HAVE_CRYPTO_CRYPTODEV_H)
            add_definitions(-DBADVPN_USE_CRYPTODEV)
        elseif (DEFINED BADVPN_WITH_CRYPTODEV)
            message(FATAL_ERROR "crypto/cryptodev.h not found")
        endif ()
    endif ()
endif ()

# check for syslog
check_include_files(syslog.h HAVE_SYSLOG_H)
if (HAVE_SYSLOG_H)
    add_definitions(-DBADVPN_USE_SYSLOG)
endif ()

# add preprocessor definitions
if (BIG_ENDIAN)
    add_definitions(-DBADVPN_BIG_ENDIAN)
else ()
    add_definitions(-DBADVPN_LITTLE_ENDIAN)
endif ()

# install man pages
install(
    FILES badvpn.7
	DESTINATION ${CMAKE_INSTALL_MANDIR}/man7
)

# reset variables indicating whether we're building various libraries,
# and set them in the respective CMakeLists files. This is used to disable
# building examples and tests which require libraries that are not available.
set(BUILDING_SECURITY 0)
set(BUILDING_DHCPCLIENT 0)
set(BUILDING_ARPPROBE 0)
set(BUILDING_BKIO 0)
set(BUILDING_PREDICATE 0)
set(BUILDING_UDEVMONITOR 0)
set(BUILDING_THREADWORK 0)
set(BUILDING_RANDOM 0)

# Used to register an internal library.
# This will also add a library with the -plugin suffix, which is useful
# for use by dynamic libraries (e.g. NCD modules):
# - If BUILD_SHARED_LIBS is off (default), the libraries ${LIB_NAME} and ${LIB_NAME}-plugin
#   are built separately. Both are static libraries but the -plugin variant is build as position
#   independent code, so it can be (statically) linked into dynamic libraries.
# - If BUILD_SHARED_LIBS is on, only ${LIB_NAME} is built, as a shared library.
#   The ${LIB_NAME}-plugin target is set up as an alias to ${LIB_NAME}.
function(badvpn_add_library LIB_NAME LINK_BADVPN_LIBS LINK_SYS_LIBS LIB_SOURCES)
    set(BADVPN_LIBS_EXEC)
    set(BADVPN_LIBS_PLUGIN)
    foreach(LIB ${LINK_BADVPN_LIBS})
        list(APPEND BADVPN_LIBS_EXEC "${LIB}")
        list(APPEND BADVPN_LIBS_PLUGIN "${LIB}-plugin")
    endforeach()

    add_library("${LIB_NAME}" ${LIB_SOURCES})
    target_link_libraries("${LIB_NAME}" ${BADVPN_LIBS_EXEC} ${LINK_SYS_LIBS})
    set_target_properties("${LIB_NAME}" PROPERTIES OUTPUT_NAME "badvpn-${LIB_NAME}")

    if(WITH_PLUGIN_LIBS)
        if(BUILD_SHARED_LIBS)
            add_library("${LIB_NAME}-plugin" ALIAS "${LIB_NAME}")
        else()
            add_library("${LIB_NAME}-plugin" STATIC ${LIB_SOURCES})
            target_link_libraries("${LIB_NAME}-plugin" ${BADVPN_LIBS_PLUGIN} ${LINK_SYS_LIBS})
            set_target_properties("${LIB_NAME}-plugin" PROPERTIES OUTPUT_NAME "badvpn-${LIB_NAME}-plugin")
            set_target_properties("${LIB_NAME}-plugin" PROPERTIES POSITION_INDEPENDENT_CODE YES)
            set_target_properties("${LIB_NAME}-plugin" PROPERTIES COMPILE_FLAGS "-fvisibility=hidden -DBADVPN_PLUGIN")
        endif()
    endif()
endfunction()

# internal libraries
add_subdirectory(base)
add_subdirectory(system)
add_subdirectory(flow)
add_subdirectory(flowextra)
if (OpenSSL_FOUND)
    set(BUILDING_SECURITY 1)
    add_subdirectory(security)
endif ()
if (NSS_FOUND)
    add_subdirectory(nspr_support)
endif ()
if (BUILD_CLIENT OR BUILDING_SECURITY)
    set(BUILDING_THREADWORK 1)
    add_subdirectory(threadwork)
endif ()
if (BUILD_CLIENT OR BUILD_TUN2SOCKS)
    add_subdirectory(tuntap)
endif ()
if (BUILD_SERVER)
    set(BUILDING_PREDICATE 1)
    add_subdirectory(predicate)
endif ()
if (BUILD_CLIENT OR BUILD_FLOODER)
    add_subdirectory(server_connection)
endif ()
if (BUILD_NCD AND NOT EMSCRIPTEN)
    set(BUILDING_DHCPCLIENT 1)
    set(BUILDING_ARPPROBE 1)
    set(BUILDING_UDEVMONITOR 1)
    set(BUILDING_RANDOM 1)
    add_subdirectory(stringmap)
    add_subdirectory(udevmonitor)
    add_subdirectory(dhcpclient)
    add_subdirectory(arpprobe)
    add_subdirectory(random)
endif ()
if (BUILD_TUN2SOCKS)
    add_subdirectory(socksclient)
    add_subdirectory(udpgw_client)
    add_subdirectory(socks_udp_client)
    add_subdirectory(lwip)
endif ()

# example programs
if (BUILD_EXAMPLES)
    add_subdirectory(examples)
endif ()

# tests
if (BUILD_TESTS)
    add_subdirectory(tests)
endif ()

# server
if (BUILD_SERVER)
    add_subdirectory(server)
endif ()

# client
if (BUILD_CLIENT)
    add_subdirectory(client)
endif ()

# flooder
if (BUILD_FLOODER)
    add_subdirectory(flooder)
endif ()

# tun2socks
if (BUILD_TUN2SOCKS)
    add_subdirectory(tun2socks)
endif ()

# udpgw
if (BUILD_UDPGW)
    add_subdirectory(udpgw)
endif ()

# ncd
if (BUILD_NCD)
    add_subdirectory(ncd)
    if (NOT EMSCRIPTEN)
        add_subdirectory(ncd-request)
    endif ()
endif ()

# dostest
if (BUILD_DOSTEST)
    add_subdirectory(dostest)
endif ()

message(STATUS "Building components:")

# print what we're building and what not
foreach (name ${BUILD_COMPONENTS})
    # to lower name
    string(TOLOWER "${name}" name_withspaces)

    # append spaces to name
    #while (TRUE)
    #    string(LENGTH "${name_withspaces}" length)
    #    if (NOT (length LESS 12))
    #        break()
    #    endif ()
    #    set(name_withspaces "${name_withspaces} ")
    #endwhile ()
    
    # determine if we're building
    if (BUILD_${name})
        set(building "yes")
    else ()
        set(building "no")
    endif ()
    
    message(STATUS "    ${name_withspaces} ${building}")
endforeach ()