Skip to content

Commit

Permalink
Add libcurl download & build script for optional windows dependency (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
0blu authored Oct 31, 2024
1 parent 2d0db2a commit 83fe148
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 68 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ cmake-build-*
#
# Top-level generic files
#
bin
build
/bin/
/build/
/run/
/opt/
tags
TAGS
!.gitignore
Expand Down
37 changes: 27 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ include(cmake/options.cmake)

include(cmake/platform/detect_platform.cmake)

if(USE_LIBCURL)
find_package(CURL REQUIRED)
#add_definitions(-D_HAS_AUTO_PTR_ETC) # for VS2017 ACE support, won't do any harm to other compilers
#set(CMAKE_CXX_STANDARD 17)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
endif()

# Force out-of-source build
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" BUILDING_IN_SOURCE)
if(BUILDING_IN_SOURCE)
Expand Down Expand Up @@ -136,7 +129,13 @@ if(NOT USE_STD_MALLOC)

endif()

# Win32 delifered packages
if (ENABLE_MAILSENDER)
set(REQUIRES_LIBCURL ON)
else()
set(REQUIRES_LIBCURL OFF)
endif()

# Using the prepackages Windows dependencies from the repo
if(WIN32)
set(MYSQL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/dep/windows/include/mysql)
set(MYSQL_LIBRARY ${CMAKE_SOURCE_DIR}/dep/windows/lib/${DEP_ARCH}_release/libmySQL.lib)
Expand All @@ -145,6 +144,10 @@ if(WIN32)
set(OPENSSL_LIBRARIES ${CMAKE_SOURCE_DIR}/dep/windows/lib/${DEP_ARCH}_release/libeay32.lib)
set(OPENSSL_DEBUG_LIBRARIES ${CMAKE_SOURCE_DIR}/dep/windows/lib/${DEP_ARCH}_debug/libeay32.lib)
set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/dep/windows/include/zlib)
if (REQUIRES_LIBCURL)
set(CURL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/dep/windows/optional_dependencies/curl/include)
set(CURL_LIBRARY ${CMAKE_SOURCE_DIR}/dep/windows/optional_dependencies/curl/lib/libcurl.lib)
endif()
endif()

# *nix-specific packages
Expand All @@ -154,6 +157,20 @@ if(UNIX)
find_package(ZLIB REQUIRED)
endif()

if(REQUIRES_LIBCURL)
if(WIN32)
find_package(CURL) # No `REQUIRED`, since we want to print our own message.
if(NOT CURL_FOUND OR NOT CURL_VERSION_STRING)
message(FATAL_ERROR
"Your build options require CURL to be present, but it was not found.\n"
"You can find a script to automatically download CURL in dep/windows/optional_dependencies"
)
endif()
else()
find_package(CURL REQUIRED)
endif()
endif()

# Add uninstall script and target
#configure_file(
# "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
Expand Down Expand Up @@ -304,8 +321,8 @@ if(USE_STD_MALLOC)
set(DEFINITIONS ${DEFINITIONS} USE_STANDARD_MALLOC)
endif()

if (USE_LIBCURL)
set(DEFINITIONS ${DEFINITIONS} USE_SENDGRID)
if (ENABLE_MAILSENDER)
set(DEFINITIONS ${DEFINITIONS} ENABLE_MAILSENDER)
endif()

set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS ${DEFINITIONS})
Expand Down
21 changes: 10 additions & 11 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
option(USE_STD_MALLOC "Use standard malloc instead of TBB" OFF)
option(BUILD_FOR_HOST_CPU "Build specifically for the host CPU via `-march=native` (might not run on different machines)" ON)
option(TBB_DEBUG "Use TBB debug libraries" OFF)
option(USE_SCRIPTS "Compile scripts" ON)
option(USE_EXTRACTORS "Compile extractors" OFF)
option(USE_LIBCURL "Compile with libcurl for email support" OFF)
option(USE_REALMMERGE "Compile helper tool for merging character databases" OFF)
option(USE_SCRIPTS "Build scripts" ON)
option(USE_EXTRACTORS "Build extractors" OFF)
option(USE_REALMMERGE "Build helper tool for merging character databases" OFF)
option(ENABLE_MAILSENDER "Enables support for sending emails via sendgrid.com (requires libcurl)" OFF)

# Other options
set(SUPPORTED_CLIENT_BUILD "CLIENT_BUILD_1_12_1" CACHE STRING "Client version the core will support")
Expand Down Expand Up @@ -48,7 +48,6 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()


