Skip to content

Building Static Deps on Windows, etc. #1526

@Bioblaze

Description

@Bioblaze

I am working on a node editor interface, and recently was asked to make a discord bot plugin for the system.

I realized after alot of research, you have some serious hardcoded references to your libs, and made it really annoying since I needed a single static build of the dpp found out omfg its 4gb, so set with a dynamic linked library but then the associated deps were also dynamically linked, like i need them static.

So I wrote a patch that is absolute shit.
But it works for my project as it is, so I decided to post it here in issues, since I doubt its good enough to be a PR lol

diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt
index cc94d030..ac05e15d 100644
--- a/library/CMakeLists.txt
+++ b/library/CMakeLists.txt
@@ -69,9 +69,16 @@ endif()
 
 if (CONAN_EXPORTED)
 	message("-- INFO: ${Green}Conan detected${ColourReset}... finding packages...")
-	find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto)
-	find_package(ZLIB REQUIRED)
-	find_package(Opus)
+	if (NOT WIN32)
+		# On non-Windows, use find_package for Conan targets
+		find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto)
+		find_package(ZLIB REQUIRED)
+		find_package(Opus)
+	else()
+		# On Windows with CONAN_EXPORTED, libraries are provided externally
+		# via cache variables (OPENSSL_SSL_LIBRARY, OPENSSL_CRYPTO_LIBRARY, ZLIB_LIBRARY)
+		message("-- Using externally provided OpenSSL/zlib libraries")
+	endif()
 	find_package(Threads REQUIRED)
 	find_package(Git QUIET)
 endif()
@@ -98,6 +105,11 @@ if(WIN32 AND NOT MINGW)
 			set(HAVE_OPUS_OPUS_H "${CMAKE_CURRENT_SOURCE_DIR}/../win32/include/opus/opus.h")
 
 			include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../win32/include")
+		else()
+			# CONAN_EXPORTED: Use externally provided OpenSSL/zlib
+			# Include dirs and libraries are set by parent CMakeLists.txt
+			message("-- Using externally provided OpenSSL and zlib (static linking)")
+			include_directories(${OPENSSL_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
 		endif()
 
 		set(OPUS_FOUND 1)
@@ -295,6 +307,10 @@ foreach (fullmodname ${subdirlist})
 				"${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/lib/zlib.lib")
 		endif()
 
+	elseif (WIN32 AND NOT MINGW AND CONAN_EXPORTED)
+		# Windows with externally provided static OpenSSL/zlib (not Conan targets)
+		# Libraries are linked by parent CMakeLists.txt via target_link_libraries(dpp ...)
+		target_link_libraries(${modname} PUBLIC ws2_32 crypt32)
 	else()
 		if (CONAN_EXPORTED)
 			target_link_libraries(${modname} PUBLIC openssl::openssl ZLIB::ZLIB Opus::opus)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions