-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
116 lines (95 loc) · 3.41 KB
/
Copy pathCMakeLists.txt
File metadata and controls
116 lines (95 loc) · 3.41 KB
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
# Copyright 2020-2026 Nikita Fediuchin. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.22)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "Prevented in-tree build")
endif()
if(TARGET nets-static)
return()
endif()
include(cmake/package-managers.cmake)
project(nets VERSION 3.0.0 LANGUAGES C
DESCRIPTION "Secure multi-platform networking library \
with implemented TCP / UDP server and client"
HOMEPAGE_URL "https://github.com/cfnptr/nets")
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED TRUE)
option(NETS_BUILD_EXAMPLES "Build Nets usage examples" ON)
option(NETS_USE_OPENSSL "Use OpenSSL for secure communication" ON)
option(NETS_USE_CURL "Use cURL for HTTP requests" ON)
if(NETS_USE_OPENSSL)
find_package(OpenSSL)
if(NOT OpenSSL_FOUND AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(OPENSSL_SSL_LIBRARY /usr/lib64/libssl.so)
set(OPENSSL_CRYPTO_LIBRARY /usr/lib64/libcrypto.so)
find_package(OpenSSL)
if(NOT OpenSSL_FOUND)
set(OPENSSL_SSL_LIBRARY /usr/lib/libssl.so)
set(OPENSSL_CRYPTO_LIBRARY /usr/lib/libcrypto.so)
find_package(OpenSSL)
endif()
endif()
if(OpenSSL_FOUND)
set(NETS_SUPPORT_OPENSSL 1)
else()
set(NETS_SUPPORT_OPENSSL 0)
endif()
else()
set(NETS_SUPPORT_OPENSSL 0)
endif()
if(NETS_USE_CURL)
find_package(CURL)
if(CURL_FOUND)
set(NETS_SUPPORT_CURL 1)
else()
set(NETS_SUPPORT_CURL 0)
endif()
else()
set(NETS_SUPPORT_CURL 0)
endif()
include(TestBigEndian)
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
set(NETS_LITTLE_ENDIAN 0)
else()
set(NETS_LITTLE_ENDIAN 1)
endif()
set(NETS_INCLUDE_DIRECTORIES ${PROJECT_BINARY_DIR}/include
${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/wrappers/cpp)
set(NETS_LINK_LIBRARIES mpmt-static mpio-static)
set(MPMT_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(MPMT_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(MPMT_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(libraries/mpmt)
set(MPIO_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(MPIO_BUILD_TESTS OFF CACHE BOOL "" FORCE)
add_subdirectory(libraries/mpio)
configure_file(cmake/defines.h.in include/nets/defines.h)
if(NETS_USE_OPENSSL AND OpenSSL_FOUND)
list(APPEND NETS_LINK_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
endif()
if(NETS_USE_CURL AND CURL_FOUND)
list(APPEND NETS_LINK_LIBRARIES CURL::libcurl)
endif()
set(NETS_SOURCES source/datagram-client.c source/datagram-server.c source/socket.c
source/stream-client.c source/stream-message.c source/stream-server.c)
add_library(nets-static STATIC ${NETS_SOURCES})
target_link_libraries(nets-static PUBLIC ${NETS_LINK_LIBRARIES})
target_include_directories(nets-static PUBLIC ${NETS_INCLUDE_DIRECTORIES})
if(NETS_BUILD_EXAMPLES)
add_executable(nets-datagram-example examples/datagram-example.c)
target_link_libraries(nets-datagram-example PRIVATE nets-static)
target_include_directories(nets-datagram-example PRIVATE
${PROJECT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/include)
endif()