From c73c8ca4736118fd9a0e043bc23757a592b1e306 Mon Sep 17 00:00:00 2001 From: Beats <61994374+beats-dh@users.noreply.github.com> Date: Tue, 1 Nov 2022 14:16:36 -0300 Subject: [PATCH] [Enhancement] Added build for use static librarys (#541) This activates builds in static lib, where DLLs files are not generated (they are included in the executable file) --- CMakePresets.json | 14 ++++++++++---- src/CMakeLists.txt | 40 +++++++++++++++++++++++++++++++++------- src/otpch.cpp | 20 -------------------- 3 files changed, 43 insertions(+), 31 deletions(-) delete mode 100644 src/otpch.cpp diff --git a/CMakePresets.json b/CMakePresets.json index 589c334a359..5a5868d943b 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -15,8 +15,10 @@ "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": { "value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", - "type": "FILEPATH" + "type": "FILEPATH" }, + "BUILD_STATIC_LIBRARY": "ON", + "VCPKG_TARGET_TRIPLET": "x64-windows-static", "CMAKE_BUILD_TYPE": "RelWithDebInfo", "OPTIONS_ENABLE_SCCACHE": "ON" }, @@ -44,7 +46,7 @@ "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": { "value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", - "type": "FILEPATH" + "type": "FILEPATH" }, "CMAKE_BUILD_TYPE": "RelWithDebInfo", "OPTIONS_ENABLE_CCACHE": "ON" @@ -61,7 +63,9 @@ "displayName": "Windows - Release + ASAN", "description": "Release Mode with ASAN", "cacheVariables": { - "ASAN_ENABLED": "ON" + "ASAN_ENABLED": "ON", + "BUILD_STATIC_LIBRARY": "OFF", + "VCPKG_TARGET_TRIPLET": "x64-windows" }, "architecture": { "value": "x64", @@ -76,7 +80,9 @@ "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "DEBUG_LOG": "ON", - "ASAN_ENABLED": "ON" + "ASAN_ENABLED": "ON", + "BUILD_STATIC_LIBRARY": "OFF", + "VCPKG_TARGET_TRIPLET": "x64-windows" }, "architecture": { "value": "x64", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aa6aa6e86a3..000577c5e69 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,8 @@ -project(canary) +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + project(canary-debug) +else() + project(canary) +endif() # ***************************************************************************** # Cmake Features @@ -27,9 +31,11 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # ***************************************************************************** # Options # ***************************************************************************** +option(TOGGLE_BIN_FOLDER "Use build/bin folder for generate compilation files" ON) option(OPTIONS_ENABLE_OPENMP "Enable Open Multi-Processing support." ON) option(DEBUG_LOG "Enable Debug Log" OFF) option(ASAN_ENABLED "Build this target with AddressSanitizer" OFF) +option(BUILD_STATIC_LIBRARY "Build using static libraries" OFF) # ***************************************************************************** @@ -94,12 +100,12 @@ endif() # === DEBUG LOG === # cmake -DDEBUG_LOG=ON .. -if(CMAKE_BUILD_TYPE MATCHES Debug) +if(DEBUG_LOG) target_compile_definitions(${PROJECT_NAME} PRIVATE -DDEBUG_LOG=ON ) log_option_enabled("DEBUG LOG") else() log_option_disabled("DEBUG LOG") -endif(CMAKE_BUILD_TYPE MATCHES Debug) +endif(DEBUG_LOG) # Set for suppress deprecated declarations (for GCC/GNU) @@ -267,7 +273,6 @@ target_sources(${PROJECT_NAME} map/house/house.cpp map/house/housetile.cpp map/map.cpp - otpch.cpp otserv.cpp security/rsa.cpp server/network/connection/connection.cpp @@ -297,7 +302,17 @@ if (MSVC) string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}") endif() - target_compile_options(${PROJECT_NAME} PUBLIC /MP /FS /Zf /EHsc ) + if(BUILD_STATIC_LIBRARY) + log_option_enabled("STATIC_LIBRARY") + set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib") + find_package(unofficial-libmariadb CONFIG REQUIRED) + set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + target_link_libraries(${PROJECT_NAME} PRIVATE unofficial::libmariadb unofficial::mariadbclient jsoncpp_static) + else() + log_option_disabled("STATIC_LIBRARY") + target_link_libraries(${PROJECT_NAME} PRIVATE jsoncpp_lib) + target_compile_options(${PROJECT_NAME} PUBLIC /MP /FS /Zf /EHsc ) + endif() target_include_directories(${PROJECT_NAME} PRIVATE @@ -312,7 +327,6 @@ if (MSVC) ${Protobuf_INCLUDE_DIRS} ${SPDLOG_INCLUDE_DIR} ${GMP_INCLUDE_DIR} - $ ) target_link_libraries(${PROJECT_NAME} @@ -327,7 +341,6 @@ if (MSVC) ${SPDLOG_LIBRARY} ${GMP_LIBRARIES} fmt::fmt - jsoncpp_lib ) else() @@ -365,3 +378,16 @@ set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" ) + +## Link compilation files to build/bin folder, else link to the main dir +if (TOGGLE_BIN_FOLDER) + set_target_properties(${PROJECT_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + ) +else() + set_target_properties(${PROJECT_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/" + ) +endif() diff --git a/src/otpch.cpp b/src/otpch.cpp deleted file mode 100644 index bc54154a6f9..00000000000 --- a/src/otpch.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/** - * The Forgotten Server - a free and open-source MMORPG server emulator - * Copyright (C) 2019 Mark Samman - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "otpch.h"