1
0
mirror of https://github.com/anope/anope.git synced 2026-07-03 20:43:13 +02:00

Replace calculate_libraries with inline CMake code.

This commit is contained in:
Sadie Powell
2025-10-05 16:03:59 +01:00
parent 0b3e55ed8f
commit 1a5d49b7f6
14 changed files with 89 additions and 139 deletions
+7 -33
View File
@@ -52,12 +52,6 @@ macro(build_modules SRC)
file(RELATIVE_PATH FNAME ${SRC} ${MODULE_SRC})
# Convert the real source file extension to have a library extension
string(REGEX REPLACE "\\.cpp$" "${CMAKE_SHARED_LIBRARY_SUFFIX}" SO ${FNAME})
# Reset linker flags
set(TEMP_LDFLAGS)
# Reset extra dependencies
set(TEMP_DEPENDENCIES)
# Calculate the library dependencies for the given source file
calculate_libraries(${MODULE_SRC} TEMP_LDFLAGS TEMP_DEPENDENCIES)
# For Visual Studio only, include win32_memory static library, required to override Visual Studio's overrides of the new/delete operators
if(MSVC)
set(WIN32_MEMORY win32_memory)
@@ -66,6 +60,8 @@ macro(build_modules SRC)
endif()
# Generate the module and set its linker flags, also set it to depend on the main Anope executable to be built beforehand
add_library(${SO} MODULE ${MODULE_SRC})
# Execute inline CMake code for the module
inline_cmake(${SO} ${MODULE_SRC})
# Windows requires this because it's weird
if(WIN32)
set(WIN32_NO_LIBS "/nodefaultlib:\"libcmt.lib\" /OPT:NOREF")
@@ -77,7 +73,7 @@ macro(build_modules SRC)
FOLDER "Modules"
INSTALL_RPATH_USE_LINK_PATH ON
LINKER_LANGUAGE CXX
LINK_FLAGS "${TEMP_LDFLAGS} ${WIN32_NO_LIBS}"
LINK_FLAGS "${WIN32_NO_LIBS}"
PREFIX ""
SUFFIX ""
)
@@ -85,13 +81,12 @@ macro(build_modules SRC)
if(HAVE_LOCALIZATION)
add_dependencies(${SO} module_language)
endif()
target_link_libraries(${SO} ${TEMP_DEPENDENCIES})
# For Windows only, have the module link to the export library of Anope as well as wsock32 and Ws2_32 libraries (most of the modules probably don't need this, but this is to be on the safe side), also set its version
if(WIN32)
target_link_libraries(${SO} ${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY})
target_link_libraries(${SO} PUBLIC ${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY})
set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}")
elseif(APPLE)
target_link_libraries(${SO} ${PROGRAM_NAME})
target_link_libraries(${SO} PUBLIC ${PROGRAM_NAME})
endif()
# Set the module to be installed to the module directory under the data directory
install(TARGETS ${SO}
@@ -113,31 +108,11 @@ macro(build_subdir)
# Set all the files to use C++ as well as set their compile flags (use the module-specific compile flags, though)
set_source_files_properties(${MODULES_SUBDIR_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}")
# Iterate through the source files in the subdirectory
foreach(SRC ${MODULES_SUBDIR_SRCS})
# Reset linker flags
set(TEMP_LDFLAGS)
# Reset extra dependencies
set(TEMP_DEPENDENCIES)
# Calculate the library dependencies for the given source file
calculate_libraries(${SRC} SKIP_LIBRARIES MODULE TEMP_LDFLAGS TEMP_DEPENDENCIES)
# Append this source file's linker flags to the subdirectoy's linker flags, if there are any to append
if(TEMP_DEPENDENCIES)
list(APPEND SUBDIR_EXTRA_DEPENDS ${TEMP_DEPENDENCIES})
endif()
endforeach()
# Remove duplicates from the linker flags
if(SUBDIR_LDFLAGS)
list(REMOVE_DUPLICATES SUBDIR_LDFLAGS)
endif()
# Remove duplicates from the extra dependencies
if(SUBDIR_EXTRA_DEPENDS)
list(REMOVE_DUPLICATES SUBDIR_EXTRA_DEPENDS)
endif()
# For Visual Studio only, include win32_memory static library, required to override Visual Studio's overrides of the new/delete operators
if(MSVC)
set(WIN32_MEMORY win32_memory)
@@ -160,13 +135,12 @@ macro(build_subdir)
if(HAVE_LOCALIZATION)
add_dependencies(${SO} module_language)
endif()
target_link_libraries(${SO} ${SUBDIR_EXTRA_DEPENDS})
# For Windows only, have the module link to the export library of Anope as well as wsock32 and Ws2_32 libraries (most of the modules probably don't need this, but this is to be on the safe side), also set it's version
if(WIN32)
target_link_libraries(${SO} ${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY})
target_link_libraries(${SO} PUBLIC ${PROGRAM_NAME} PUBLIC wsock32 Ws2_32 ${WIN32_MEMORY})
set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}")
elseif(APPLE)
target_link_libraries(${SO} ${PROGRAM_NAME})
target_link_libraries(${SO} PUBLIC ${PROGRAM_NAME})
endif()
# Set the module to be installed to the module directory under the data directory
+8 -2
View File
@@ -8,8 +8,14 @@
*
*/
/* RequiredLibraries: argon2 */
/* RequiredWindowsLibraries: argon2 */
/// BEGIN CMAKE
/// if(WIN32)
/// target_link_libraries(${SO} PRIVATE CONAN_PKG::argon2)
/// else()
/// pkg_check_modules("ARGON2" IMPORTED_TARGET REQUIRED "libargon2")
/// target_link_libraries(${SO} PRIVATE PkgConfig::ARGON2)
/// endif()
/// END CMAKE
#include <climits>
#include <random>
-2
View File
@@ -8,8 +8,6 @@
*
*/
/* RequiredLibraries: crypt */
#include "module.h"
class EPOSIX final
+6 -1
View File
@@ -9,7 +9,12 @@
* Based on the original code of Services by Andy Church.
*/
/* RequiredLibraries: ldap_r|ldap,lber */
/// BEGIN CMAKE
/// if(NOT WIN32)
/// pkg_check_modules("OPENLDAP" IMPORTED_TARGET REQUIRED "lber" "ldap")
/// target_link_libraries(${SO} PRIVATE PkgConfig::OPENLDAP)
/// endif()
/// END CMAKE
#include "module.h"
#include "modules/ldap.h"
+8 -2
View File
@@ -6,8 +6,14 @@
* Please read COPYING and README for further details.
*/
/* RequiredLibraries: mysqlclient */
/* RequiredWindowsLibraries: libmysql */
/// BEGIN CMAKE
/// if(WIN32)
/// target_link_libraries(${SO} PRIVATE CONAN_PKG::libmysqlclient)
/// else()
/// pkg_search_module("MYSQL" IMPORTED_TARGET REQUIRED "mysqlclient" "mariadb")
/// target_link_libraries(${SO} PRIVATE PkgConfig::MYSQL)
/// endif()
/// END CMAKE
#include "module.h"
#include "modules/sql.h"
+8 -2
View File
@@ -6,8 +6,14 @@
* Please read COPYING and README for further details.
*/
/* RequiredLibraries: pcre2-8 */
/* RequiredWindowsLibraries: pcre2-8 */
/// BEGIN CMAKE
/// if(WIN32)
/// target_link_libraries(${SO} PRIVATE CONAN_PKG::pcre2)
/// else()
/// pkg_check_modules("PCRE2" IMPORTED_TARGET REQUIRED "libpcre2-8")
/// target_link_libraries(${SO} PRIVATE PkgConfig::PCRE2)
/// endif()
/// END CMAKE
#include "module.h"
+4 -1
View File
@@ -6,7 +6,10 @@
* Please read COPYING and README for further details.
*/
/* RequiredLibraries: tre */
/// BEGIN CMAKE
/// pkg_check_modules("TRE" IMPORTED_TARGET REQUIRED "tre")
/// target_link_libraries(${SO} PRIVATE PkgConfig::TRE)
/// END CMAKE
#include "module.h"
#include <tre/regex.h>
+4 -2
View File
@@ -6,8 +6,10 @@
* Please read COPYING and README for further details.
*/
/* RequiredLibraries: sqlite3 */
/* RequiredWindowsLibraries: sqlite3 */
/// BEGIN CMAKE
/// find_package("SQLite3" REQUIRED)
/// target_link_libraries(${SO} PRIVATE SQLite::SQLite3)
/// END CMAKE
#include "module.h"
#include "modules/sql.h"
+4 -2
View File
@@ -7,8 +7,10 @@
* Please read COPYING and README for further details.
*/
/* RequiredLibraries: gnutls */
/* RequiredWindowsLibraries: libgnutls-30 */
/// BEGIN CMAKE
/// find_package("GnuTLS" REQUIRED)
/// target_link_libraries(${SO} PRIVATE GnuTLS::GnuTLS)
/// END CMAKE
#include "module.h"
#include "modules/ssl.h"
+4 -2
View File
@@ -6,8 +6,10 @@
* Please read COPYING and README for further details.
*/
/* RequiredLibraries: ssl,crypto */
/* RequiredWindowsLibraries: libssl,libcrypto */
/// BEGIN CMAKE
/// find_package("OpenSSL" REQUIRED)
/// target_link_libraries(${SO} PRIVATE OpenSSL::Crypto OpenSSL::SSL)
/// END CMAKE
#include "module.h"
#include "modules/ssl.h"
+5 -2
View File
@@ -6,8 +6,11 @@
* Please read COPYING and README for further details.
*/
/* RequiredLibraries: xmlrpc */
/// BEGIN CMAKE
/// find_library("XMLRPC" "xmlrpc" REQUIRED)
/// message(STATUS "Found XMLRPC: ${XMLRPC}")
/// target_link_libraries(${SO} PRIVATE ${XMLRPC})
/// END CMAKE
#include <xmlrpc-c/base.h>