-
Notifications
You must be signed in to change notification settings - Fork 12
/
CMakeLists.txt
138 lines (108 loc) · 4.09 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
cmake_minimum_required(VERSION 3.20)
project(AmxxEasyHttp
VERSION 2.4.0
DESCRIPTION "HTTP, HTTPS and FTP for AMXX plugins"
HOMEPAGE_URL "https://github.com/Next21Team/AmxxEasyHttp"
LANGUAGES CXX
)
option(AMXX_EASY_HTTP_BUILD_TESTS "Set ON to build a tests (dll/so will not be built in this case)" OFF)
option(AMXX_EASY_HTTP_USE_SYSTEM_GTEST "Set ON to use GTest installed on the system (otherwise GTest will be downloaded via FetchContent)" OFF)
###
### Cmake setup
###
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) # Prevent option() from removing normal variables with the same name
set(CMAKE_POLICY_DEFAULT_CMP0117 NEW) # Do not add /GR to standard compilation flags (prevents D9025 warning)
set(AMXX_EASY_HTTP_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_MODULE_PATH
${AMXX_EASY_HTTP_ROOT}/cmake
${CMAKE_MODULE_PATH}
)
if (AMXX_EASY_HTTP_BUILD_TESTS)
set(AMXX_EASY_HTTP_BUILD_STATIC ON)
else ()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/out/bin/${CMAKE_BUILD_TYPE})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/out/pdb/${CMAKE_BUILD_TYPE})
endif ()
set(BUILD_SHARED_LIBS OFF) # BUILD_SHARED_LIBS only affect external dependencies
###
### Compilers setup
###
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message(FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}. Only GCC and MSVC are supported")
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(GCC ON)
endif ()
set(CMAKE_CXX_STANDARD 17)
if (GCC)
add_compile_options(
-m32
)
add_link_options(
-m32
-static-libstdc++ # Static linking of the GCC C++ runtime
-static-libgcc # Static linking of the GCC library
)
elseif (MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") # Static linking of the MSVC's C++ runtime
endif ()
###
### cpr setup
###
set(CPR_USE_SYSTEM_CURL ON)
set(CPR_ENABLE_SSL ON)
if (UNIX)
set(CPR_FORCE_OPENSSL_BACKEND ON)
elseif (WIN32)
set(CPR_FORCE_WINSSL_BACKEND ON)
endif ()
###
### Add dependencies and subprojects
###
add_subdirectory(dep/cpr)
add_subdirectory(dep/asyncplusplus)
add_subdirectory(dep/parson)
add_subdirectory(src)
if (GCC)
target_compile_options(cpr PRIVATE
-Wno-error=attribute-warning
)
endif ()
###
### GTest setup
###
if (AMXX_EASY_HTTP_BUILD_TESTS)
if (AMXX_EASY_HTTP_USE_SYSTEM_GTEST)
find_package(GTest)
endif ()
if (NOT AMXX_EASY_HTTP_USE_SYSTEM_GTEST OR NOT GTEST_FOUND)
message(STATUS "Not using system gtest, using built-in googletest project instead.")
FetchContent_Declare(GoogleTest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.15.2
USES_TERMINAL_DOWNLOAD TRUE) # <---- This is needed only for Ninja to show download progress
FetchContent_MakeAvailable(googletest)
add_library(gtest_int INTERFACE)
target_link_libraries(gtest_int INTERFACE gtest)
target_include_directories(gtest_int INTERFACE ${googletest_SOURCE_DIR}/include)
add_library(GTest::GTest ALIAS gtest_int)
# Group under the "tests/gtest" project folder in IDEs such as Visual Studio.
set_property(TARGET gtest PROPERTY FOLDER "tests/gtest")
set_property(TARGET gtest_main PROPERTY FOLDER "tests/gtest")
endif ()
enable_testing()
add_subdirectory(tests)
endif ()
###
### Add custom build targets
###
set(MAIN_TARGET_NAME easy_http)
add_custom_target(BUILD_ALL ALL)
add_dependencies(BUILD_ALL ${MAIN_TARGET_NAME})
add_custom_target(INSTALL_ALL
COMMENT "Copying '${MAIN_TARGET_NAME}' library to '$ENV{${MAIN_TARGET_NAME}_COPY_TO_PATH}'"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${MAIN_TARGET_NAME}> $ENV{${MAIN_TARGET_NAME}_COPY_TO_PATH})
add_custom_target(BUILD_AND_INSTALL_ALL ALL)
add_dependencies(BUILD_AND_INSTALL_ALL BUILD_ALL)
add_dependencies(BUILD_AND_INSTALL_ALL INSTALL_ALL)