From f150ee857f029026cd504bdbf34e904f3d15ce2f Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 14 Jun 2026 12:45:18 +0100 Subject: [PATCH] Build vendored libraries as static libraries and link against them. This avoids rebuilding code we've already built. --- CMakeLists.txt | 5 +++-- modules/CMakeLists.txt | 2 +- modules/database/db_json.cpp | 6 +++++- modules/encryption/enc_bcrypt.cpp | 6 +++++- modules/encryption/enc_md5.cpp | 6 +++++- modules/encryption/enc_sha1.cpp | 6 +++++- modules/encryption/enc_sha2.cpp | 6 +++++- modules/rpc/jsonrpc.cpp | 8 +++++++- vendor/CMakeLists.txt | 20 ++++++++++++++++++++ 9 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 vendor/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b82143b7..9de5cf910 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,8 @@ # This usage of CMake requires at least version 3.20 cmake_minimum_required(VERSION 3.20 FATAL_ERROR) -# Set the project as C++ primarily -project(Anope CXX) +# Set the project as C++ primarily with C for the vendored libraries +project(Anope CXX C) # Force the locale to C for later uses of things like gcc so the messages come up in English, not the user's default language set(ENV{LC_ALL} C) @@ -294,6 +294,7 @@ endif() add_subdirectory(data) add_subdirectory(docs) add_subdirectory(language) +add_subdirectory(vendor) add_subdirectory(src) add_subdirectory(modules) add_subdirectory(include) diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index d92e0ac08..1574e5d96 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -50,7 +50,7 @@ macro(inline_cmake TARGET FILE) set(CODE "${CODE}\n${CLEAN_LINE}") endif() elseif(LINE MATCHES "^/// BEGIN CMAKE$") - message(STATUS "Executing inline CMake code for ${TARGET}") + message(DEBUG "Executing inline CMake code for ${TARGET}") set(IN_CODE ON) endif() endforeach() diff --git a/modules/database/db_json.cpp b/modules/database/db_json.cpp index e74caf42a..4dc4b7229 100644 --- a/modules/database/db_json.cpp +++ b/modules/database/db_json.cpp @@ -12,10 +12,14 @@ // // SPDX-License-Identifier: GPL-2.0-only +/// BEGIN CMAKE +/// target_link_libraries(${SO} PRIVATE "vendored_yyjson") +/// END CMAKE + #include namespace fs = std::filesystem; -#include "yyjson/yyjson.c" +#include "yyjson/yyjson.h" #include "module.h" diff --git a/modules/encryption/enc_bcrypt.cpp b/modules/encryption/enc_bcrypt.cpp index 55a323612..8ead26858 100644 --- a/modules/encryption/enc_bcrypt.cpp +++ b/modules/encryption/enc_bcrypt.cpp @@ -12,10 +12,14 @@ // // SPDX-License-Identifier: GPL-2.0-only +/// BEGIN CMAKE +/// target_link_libraries(${SO} PRIVATE "vendored_bcrypt") +/// END CMAKE + #include #include -#include "bcrypt/crypt_blowfish.c" +#include "bcrypt/crypt_blowfish.h" #include "module.h" #include "modules/encryption.h" diff --git a/modules/encryption/enc_md5.cpp b/modules/encryption/enc_md5.cpp index 1dbdef327..4e0784733 100644 --- a/modules/encryption/enc_md5.cpp +++ b/modules/encryption/enc_md5.cpp @@ -12,10 +12,14 @@ // // SPDX-License-Identifier: GPL-2.0-only +/// BEGIN CMAKE +/// target_link_libraries(${SO} PRIVATE "vendored_md5") +/// END CMAKE + #include "module.h" #include "modules/encryption.h" -#include "md5/md5.c" +#include "md5/md5.h" class MD5Context final : public Encryption::Context diff --git a/modules/encryption/enc_sha1.cpp b/modules/encryption/enc_sha1.cpp index d65802a95..a34c4e635 100644 --- a/modules/encryption/enc_sha1.cpp +++ b/modules/encryption/enc_sha1.cpp @@ -12,10 +12,14 @@ // // SPDX-License-Identifier: GPL-2.0-only +/// BEGIN CMAKE +/// target_link_libraries(${SO} PRIVATE "vendored_sha1") +/// END CMAKE + #include "module.h" #include "modules/encryption.h" -#include "sha1/sha1.c" +#include "sha1/sha1.h" class SHA1Context final : public Encryption::Context diff --git a/modules/encryption/enc_sha2.cpp b/modules/encryption/enc_sha2.cpp index 49e97fc84..2ddae4044 100644 --- a/modules/encryption/enc_sha2.cpp +++ b/modules/encryption/enc_sha2.cpp @@ -12,10 +12,14 @@ // // SPDX-License-Identifier: GPL-2.0-only +/// BEGIN CMAKE +/// target_link_libraries(${SO} PRIVATE "vendored_sha2") +/// END CMAKE + #include #include -#include "sha2/sha2.c" +#include "sha2/sha2.h" #include "module.h" #include "modules/encryption.h" diff --git a/modules/rpc/jsonrpc.cpp b/modules/rpc/jsonrpc.cpp index b556dfe5c..39c580464 100644 --- a/modules/rpc/jsonrpc.cpp +++ b/modules/rpc/jsonrpc.cpp @@ -12,11 +12,17 @@ // // SPDX-License-Identifier: GPL-2.0-only +/// BEGIN CMAKE +/// target_link_libraries(${SO} PRIVATE "vendored_yyjson") +/// END CMAKE + +#include + #include "module.h" #include "modules/rpc.h" #include "modules/httpd.h" -#include "yyjson/yyjson.c" +#include "yyjson/yyjson.h" template struct overloaded : Ts... { using Ts::operator()...; }; template overloaded(Ts...) -> overloaded; diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt new file mode 100644 index 000000000..5a4e02863 --- /dev/null +++ b/vendor/CMakeLists.txt @@ -0,0 +1,20 @@ +file(GLOB LIBRARIES CONFIGURE_DEPENDS "*") +foreach(LIBRARY IN LISTS LIBRARIES) + if(IS_DIRECTORY ${LIBRARY}) + file(GLOB_RECURSE LIBRARY_SOURCES CONFIGURE_DEPENDS + "${LIBRARY}/*.c" + "${LIBRARY}/*.cc" + "${LIBRARY}/*.cpp" + ) + if(LIBRARY_SOURCES) + cmake_path(GET LIBRARY FILENAME LIBRARY_NAME) + set(LIBRARY_TARGET "vendored_${LIBRARY_NAME}") + add_library(${LIBRARY_TARGET} STATIC ${LIBRARY_SOURCES}) + target_compile_options(${LIBRARY_TARGET} PRIVATE "$,/W0,-w>") + set_target_properties(${LIBRARY_TARGET} PROPERTIES + FOLDER "VendoredLibraries" + PREFIX "" + ) + endif() + endif() +endforeach()