-
Notifications
You must be signed in to change notification settings - Fork 11
/
CMakeLists.txt
62 lines (53 loc) · 1.99 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
cmake_minimum_required(VERSION 3.9)
project(zhe C)
#cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DTCP=OFF -DCMAKE_INSTALL_PREFIX=.. ..
#cmake -GNinja -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DCMAKE_BUILD_TYPE=Debug -DTCP=ON -DSSL=ON -DZHE_CONFIG=client-nbiot ..
#set(TCP ON)
#set(SSL ON)
#set(ZHE_CONFIG client-nbiot)
if(NOT ZHE_CONFIG)
set(ZHE_CONFIG p2p)
endif()
set(CMAKE_C_STANDARD 99)
include(CheckIPOSupported)
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
check_ipo_supported(RESULT supported OUTPUT error)
if(supported)
#message(STATUS "IPO / LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()
add_compile_options(
$<$<C_COMPILER_ID:MSVC>:/W3>
$<$<C_COMPILER_ID:Clang>:-Wall>
$<$<C_COMPILER_ID:AppleClang>:-Wall>
$<$<C_COMPILER_ID:GNU>:-Wall>)
add_compile_options(
$<$<C_COMPILER_ID:Clang>:-pedantic>
$<$<C_COMPILER_ID:AppleClang>:-pedantic>
$<$<C_COMPILER_ID:GNU>:-pedantic>)
# Clang doesn't colour its output by default when invoked by Ninja
# Can't commit this as it would break when ninja itself is not sending its output to a TTY
if(${CMAKE_GENERATOR} STREQUAL "Ninja" AND (${CMAKE_C_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_C_COMPILER_ID} STREQUAL "AppleClang"))
add_compile_options(-Xclang -fcolor-diagnostics)
endif()
set(ZIncludes
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/example/platform"
"${PROJECT_SOURCE_DIR}/example/configs/${ZHE_CONFIG}")
file(GLOB ZSources "src/*.c")
if(TCP)
add_definitions(-DTCP)
file(GLOB ZPlatform "example/platform/zhe-*.c" "example/platform/platform-tcp.c")
if(SSL)
find_package(OpenSSL REQUIRED)
add_definitions(-DUSE_SSL=1)
include_directories(${OPENSSL_INCLUDE_DIR})
link_libraries(${OPENSSL_LIBRARIES})
message(STATUS "Using OpenSSL ${OPENSSL_VERSION} at ${OPENSSL_INCLUDE_DIR}")
endif()
else()
file(GLOB ZPlatform "example/platform/zhe-*.c" "example/platform/platform-udp.c")
endif()
add_subdirectory(src)
add_subdirectory(example)