| 1 |
# |
| 2 |
# D++ (DPP), The Lightweight C++ Discord Library |
| 3 |
# |
| 4 |
# Copyright 2021 Craig Edwards <[email protected]> |
| 5 |
# |
| 6 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
# you may not use this file except in compliance with the License. |
| 8 |
# You may obtain a copy of the License at |
| 9 |
# |
| 10 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
# |
| 12 |
# Unless required by applicable law or agreed to in writing, software |
| 13 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
# See the License for the specific language governing permissions and |
| 16 |
# limitations under the License. |
| 17 |
# |
| 18 |
|
| 19 |
cmake_minimum_required (VERSION 3.16) |
| 20 |
set(CMAKE_CXX_STANDARD 17) |
| 21 |
|
| 22 |
option(BUILD_SHARED_LIBS "Build shared libraries" ON) |
| 23 |
option(BUILD_VOICE_SUPPORT "Build voice support" ON) |
| 24 |
option(RUN_LDCONFIG "Run ldconfig after installation" ON) |
| 25 |
option(DPP_INSTALL "Generate the install target" ON) |
| 26 |
option(DPP_BUILD_TEST "Build the test program" ON) |
| 27 |
option(DPP_NO_VCPKG "No VCPKG" OFF) |
| 28 |
option(DPP_NO_CONAN "No Conan" OFF) |
| 29 |
option(CONAN_EXPORTED "Exported via Conan - DO NOT SET MANUALLY" OFF) |
| 30 |
option(DPP_NO_CORO "Remove Support for C++20 coroutines" OFF) |
| 31 |
option(DPP_FORMATTERS "Support for C++20 formatters" OFF) |
| 32 |
option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OFF) |
| 33 |
option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF) |
| 34 |
option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF) |
| 35 |
option(DPP_TEST_VCPKG "Force VCPKG build without VCPKG installed (for development use only!)" OFF) |
| 36 |
|
| 37 |
include(CheckCXXSymbolExists) |
| 38 |
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 39 |
add_compile_definitions(DPP_BUILD) |
| 40 |
add_compile_definitions(NOMINMAX) |
| 41 |
|
| 42 |
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/colour.cmake") |
| 43 |
|
| 44 |
set(DPP_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) |
| 45 |
|
| 46 |
file(READ "${DPP_ROOT_PATH}/include/dpp/version.h" version_h) |
| 47 |
|
| 48 |
if(NOT version_h MATCHES "DPP_VERSION_SHORT ([0-9][0-9])([0-9][0-9])([0-9][0-9])") |
| 49 |
message(FATAL_ERROR "Cannot get DPP_VERSION_SHORT from version.h") |
| 50 |
endif() |
| 51 |
|
| 52 |
math(EXPR DPP_VERSION_MAJOR "${CMAKE_MATCH_1}") |
| 53 |
math(EXPR DPP_VERSION_MINOR "${CMAKE_MATCH_2}") |
| 54 |
math(EXPR DPP_VERSION_PATCH "${CMAKE_MATCH_3}") |
| 55 |
|
| 56 |
string(CONCAT DPP_VERSION "${DPP_VERSION_MAJOR}.${DPP_VERSION_MINOR}.${DPP_VERSION_PATCH}") |
| 57 |
|
| 58 |
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${DPP_ROOT_PATH}/cmake/") |
| 59 |
|
| 60 |
if (DPP_TEST_VCPKG) |
| 61 |
message("-- ${Red}DEVELOPER WARNING${ColourReset}: Running in ${Red}VCPKG test mode${ColourReset}: EMULATING A VCPKG BUILD WITHOUT VCPKG") |
| 62 |
else() |
| 63 |
if (DPP_NO_VCPKG) |
| 64 |
message("${ColourReset}-- INFO: Explicitly disabling VCPKG as running inside the CI action.") |
| 65 |
else() |
| 66 |
message("${ColourReset}-- INFO: Using VCPKG if detected") |
| 67 |
endif() |
| 68 |
endif() |
| 69 |
|
| 70 |
if (DPP_NO_CONAN) |
| 71 |
message("-- INFO: Explicitly disabling Conan as running inside the CI action.") |
| 72 |
endif() |
| 73 |
|
| 74 |
if (WIN32 AND NOT MINGW AND BUILD_SHARED_LIBS) |
| 75 |
message("-- INFO: Configuring .rc resource script") |
| 76 |
configure_file("${DPP_ROOT_PATH}/src/dpp/dpp.rc.in" "${DPP_ROOT_PATH}/src/dpp/dpp.rc" NEWLINE_STYLE WIN32) |
| 77 |
endif() |
| 78 |
|
| 79 |
if (DPP_TEST_VCPKG) |
| 80 |
set(PROJECT_NAME "dpp") |
| 81 |
project( |
| 82 |
"${PROJECT_NAME}" |
| 83 |
VERSION "${DPP_VERSION}" |
| 84 |
LANGUAGES CXX |
| 85 |
HOMEPAGE_URL "https://dpp.dev/" |
| 86 |
DESCRIPTION "An incredibly lightweight C++ Discord library." |
| 87 |
) |
| 88 |
|
| 89 |
if (MSVC AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") |
| 90 |
set(DPP_CLANG_CL true) |
| 91 |
endif() |
| 92 |
|
| 93 |
# Required before we add any subdirectories. |
| 94 |
if (DPP_BUILD_TEST) |
| 95 |
enable_testing(${CMAKE_CURRENT_SOURCE_DIR}) |
| 96 |
endif() |
| 97 |
|
| 98 |
add_subdirectory(library-vcpkg) |
| 99 |
else() |
| 100 |
if (NOT DPP_NO_VCPKG AND EXISTS "${_VCPKG_ROOT_DIR}") |
| 101 |
set(PROJECT_NAME "dpp") |
| 102 |
project( |
| 103 |
"${PROJECT_NAME}" |
| 104 |
VERSION "${DPP_VERSION}" |
| 105 |
LANGUAGES CXX |
| 106 |
HOMEPAGE_URL "https://dpp.dev/" |
| 107 |
DESCRIPTION "An incredibly lightweight C++ Discord library." |
| 108 |
) |
| 109 |
|
| 110 |
if (MSVC AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") |
| 111 |
set(DPP_CLANG_CL true) |
| 112 |
endif() |
| 113 |
|
| 114 |
# Required before we add any subdirectories. |
| 115 |
if (DPP_BUILD_TEST) |
| 116 |
enable_testing(${CMAKE_CURRENT_SOURCE_DIR}) |
| 117 |
endif() |
| 118 |
|
| 119 |
add_subdirectory(library-vcpkg) |
| 120 |
else() |
| 121 |
set(PROJECT_NAME "libdpp") |
| 122 |
project( |
| 123 |
"${PROJECT_NAME}" |
| 124 |
VERSION "${DPP_VERSION}" |
| 125 |
LANGUAGES CXX |
| 126 |
HOMEPAGE_URL "https://dpp.dev/" |
| 127 |
DESCRIPTION "An incredibly lightweight C++ Discord library." |
| 128 |
) |
| 129 |
|
| 130 |
if (MSVC AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") |
| 131 |
set(DPP_CLANG_CL true) |
| 132 |
endif() |
| 133 |
|
| 134 |
# Required before we add any subdirectories. |
| 135 |
if (DPP_BUILD_TEST) |
| 136 |
enable_testing(${CMAKE_CURRENT_SOURCE_DIR}) |
| 137 |
endif() |
| 138 |
|
| 139 |
add_subdirectory(library) |
| 140 |
endif() |
| 141 |
endif() |
| 142 |
|
| 143 |
find_package(Filesystem) |
| 144 |
|
| 145 |
if(DPP_USE_EXTERNAL_JSON) |
| 146 |
# We do nothing here, we just assume it is on the include path. |
| 147 |
# nlohmann::json's cmake stuff does all kinds of weird, and is more hassle than it's worth. |
| 148 |
# This functionality is here mostly for package maintainers so if you enable it you should |
| 149 |
# know what you are doing. |
| 150 |
message("-- Using external nlohmann::json") |
| 151 |
target_compile_definitions(dpp PUBLIC DPP_USE_EXTERNAL_JSON) |
| 152 |
else() |
| 153 |
# Add the nlohmann single include to the include path. Note that nlohmann::json is kinda |
| 154 |
# fussy, this is an older version because trying to use v3.11.2 gave a bunch of parse errors |
| 155 |
# that made no sense, it seems they may have changed their parsing rules somehow. |
| 156 |
message("-- Using bundled nlohmann::json") |
| 157 |
endif() |
| 158 |
|
| 159 |
if (NOT WIN32) |
| 160 |
target_link_libraries(dpp PRIVATE std::filesystem) |
| 161 |
endif() |