message("")
message(STATUS
"This script builds the vMaNGOS server.
Expand All @@ -60,16 +59,16 @@ message(STATUS
USE_STD_MALLOC Use standard malloc instead of TBB
BUILD_FOR_HOST_CPU Build specifically for the host CPU via `-march=native` (might not run on different machines)
TBB_DEBUG Use TBB debug libraries
USE_SCRIPTS Compile scripts
USE_EXTRACTORS Compile extractors
USE_LIBCURL Compile with libcurl for email support
USE_REALMMERGE Compile helper tool for merging character databases
USE_SCRIPTS Build scripts
USE_EXTRACTORS Build extractors
USE_REALMMERGE Build helper tool for merging character databases
ENABLE_MAILSENDER Enables support for sending emails via sendgrid.com (requires libcurl)
SUPPORTED_CLIENT_BUILD Client version the core will support
To set an option simply type -D<OPTION>=<VALUE> after 'cmake <srcs>'.
Also, you can specify the generator with -G. see 'cmake --help' for more details
For example:
Build server
cmake -DCMAKE_INSTALL_PREFIX=../opt/vmangos ..
Build server with default settings:
$ mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=../opt/vmangos ..
")
6 changes: 6 additions & 0 deletions cmake/showoptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ else()
message(STATUS "Build scripts : No")
endif()

if(ENABLE_MAILSENDER)
message(STATUS "Mailsender enabled : Yes")
else()
message(STATUS "Mailsender enabled : No (default)")
endif()

if(UNIX)
if(DEBUG_SYMBOLS)
message(STATUS "Debug symbols : Included")
Expand Down
1 change: 1 addition & 0 deletions dep/windows/optional_dependencies/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl/
83 changes: 83 additions & 0 deletions dep/windows/optional_dependencies/curl_download_and_build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
@echo off
setlocal enabledelayedexpansion

set paths[0]=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat
set aliases[0]=Visual Studio 2017
set paths[1]=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
set aliases[1]=Visual Studio 2017 (Enterprise)

set paths[2]=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat
set aliases[2]=Visual Studio 2019
set paths[3]=C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
set aliases[3]=Visual Studio 2019 (Enterprise)

set paths[4]=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat
set aliases[4]=Visual Studio 2022
set paths[5]=C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat
set aliases[5]=Visual Studio 2022 (Enterprise)

set available_paths=
set available_aliases=
set count=0

for /l %%i in (0, 1, 5) do (
if exist "!paths[%%i]!" (
set available_paths[!count!]=!paths[%%i]!
set available_aliases[!count!]=!aliases[%%i]!
echo !count!: !aliases[%%i]!
set /a count+=1
)
)

if %count% equ 1 (
echo Selected: !available_aliases[0]!
set VS_VARS_ALL_PATH="!available_paths[0]!"
) else if %count% gtr 1 (
set /p choice="Enter the number of the Visual Studio version to use: "
if defined available_paths[%choice%] (
echo Selected: !available_aliases[%choice%]!
set VS_VARS_ALL_PATH="!available_paths[%choice%]!"
) else (
echo Invalid choice.
)
) else (
color 4
echo No valid Visual Studio installations found.
pause
exit /b 1
)

:: Setup env vars
call %VS_VARS_ALL_PATH% x64 || (color 4 & echo Error detected & pause & exit /b)

@echo on

if not exist curl (mkdir curl)
cd curl
if not exist lib (mkdir lib)
if not exist include (mkdir include)

if not exist "curl-build" (
call git clone --branch curl-8_10_1 --depth 1 https://github.com/curl/curl.git curl-build || (color 4 & echo Error detected & pause & exit /b)
)

cd curl-build
call buildconf.bat || (color 4 & echo Error detected & pause & exit /b)
cd winbuild
call nmake /f Makefile.vc mode=dll MACHINE=x64 || (color 4 & echo Error detected & pause & exit /b)

cd ..\..
::xcopy /y "curl-build\builds\libcurl-vc-x64-release-static-ipv6-sspi-schannel\lib\libcurl_a.lib" "lib\" || (color 4 & echo Error detected & pause & exit /b)
::xcopy /e /i /y "curl-build\builds\libcurl-vc-x64-release-static-ipv6-sspi-schannel\include" "include" || (color 4 & echo Error detected & pause & exit /b)
xcopy /y "curl-build\builds\libcurl-vc-x64-release-dll-ipv6-sspi-schannel\lib\libcurl.lib" "lib\" || (color 4 & echo Error detected & pause & exit /b)
xcopy /e /i /y "curl-build\builds\libcurl-vc-x64-release-dll-ipv6-sspi-schannel\include" "include" || (color 4 & echo Error detected & pause & exit /b)

color 2
echo.
echo.
echo ================================
echo Done :)
echo Press enter to delete the temporary build folder
pause

rmdir /s /q curl-build
7 changes: 2 additions & 5 deletions src/mangosd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

set(EXECUTABLE_NAME mangosd)
set(EXECUTABLE_SRCS
set(EXECUTABLE_SRCS
CliRunnable.h
MaNGOSsoap.h
Master.h
Expand All @@ -35,12 +35,11 @@ if(WIN32)
list(APPEND EXECUTABLE_SRCS
mangosd.rc
)

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D__ACE_INLINE__")
endif()

include_directories(
${CMAKE_SOURCE_DIR}/src/shared
${CMAKE_SOURCE_DIR}/dep/include/g3dlite
${CMAKE_SOURCE_DIR}/src/framework
${CMAKE_SOURCE_DIR}/src/framework/Network
Expand Down Expand Up @@ -69,8 +68,6 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/game/Threat
${CMAKE_SOURCE_DIR}/src/game/Transports
${CMAKE_SOURCE_DIR}/src/game/vmap
${CMAKE_BINARY_DIR}/src/shared
${CMAKE_BINARY_DIR}
${ACE_INCLUDE_DIR}
${MYSQL_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
Expand Down
4 changes: 2 additions & 2 deletions src/realmd/AuthSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "PatchHandler.h"
#include "Util.h"

#ifdef USE_SENDGRID
#ifdef ENABLE_MAILSENDER
#include "MailerService.h"
#include "SendgridMail.h"
#endif
Expand Down Expand Up @@ -722,7 +722,7 @@ bool AuthSocket::_HandleLogonProof()
return true;
}

#ifdef USE_SENDGRID
#ifdef ENABLE_MAILSENDER
if (sConfig.GetBoolDefault("SendMail", false))
{
auto mail = std::make_unique<SendgridMail>
Expand Down
24 changes: 2 additions & 22 deletions src/realmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

set(EXECUTABLE_NAME realmd)
set(EXECUTABLE_SRCS
set(EXECUTABLE_SRCS
AuthCodes.h
AuthSocket.h
BufferedSocket.h
Expand All @@ -34,24 +34,8 @@ if(WIN32)
list(APPEND EXECUTABLE_SRCS
realmd.rc
)

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D__ACE_INLINE__")
endif()

include_directories(
${CMAKE_SOURCE_DIR}/src/shared
${CMAKE_SOURCE_DIR}/src/framework
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/src/shared
${MYSQL_INCLUDE_DIR}
${ACE_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
)

if(WIN32)
include_directories(
${CMAKE_SOURCE_DIR}/dep/windows/include
)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D__ACE_INLINE__")
endif()

add_executable(${EXECUTABLE_NAME}
Expand Down Expand Up @@ -89,10 +73,6 @@ if(UNIX)
)
endif()

if (USE_LIBCURL)
target_link_libraries(${EXECUTABLE_NAME} curl)
endif()

set(EXECUTABLE_LINK_FLAGS "")

if(UNIX)
Expand Down
4 changes: 2 additions & 2 deletions src/realmd/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include <ace/Acceptor.h>
#include <ace/SOCK_Acceptor.h>

#ifdef USE_SENDGRID
#ifdef ENABLE_MAILSENDER
#include "MailerService.h"
#include <curl/curl.h>
#endif
Expand Down Expand Up @@ -217,7 +217,7 @@ extern int main(int argc, char **argv)

sLog.Out(LOG_BASIC, LOG_LVL_DETAIL, "Using ACE: %s", ACE_VERSION);

#ifdef USE_SENDGRID
#ifdef ENABLE_MAILSENDER
sLog.Out(LOG_BASIC, LOG_LVL_DETAIL, "Using CURL version %s", curl_version());

// not checking the SendMail config option here to make sure config reloads will work (in the future?)
Expand Down
2 changes: 1 addition & 1 deletion src/realmd/realmd.conf.dist.in
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ ConfVersion=2020010501
#
# SendMail
# Whether the server is allowed to send emails
# The server must have been compiled with USE_SENDGRID
# The server must have been compiled with ENABLE_MAILSENDER
# Default: 0 (Do not send mail)
#
# MailFrom
Expand Down
Loading

0 comments on commit 83fe148

Please sign in to comment.