-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
CMakeLists.txt
160 lines (134 loc) · 5.18 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#
# D++ (DPP), The Lightweight C++ Discord Library
#
# Copyright 2021 Craig Edwards <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
cmake_minimum_required (VERSION 3.16)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(BUILD_VOICE_SUPPORT "Build voice support" ON)
option(RUN_LDCONFIG "Run ldconfig after installation" ON)
option(DPP_INSTALL "Generate the install target" ON)
option(DPP_BUILD_TEST "Build the test program" ON)
option(DPP_NO_VCPKG "No VCPKG" OFF)
option(DPP_NO_CONAN "No Conan" OFF)
option(CONAN_EXPORTED "Exported via Conan - DO NOT SET MANUALLY" OFF)
option(DPP_CORO "Support for C++20 coroutines" OFF)
option(DPP_FORMATTERS "Support for C++20 formatters" OFF)
option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OFF)
option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF)
option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF)
option(DPP_TEST_VCPKG "Force VCPKG build without VCPKG installed (for development use only!)" OFF)
include(CheckCXXSymbolExists)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_compile_definitions(DPP_BUILD)
add_compile_definitions(NOMINMAX)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/colour.cmake")
set(DPP_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
file(READ "${DPP_ROOT_PATH}/include/dpp/version.h" version_h)
if(NOT version_h MATCHES "DPP_VERSION_SHORT ([0-9][0-9])([0-9][0-9])([0-9][0-9])")
message(FATAL_ERROR "Cannot get DPP_VERSION_SHORT from version.h")
endif()
math(EXPR DPP_VERSION_MAJOR "${CMAKE_MATCH_1}")
math(EXPR DPP_VERSION_MINOR "${CMAKE_MATCH_2}")
math(EXPR DPP_VERSION_PATCH "${CMAKE_MATCH_3}")
string(CONCAT DPP_VERSION "${DPP_VERSION_MAJOR}.${DPP_VERSION_MINOR}.${DPP_VERSION_PATCH}")
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${DPP_ROOT_PATH}/cmake/")
if (DPP_TEST_VCPKG)
message("-- ${Red}DEVELOPER WARNING${ColourReset}: Running in ${Red}VCPKG test mode${ColourReset}: EMULATING A VCPKG BUILD WITHOUT VCPKG")
else()
if (DPP_NO_VCPKG)
message("-- INFO: Explicitly disabling VCPKG as running inside the CI action.")
else()
message("-- INFO: Using VCPKG if detected")
endif()
endif()
if (DPP_NO_CONAN)
message("-- INFO: Explicitly disabling Conan as running inside the CI action.")
endif()
if (WIN32 AND NOT MINGW AND BUILD_SHARED_LIBS)
message("-- INFO: Configuring .rc resource script")
configure_file("${DPP_ROOT_PATH}/src/dpp/dpp.rc.in" "${DPP_ROOT_PATH}/src/dpp/dpp.rc" NEWLINE_STYLE WIN32)
endif()
if (DPP_TEST_VCPKG)
set(PROJECT_NAME "dpp")
project(
"${PROJECT_NAME}"
VERSION "${DPP_VERSION}"
LANGUAGES CXX
HOMEPAGE_URL "https://dpp.dev/"
DESCRIPTION "An incredibly lightweight C++ Discord library."
)
if (MSVC AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(DPP_CLANG_CL true)
endif()
# Required before we add any subdirectories.
if (DPP_BUILD_TEST)
enable_testing(${CMAKE_CURRENT_SOURCE_DIR})
endif()
add_subdirectory(library-vcpkg)
else()
if (NOT DPP_NO_VCPKG AND EXISTS "${_VCPKG_ROOT_DIR}")
set(PROJECT_NAME "dpp")
project(
"${PROJECT_NAME}"
VERSION "${DPP_VERSION}"
LANGUAGES CXX
HOMEPAGE_URL "https://dpp.dev/"
DESCRIPTION "An incredibly lightweight C++ Discord library."
)
if (MSVC AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(DPP_CLANG_CL true)
endif()
# Required before we add any subdirectories.
if (DPP_BUILD_TEST)
enable_testing(${CMAKE_CURRENT_SOURCE_DIR})
endif()
add_subdirectory(library-vcpkg)
else()
set(PROJECT_NAME "libdpp")
project(
"${PROJECT_NAME}"
VERSION "${DPP_VERSION}"
LANGUAGES CXX
HOMEPAGE_URL "https://dpp.dev/"
DESCRIPTION "An incredibly lightweight C++ Discord library."
)
if (MSVC AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(DPP_CLANG_CL true)
endif()
# Required before we add any subdirectories.
if (DPP_BUILD_TEST)
enable_testing(${CMAKE_CURRENT_SOURCE_DIR})
endif()
add_subdirectory(library)
endif()
endif()
find_package(Filesystem)
if(DPP_USE_EXTERNAL_JSON)
# We do nothing here, we just assume it is on the include path.
# nlohmann::json's cmake stuff does all kinds of weird, and is more hassle than it's worth.
# This functionality is here mostly for package maintainers so if you enable it you should
# know what you are doing.
message("-- Using external nlohmann::json")
target_compile_definitions(dpp PUBLIC DPP_USE_EXTERNAL_JSON)
else()
# Add the nlohmann single include to the include path. Note that nlohmann::json is kinda
# fussy, this is an older version because trying to use v3.11.2 gave a bunch of parse errors
# that made no sense, it seems they may have changed their parsing rules somehow.
message("-- Using bundled nlohmann::json")
endif()
if (NOT WIN32)
target_link_libraries(dpp PRIVATE std::filesystem)
endif()