From 024400be46a83957cea5bc4f34e1c729ed9fe21d Mon Sep 17 00:00:00 2001 From: Syping Date: Tue, 5 Mar 2024 21:02:05 +0100 Subject: [PATCH] improved external project passthrough of variables --- cmake/ArgumentPassthrough.cmake | 54 ++++++++++++++++++++++++++++++++ cmake/DPPAsExternalProject.cmake | 22 ++++--------- 2 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 cmake/ArgumentPassthrough.cmake diff --git a/cmake/ArgumentPassthrough.cmake b/cmake/ArgumentPassthrough.cmake new file mode 100644 index 0000000..56d25d1 --- /dev/null +++ b/cmake/ArgumentPassthrough.cmake @@ -0,0 +1,54 @@ +#[[************************************************************************** +* 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. +****************************************************************************]] + +if (DEFINED CMAKE_BUILD_TYPE) + list(APPEND CMAKE_PASSTHROUGH_ARGS "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") +endif() +if (DEFINED CMAKE_C_COMPILER) + list(APPEND CMAKE_PASSTHROUGH_ARGS "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}") + list(APPEND CMAKE_PASSTHROUGH_ENV "CC=${CMAKE_C_COMPILER}") +endif() +if (DEFINED CMAKE_C_COMPILER_TARGET) + list(APPEND CMAKE_PASSTHROUGH_ARGS "-DCMAKE_C_COMPILER_TARGET=${CMAKE_C_COMPILER_TARGET}") +endif() +if (DEFINED CMAKE_CXX_COMPILER) + list(APPEND CMAKE_PASSTHROUGH_ARGS "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}") +endif() +if (DEFINED CMAKE_CXX_COMPILER_TARGET) + list(APPEND CMAKE_PASSTHROUGH_ARGS "-DCMAKE_CXX_COMPILER_TARGET=${CMAKE_CXX_COMPILER_TARGET}") +endif() +if (DEFINED CMAKE_SYSROOT) + list(APPEND CMAKE_PASSTHROUGH_ARGS "-DCMAKE_SYSROOT=${CMAKE_SYSROOT}") +endif() +if (DEFINED CMAKE_SYSTEM_NAME) + list(APPEND CMAKE_PASSTHROUGH_ARGS "-DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}") +endif() +if (DEFINED CMAKE_SYSTEM_PROCESSOR) + list(APPEND CMAKE_PASSTHROUGH_ARGS "-DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}") +endif() +if (DEFINED CMAKE_SYSTEM_VERSION) + list(APPEND CMAKE_PASSTHROUGH_ARGS "-DCMAKE_SYSTEM_VERSION=${CMAKE_SYSTEM_VERSION}") +endif() +if (DEFINED CMAKE_TOOLCHAIN_FILE) + list(APPEND CMAKE_PASSTHROUGH_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") +endif() +if (DEFINED CMAKE_PASSTHROUGH_ENV) + set(CMAKE_PASSTHROUGH_ENV + "${CMAKE_COMMAND}" -E env ${CMAKE_PASSTHROUGH_ENV} + ) +endif() diff --git a/cmake/DPPAsExternalProject.cmake b/cmake/DPPAsExternalProject.cmake index b96dcc0..4b046a4 100644 --- a/cmake/DPPAsExternalProject.cmake +++ b/cmake/DPPAsExternalProject.cmake @@ -16,15 +16,7 @@ * responsible for anything with use of the software, you are self responsible. ****************************************************************************]] -# Needed for compiler passthrough -if (DEFINED CMAKE_C_COMPILER) - set(CMAKE_ENV_CC_COMMAND "${CMAKE_COMMAND}" -E env "CC=${CMAKE_C_COMPILER}") - set(DEFINE_CMAKE_C_COMPILER "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}") -endif() - -if (DEFINED CMAKE_CXX_COMPILER) - set(DEFINE_CMAKE_CXX_COMPILER "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}") -endif() +include(ArgumentPassthrough) # OpenSSL needs to be configured with perl and build with make find_package(Perl REQUIRED) @@ -36,10 +28,10 @@ endif() find_program(NPROC_EXECUTABLE nproc) if (DEFINED NPROC_EXECUTABLE) execute_process( - COMMAND ${NPROC_EXECUTABLE} + COMMAND "${NPROC_EXECUTABLE}" OUTPUT_VARIABLE NPROC ) - string(STRIP ${NPROC} NPROC) + string(STRIP "${NPROC}" NPROC) set(JOBS_ARGUMENT "-j${NPROC}" CACHE INTERNAL "make jobs argument") endif() @@ -49,8 +41,7 @@ ExternalProject_Add(ZLIB URL_HASH SHA256=38ef96b8dfe510d42707d9c781877914792541133e1870841463bfa73f883e32 CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF - "-DCMAKE_BUILD_TYPE=$" - "${DEFINE_CMAKE_C_COMPILER}" + "${CMAKE_PASSTHROUGH_ARGS}" "-DCMAKE_INSTALL_PREFIX=" -DZLIB_BUILD_EXAMPLES=OFF ) @@ -61,7 +52,7 @@ ExternalProject_Add(OpenSSL URL https://www.openssl.org/source/openssl-3.0.13.tar.gz URL_HASH SHA256=88525753f79d3bec27d2fa7c66aa0b92b3aa9498dafd93d7cfa4b3780cdae313 CONFIGURE_COMMAND - ${CMAKE_ENV_CC_COMMAND} + ${CMAKE_PASSTHROUGH_ENV} "${PERL_EXECUTABLE}" "/Configure" "--prefix=" @@ -84,8 +75,7 @@ ExternalProject_Add(DPP CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DBUILD_VOICE_SUPPORT=OFF - "-DCMAKE_BUILD_TYPE=$" - "${DEFINE_CMAKE_CXX_COMPILER}" + "${CMAKE_PASSTHROUGH_ARGS}" "-DCMAKE_INSTALL_PREFIX=" -DDPP_NO_VCPKG=ON -DRUN_LDCONFIG=OFF