Skip to content

Commit

Permalink
[Enhancement] Added build for use static librarys (#541)
Browse files Browse the repository at this point in the history
This activates builds in static lib, where DLLs files are not generated (they are included in the executable file)
  • Loading branch information
beats-dh authored Nov 1, 2022
1 parent 8a35e84 commit c73c8ca
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
14 changes: 10 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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",
Expand Down
40 changes: 33 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
project(canary)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
project(canary-debug)
else()
project(canary)
endif()

# *****************************************************************************
# Cmake Features
Expand Down Expand Up @@ -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)


# *****************************************************************************
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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$<$<CONFIG:Debug>: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
Expand All @@ -312,7 +327,6 @@ if (MSVC)
${Protobuf_INCLUDE_DIRS}
${SPDLOG_INCLUDE_DIR}
${GMP_INCLUDE_DIR}
$<TARGET_PROPERTY:jsoncpp_lib,INTERFACE_INCLUDE_DIRECTORIES>
)

target_link_libraries(${PROJECT_NAME}
Expand All @@ -327,7 +341,6 @@ if (MSVC)
${SPDLOG_LIBRARY}
${GMP_LIBRARIES}
fmt::fmt
jsoncpp_lib
)

else()
Expand Down Expand Up @@ -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()
20 changes: 0 additions & 20 deletions src/otpch.cpp

This file was deleted.

0 comments on commit c73c8ca

Please sign in to comment.