-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
118 lines (103 loc) · 3.42 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
cmake_minimum_required(VERSION 3.0)
project(app)
# Fix warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
option(RA2YRCPP_BUILD_CLI_TOOL "Build the main CLI tool" ON)
option(RA2YRCPP_BUILD_MAIN_DLL "Build the main library for Windows targets" ON)
option(RA2YRCPP_BUILD_TESTS "Build tests" ON)
option(RA2YRCPP_DEBUG_LOG "Enable debug logs even for non-debug builds" OFF)
add_compile_definitions(RA2YRCPP_VERSION=${RA2YRCPP_VERSION})
if(MINGW)
add_compile_definitions(__MINGW_FORCE_SYS_INTRINS)
add_compile_options(-masm=intel)
endif()
if(RA2YRCPP_DEBUG_LOG)
add_compile_definitions(DEBUG_LOG)
endif()
# FIXME: needed?
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(NOT PROTOC_PATH)
find_program(PROTOC_PATH protoc REQUIRED)
endif()
include(FetchContent)
FetchContent_Declare(
googletest
# Specify the commit you depend on and update it regularly.
URL https://github.com/google/googletest/archive/e2239ee6043f73722e7aa812a459f54a28552929.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt
ON
CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
if(WIN32)
if(MINGW)
find_library(LIB_WSOCK32 wsock32 REQUIRED)
find_library(LIB_WS2_32 ws2_32 REQUIRED)
find_package(Threads REQUIRED)
else()
set(LIB_WSOCK32 wsock32)
set(LIB_WS2_32 ws2_32)
endif()
endif()
if(MINGW)
# find MinGW libraries these are copied just for test executables, to avoid
# statically linking each of them
set(MINGW_LIBS zlib1.dll libgcc_s_dw2-1.dll libstdc++-6.dll
libwinpthread-1.dll)
set(MINGW_LIBS_FULL "")
foreach(X IN LISTS MINGW_LIBS)
find_file(LIB_OUT ${X} PATHS ${CMAKE_SYSROOT}/lib ${CMAKE_SYSROOT}/bin
NO_CACHE REQUIRED)
list(APPEND MINGW_LIBS_FULL ${LIB_OUT})
unset(LIB_OUT)
endforeach()
endif()
if(NOT MINGW AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(cdecl_s "__attribute__((cdecl))")
add_compile_definitions(__cdecl=${cdecl_s})
endif()
find_package(ZLIB REQUIRED)
# TODO: check that works for MSVC too
if(WIN32)
add_compile_definitions(protobuf_MSVC_STATIC_RUNTIME=OFF)
endif(WIN32)
set(protobuf_WITH_ZLIB
ON
CACHE BOOL "" FORCE)
if(MINGW)
add_compile_definitions(_WEBSOCKETPP_CPP11_THREAD_)
endif()
add_compile_definitions(ASIO_STANDALONE)
set(Protobuf_USE_STATIC_LIBS
ON
CACHE BOOL "" FORCE)
if(ZLIB_INCLUDE_DIR)
include_directories(${ZLIB_INCLUDE_DIR})
endif()
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR}/src/protocol)
include_directories(src)
# FIXME: override protobuf include path
if(NOT RA2YRCPP_SYSTEM_PROTOBUF)
include_directories(SYSTEM 3rdparty/protobuf/src)
endif()
include_directories(SYSTEM 3rdparty/xbyak)
include_directories(3rdparty/argparse/include)
include_directories(SYSTEM 3rdparty/fmt/include)
include_directories(SYSTEM 3rdparty/asio/asio/include)
include_directories(SYSTEM 3rdparty/websocketpp)
add_subdirectory(3rdparty/fmt)
if(RA2YRCPP_BUILD_MAIN_DLL)
include_directories(SYSTEM 3rdparty/YRpp)
add_subdirectory(3rdparty/YRpp)
add_subdirectory(src/addscn)
target_compile_options(YRpp INTERFACE -Wno-pragmas -Wno-return-type
-Wno-inconsistent-missing-override)
endif()
add_subdirectory(src)
if(RA2YRCPP_BUILD_TESTS)
add_subdirectory(tests)
endif()