-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
94 lines (76 loc) · 3.01 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
cmake_minimum_required(VERSION 3.13...3.25)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(LANGS C CXX)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
foreach(lang ${LANGS})
if(NOT DEFINED CMAKE_${lang}_COMPILER_LAUNCHER AND NOT CMAKE_${lang}_COMPILER MATCHES ".*/ccache")
message(STATUS "Enabling ccache for ${lang}")
set(CMAKE_${lang}_COMPILER_LAUNCHER ${CCACHE_PROGRAM} CACHE STRING "")
endif()
endforeach()
endif()
project(wshttp
VERSION 0.0.1
DESCRIPTION "websocket streaming capable http client"
LANGUAGES ${LANGS})
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(WSHTTP_IS_TOPLEVEL_PROJECT TRUE)
else()
set(WSHTTP_IS_TOPLEVEL_PROJECT FALSE)
endif()
# TODO: not configured yet for shared vs static
option(BUILD_SHARED_LIBS "Build as shared library" OFF)
option(BUILD_STATIC_DEPS "Build and link against static dependencies" OFF)
option(WARNINGS_AS_ERRORS "Treat all warnings as errors. turn off for development, on for release" OFF)
option(WSHTTP_BUILD_TESTS "Build wshttp test suite" ${WSHTTP_IS_TOPLEVEL_PROJECT})
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
include(GNUInstallDirs)
set(default_lto ON)
if(WIN32 OR APPLE OR BUILD_STATIC_DEPS)
set(default_lto OFF)
endif()
option(WITH_LTO "Compile with Link-time Optimization" ${default_lto})
if(WITH_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_ENABLED OUTPUT ipo_error)
if(IPO_ENABLED)
message(STATUS "LTO enabled")
else()
message(WARNING "LTO not supported by compiler: ${ipo_error}")
endif()
else()
message(STATUS "LTO disabled")
set(IPO_ENABLED OFF)
endif()
set(IPO_ENABLED OFF)
if(IPO_ENABLED AND NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
endif()
# external interface target for any general includes meant to be publicly inherited
add_library(wshttp_external INTERFACE)
target_include_directories(wshttp_external INTERFACE include)
# internal interface target for flags, paths, etc
add_library(wshttp_internal INTERFACE)
target_include_directories(wshttp_internal INTERFACE include/wshttp)
option(WARNINGS_AS_ERRORS "treat all warnings as errors. turn off for development, on for release" OFF)
set(warning_flags -Wall -Wextra -Wno-unknown-pragmas -Wno-unused-function -Werror=vla -Wno-deprecated-declaration)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND warning_flags -Wno-unknown-warning-option)
endif()
if(WARNINGS_AS_ERRORS)
list(APPEND warning_flags -Werror)
endif()
add_library(wshttp_internal_warnings INTERFACE)
target_compile_options(wshttp_internal_warnings INTERFACE "$<$<OR:$<COMPILE_LANGUAGE:CXX>,$<COMPILE_LANGUAGE:C>>:${warning_flags}>")
target_link_libraries(wshttp_internal INTERFACE wshttp_internal_warnings)
# add_link_options(-lexplain)
add_subdirectory(external)
add_subdirectory(src)
if(WSHTTP_BUILD_TESTS)
add_subdirectory(tests)
endif()