-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
86 lines (66 loc) · 1.97 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
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
project(cpp_http_request VERSION 0.1.1)
option(BUILD_TESTS "Build tests" OFF)
set(APP_NAME cpp_http_request_tests)
set(LIB_NAME cpp_http_request)
set(SHARED_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_library(${LIB_NAME} INTERFACE)
target_include_directories(${LIB_NAME} INTERFACE include/)
target_compile_features(${LIB_NAME} INTERFACE cxx_std_17)
if(BUILD_TESTS)
include(FetchContent)
include(CTest)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()
FetchContent_Declare(
json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.7.3
)
if(NOT json_POPULATED)
FetchContent_Populate(json)
set(json_INCLUDE_DIR ${json_SOURCE_DIR}/include)
endif()
enable_testing()
set(SOURCES
src/http_request_tests.cc
src/https_request_tests.cc
)
add_executable(${APP_NAME} ${SOURCES} ${HEADERS})
find_package(OpenSSL)
if(OPENSSL_FOUND)
target_compile_definitions(${APP_NAME} PUBLIC CPP_HTTP_REQUEST_SUPPORT_SSL)
endif()
target_include_directories(${APP_NAME} PUBLIC
${SHARED_INCLUDE_DIR}
${EXTERNAL_INCLUDE_DIR}
${json_INCLUDE_DIR}
)
set_target_properties(${APP_NAME} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_compile_options(${APP_NAME} PUBLIC
-pthread
-pedantic
-Wall
-Wextra
-Wshadow
)
add_test(UnitTests ${APP_NAME})
target_link_libraries(${APP_NAME} PUBLIC
${LIB_NAME}
gtest
gmock
gtest_main
OpenSSL::SSL)
endif()