From 4fe57d1a241003101f45ab5f3128ad37a66aac73 Mon Sep 17 00:00:00 2001 From: Syping Date: Thu, 29 Feb 2024 20:55:33 +0100 Subject: [PATCH] CMake: incomplete DPPAsExternalProject impl --- CMakeLists.txt | 7 ++- cmake/DPPAsExternalProject.cmake | 77 ++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 cmake/DPPAsExternalProject.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c6f84ac..ad05d7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,12 @@ if (WITH_BOOST) endif() # D++ Discord API Library for Bots -find_package(DPP REQUIRED) +option(WITH_DPP_AS_EXTERNAL_PROJECT "Build with DPP as External Project" OFF) +if (WITH_DPP_AS_EXTERNAL_PROJECT) + include(DPPAsExternalProject) +else() + find_package(DPP REQUIRED) +endif() # pthread Support set(THREADS_PREFER_PTHREAD_FLAG ON) diff --git a/cmake/DPPAsExternalProject.cmake b/cmake/DPPAsExternalProject.cmake new file mode 100644 index 0000000..f9f1d06 --- /dev/null +++ b/cmake/DPPAsExternalProject.cmake @@ -0,0 +1,77 @@ +#[[************************************************************************** +* dtranslatebot Discord Translate Bot +* Copyright (C) 2024 Syping +* +* Redistribution and use in source and binary forms, with or without modification, +* are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* This software is provided as-is, no warranties are given to you, we are not +* responsible for anything with use of the software, you are self responsible. +****************************************************************************]] + +# OpenSSL needs to build with make +find_program(MAKE_EXECUTABLE NAMES make gmake) +if (NOT MAKE_EXECUTABLE) + message(SEND_ERROR "make not found") +endif() + +find_program(NPROC_EXECUTABLE nproc) +if (NPROC_EXECUTABLE) + execute_process( + COMMAND ${NPROC_EXECUTABLE} + OUTPUT_VARIABLE NPROC + ) + set(JOBS_ARGUMENT "-j${NPROC}" CACHE STRING "make jobs argument") +endif() + +include(ExternalProject) +ExternalProject_Add(ZLIB + URL https://www.zlib.net/zlib-1.3.1.tar.xz + URL_HASH SHA256=38ef96b8dfe510d42707d9c781877914792541133e1870841463bfa73f883e32 + DOWNLOAD_EXTRACT_TIMESTAMP TRUE + CMAKE_ARGS + -DBUILD_SHARED_LIBS=OFF + "-DCMAKE_INSTALL_PREFIX=" + -DZLIB_BUILD_EXAMPLES=OFF +) +ExternalProject_Get_Property(ZLIB INSTALL_DIR) +set(ZLIB_INSTALL_DIR ${INSTALL_DIR}) + +ExternalProject_Add(OpenSSL + URL https://www.openssl.org/source/openssl-3.0.13.tar.gz + URL_HASH SHA256=88525753f79d3bec27d2fa7c66aa0b92b3aa9498dafd93d7cfa4b3780cdae313 + DOWNLOAD_EXTRACT_TIMESTAMP TRUE + CONFIGURE_COMMAND + "/config" + "--prefix=" + "--api=1.1.1" + no-deprecated + no-dtls + no-shared + no-zlib + BUILD_COMMAND ${MAKE_EXECUTABLE} ${JOBS_ARGUMENT} + INSTALL_COMMAND ${MAKE_EXECUTABLE} ${JOBS_ARGUMENT} install_sw +) +ExternalProject_Get_Property(OpenSSL INSTALL_DIR) +set(OpenSSL_INSTALL_DIR ${INSTALL_DIR}) + +ExternalProject_Add(DPP + GIT_REPOSITORY https://github.com/brainboxdotcc/DPP.git + GIT_TAG 46044c8f80134633f7b396b4d5814f83d54a96d3 + CMAKE_ARGS + -DBUILD_SHARED_LIBS=OFF + -DBUILD_VOICE_SUPPORT=OFF + "-DCMAKE_INSTALL_PREFIX=" + -DDPP_NO_VCPKG=ON + "-DOpenSSL_ROOT=${OpenSSL_INSTALL_DIR}" + "-DZLIB_ROOT=${ZLIB_INSTALL_DIR}" + DEPENDS OpenSSL + DEPENDS ZLIB +)