From e043e28529db460e8bb6847414d280929283d87f Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sun, 31 Jan 2021 19:36:23 +0200 Subject: [PATCH] Add helper option to copy dependencies to a deps folder. --- CMakeLists.txt | 3 ++- module/CMakeLists.txt | 27 +++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc125b7a..653f425f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,8 +6,9 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/vendor/POCO/cmake) # Several plugin options -option(FORCE_32BIT_BIN "Create a 32-bit executable binary if the compiler defaults to 64-bit." OFF) option(ENABLE_API21 "Build for 2.1 API." OFF) +option(COPY_DEPENDENCIES "Copy deppendent DLLs into the deps folder." OFF) +option(FORCE_32BIT_BIN "Create a 32-bit executable binary if the compiler defaults to 64-bit." OFF) include(CheckCXXCompilerFlag) # C++ standard availability check diff --git a/module/CMakeLists.txt b/module/CMakeLists.txt index a4b04090..b371d250 100644 --- a/module/CMakeLists.txt +++ b/module/CMakeLists.txt @@ -144,7 +144,7 @@ if(FORCE_32BIT_BIN) endif() # Don't prefix the module binary. set_target_properties(SqModule PROPERTIES PREFIX "") -# Custmize module binary name/ +# Customize module binary name/ if(WIN32) if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT FORCE_32BIT_BIN) set_target_properties(SqModule PROPERTIES OUTPUT_NAME "mod_squirrel_64") @@ -162,5 +162,28 @@ endif(WIN32) target_include_directories(SqModule PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(SqModule PRIVATE ${CMAKE_CURRENT_LIST_DIR}/VCMP) target_include_directories(SqModule PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Sqrat) -# Copy module into the plugins folder +# Copy module into the plug-ins folder add_custom_command(TARGET SqModule POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ "${PROJECT_SOURCE_DIR}/bin/plugins") +# Copy several dependent DLLs on windows to make distribution easier (used mainly by people that distribute builds) +if(WIN32 AND MINGW AND COPY_DEPENDENCIES) + get_filename_component(MINGW_BIN_PATH ${CMAKE_C_COMPILER} DIRECTORY REALPATH) + if(NOT IS_DIRECTORY ${MINGW_BIN_PATH}) + get_filename_component(MINGW_BIN_PATH ${CMAKE_CXX_COMPILER} DIRECTORY REALPATH) + endif() + # Make sure the deps folder exists + file(MAKE_DIRECTORY "${PROJECT_SOURCE_DIR}/bin/deps") + # Copy dependencies into the plug-ins folder (only so it can be distributed with the DLL) + file(COPY "${MINGW_BIN_PATH}/libpq.dll" DESTINATION "${PROJECT_SOURCE_DIR}/bin/deps") + file(COPY "${MINGW_BIN_PATH}/libcurl-4.dll" DESTINATION "${PROJECT_SOURCE_DIR}/bin/deps") + file(COPY "${MINGW_BIN_PATH}/libmariadb.dll" DESTINATION "${PROJECT_SOURCE_DIR}/bin/deps") + if(POCO_UNBUNDLED) + file(COPY "${MINGW_BIN_PATH}/zlib1.dll" DESTINATION "${PROJECT_SOURCE_DIR}/bin/deps") + file(COPY "${MINGW_BIN_PATH}/libexpat-1.dll" DESTINATION "${PROJECT_SOURCE_DIR}/bin/deps") + file(COPY "${MINGW_BIN_PATH}/libsqlite3-0.dll" DESTINATION "${PROJECT_SOURCE_DIR}/bin/deps") + endif() + file(COPY "${MINGW_BIN_PATH}/libstdc++-6.dll" DESTINATION "${PROJECT_SOURCE_DIR}/bin/deps") + if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT FORCE_32BIT_BIN) + file(COPY "${MINGW_BIN_PATH}/libgcc_s_seh-1.dll" DESTINATION "${PROJECT_SOURCE_DIR}/bin/deps") + endif() + file(COPY "${MINGW_BIN_PATH}/libwinpthread-1.dll" DESTINATION "${PROJECT_SOURCE_DIR}/bin/deps") +endif()