forked from moonlight-stream/moonlight-common-c
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
71 lines (56 loc) · 2.27 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
cmake_minimum_required(VERSION 3.1)
project(moonlight-common-c LANGUAGES C)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
option(USE_MBEDTLS "Use MbedTLS instead of OpenSSL" OFF)
SET(CMAKE_C_STANDARD 11)
aux_source_directory(src SRC_LIST)
aux_source_directory(enet SRC_LIST)
aux_source_directory(reedsolomon SRC_LIST)
# Build shared library by default, but allows user override
if (NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
set(BUILD_SHARED_LIBS_OVERRIDE ON)
endif()
add_library(moonlight-common-c ${SRC_LIST})
if (BUILD_SHARED_LIBS_OVERRIDE)
unset(BUILD_SHARED_LIBS)
unset(BUILD_SHARED_LIBS_OVERRIDE)
endif()
if(MSVC)
target_compile_options(moonlight-common-c PRIVATE /W3 /wd4100 /wd4232 /wd5105 /WX)
target_link_libraries(moonlight-common-c PRIVATE ws2_32.lib winmm.lib)
else()
target_compile_options(moonlight-common-c PRIVATE -Wall -Wextra -Wno-unused-parameter -Werror)
endif()
if (USE_MBEDTLS)
target_compile_definitions(moonlight-common-c PRIVATE USE_MBEDTLS)
find_package(MbedTLS QUIET)
if (MBEDTLS_FOUND)
target_link_libraries(moonlight-common-c PRIVATE ${MBEDCRYPTO_LIBRARY})
target_include_directories(moonlight-common-c SYSTEM PRIVATE ${MBEDTLS_INCLUDE_DIRS})
else()
# For sub project added via CMake
target_link_libraries(moonlight-common-c PRIVATE mbedtls)
endif()
else()
find_package(OpenSSL 1.0.2 REQUIRED)
target_link_libraries(moonlight-common-c PRIVATE ${OPENSSL_CRYPTO_LIBRARY})
target_include_directories(moonlight-common-c SYSTEM PRIVATE ${OPENSSL_INCLUDE_DIR})
endif()
string(TOUPPER "x${CMAKE_BUILD_TYPE}" BUILD_TYPE)
if("${BUILD_TYPE}" STREQUAL "XDEBUG")
target_compile_definitions(moonlight-common-c PRIVATE LC_DEBUG)
else()
target_compile_definitions(moonlight-common-c PRIVATE NDEBUG)
# Avoid false "maybe uninitialized" warning generated by old GCC versions
# when building with -O2
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(moonlight-common-c PRIVATE -Wno-maybe-uninitialized)
endif()
endif()
target_include_directories(moonlight-common-c SYSTEM PUBLIC src)
target_include_directories(moonlight-common-c PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/enet/include
${CMAKE_CURRENT_SOURCE_DIR}/reedsolomon
)
target_compile_definitions(moonlight-common-c PRIVATE HAS_SOCKLEN_T)