Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make use of CMake presets to enable easy switching between debug and release configurations on all platforms #1439

Merged
merged 86 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
2239507
Add MSVC optimization flags
jadebenn Jan 29, 2024
b682f13
Merge branch 'DarkflameUniverse:main' into MSVCCompilerFlags
jadebenn Jan 30, 2024
8a34544
test moving flags to json
jadebenn Jan 30, 2024
9b7c593
Update CMakePresets.json
jadebenn Jan 30, 2024
70f3756
testing
jadebenn Jan 31, 2024
10d7776
trying more variations on the flags
jadebenn Jan 31, 2024
e7058be
third test
jadebenn Jan 31, 2024
ab39754
testing if these even have any effect
jadebenn Jan 31, 2024
119937f
ditto
jadebenn Jan 31, 2024
ae2115c
final(?) try for now
jadebenn Jan 31, 2024
3fa8006
ONE MORE TIME
jadebenn Jan 31, 2024
4b7d1d6
trying 'init' flags instead
jadebenn Jan 31, 2024
9627639
export the compile commands so I can see if they're having any effect
jadebenn Jan 31, 2024
6cc99fa
Merge branch 'DarkflameUniverse:main' into MSVCCompilerFlags
jadebenn Feb 3, 2024
7c9f56f
move out g++ O2 flag
jadebenn Feb 3, 2024
d5089b7
add Linux debug preset
jadebenn Feb 4, 2024
62fb8ad
Merge branch 'DarkflameUniverse:main' into MSVCCompilerFlags
jadebenn Feb 9, 2024
9316bd6
Merge branch 'DarkflameUniverse:main' into MSVCCompilerFlags
jadebenn Feb 11, 2024
1116ba8
Merge branch 'DarkflameUniverse:main' into MSVCCompilerFlags
jadebenn Feb 12, 2024
199c822
Merge remote-tracking branch 'upstream/main' into MSVCCompilerFlags
jadebenn Apr 4, 2024
bba825f
update CMake presets
jadebenn Apr 4, 2024
005d439
edit macos presets
jadebenn Apr 4, 2024
a3d7019
try adding build types back to mac
jadebenn Apr 4, 2024
81e5f05
macos refuses to work :(
jadebenn Apr 4, 2024
018e570
try using compiler flags for mac instead
jadebenn Apr 4, 2024
661e093
fix typo in windows preset
jadebenn Apr 4, 2024
145f97c
build reorganization and experimental clang support
jadebenn Apr 5, 2024
f7da00f
Merge branch 'MSVCCompilerFlags' of https://github.com/jadebenn/Darkf…
jadebenn Apr 5, 2024
db5c10c
temporarily remove macos build for testing purposes
jadebenn Apr 5, 2024
9ce7d90
updated cmake workflows
jadebenn Apr 5, 2024
426d34a
unexclude toolchain dir
jadebenn Apr 5, 2024
a19afaa
update .gitignore
jadebenn Apr 5, 2024
9fc6b4e
fix build directory issue
jadebenn Apr 5, 2024
04a7bc2
edit build script
jadebenn Apr 6, 2024
ef8029d
update cmake configs
jadebenn Apr 6, 2024
7812f27
Merge branch 'main' into MSVCCompilerFlags
jadebenn Apr 6, 2024
24cbd94
attempted docker fix
jadebenn Apr 6, 2024
d6031ce
try zero-initializinng this struct to solve docker issue
jadebenn Apr 6, 2024
bc79a17
try fixing macos build
jadebenn Apr 6, 2024
6e41423
one last MacOS try for the night
jadebenn Apr 6, 2024
45ec66e
try disabling an apple-specific build rule
jadebenn Apr 6, 2024
0f843c0
more fiddling with mac test builds
jadebenn Apr 6, 2024
5fd8683
try and narrow down the macos build failure cause
jadebenn Apr 6, 2024
cc15a26
try stripping out all the custom macos test logic again
jadebenn Apr 6, 2024
1a05b02
I'm really just throwing everything to the wall and seeing what sticks
jadebenn Apr 6, 2024
829ec35
more macos tinkering
jadebenn Apr 6, 2024
d41349d
implib
jadebenn Apr 6, 2024
0c2d406
try manual link directory specification
jadebenn Apr 6, 2024
bd73aa2
save me
jadebenn Apr 6, 2024
338279c
aaaaaaaaa
jadebenn Apr 6, 2024
9a7d86a
paths paths paths
jadebenn Apr 6, 2024
dccac94
Revert "paths paths paths"
jadebenn Apr 6, 2024
c420a72
Revert "aaaaaaaaa"
jadebenn Apr 6, 2024
ce56818
Revert "save me"
jadebenn Apr 6, 2024
37dbb52
Revert "try manual link directory specification"
jadebenn Apr 6, 2024
495e70c
Revert "implib"
jadebenn Apr 6, 2024
e143f22
Revert "more macos tinkering"
jadebenn Apr 6, 2024
8af3572
Revert "I'm really just throwing everything to the wall and seeing wh…
jadebenn Apr 6, 2024
54876bf
Revert "try stripping out all the custom macos test logic again"
jadebenn Apr 6, 2024
8f5c10d
Revert "try and narrow down the macos build failure cause"
jadebenn Apr 6, 2024
8154207
Revert "more fiddling with mac test builds"
jadebenn Apr 6, 2024
bdf9adc
Revert "try disabling an apple-specific build rule"
jadebenn Apr 6, 2024
07626f8
back to debug messages
jadebenn Apr 7, 2024
a4b6b7c
see if this re-breaks mac
jadebenn Apr 7, 2024
fab74c9
are these messages actually somehow fixing the issue?
jadebenn Apr 7, 2024
6c6966a
was not actually fixed
jadebenn Apr 7, 2024
c6c771b
add debug messages (again)
jadebenn Apr 7, 2024
abe413f
debug try 2
jadebenn Apr 7, 2024
d6e4edd
change runtime output dir
jadebenn Apr 7, 2024
aa62d35
rename gcc to gnu
jadebenn Apr 7, 2024
57d0b12
expand cmake presets
jadebenn Apr 7, 2024
7d7ea68
fix preset
jadebenn Apr 7, 2024
368f4cc
change defaults
jadebenn Apr 7, 2024
24d3bc0
altered cmake configuration scripts
jadebenn Apr 9, 2024
7eae64f
disable /WX on MSVC
jadebenn Apr 9, 2024
39a8029
update github actions
jadebenn Apr 9, 2024
553740e
update build presets
jadebenn Apr 9, 2024
7f9fcb5
change gnu and clang build directories to enable consistent artifact …
jadebenn Apr 9, 2024
c4adcee
Merge remote-tracking branch 'upstream/main' into MSVCCompilerFlags
jadebenn Apr 9, 2024
b96cfd7
Merge remote-tracking branch 'upstream/main' into MSVCCompilerFlags
jadebenn Apr 9, 2024
6ccd72c
add RelWithDebInfo presets and move -Werror flag into presets.json
jadebenn Apr 13, 2024
6e781da
Merge remote-tracking branch 'upstream/main' into MSVCCompilerFlags
jadebenn Apr 13, 2024
d1bfe9f
Merge branch 'main' into MSVCCompilerFlags
jadebenn Nov 17, 2024
d7aa52a
use DLU_CONFIG_DIR envvar
jadebenn Nov 17, 2024
0e81c69
CMakePresets indentation
jadebenn Nov 17, 2024
f4311e5
temp fix for MSVC debug builds
jadebenn Nov 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
os: [ windows-2022, ubuntu-22.04, macos-13 ]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- name: Add msbuild to PATH (Windows only)
if: ${{ matrix.os == 'windows-2022' }}
uses: microsoft/setup-msbuild@v1.1
uses: microsoft/setup-msbuild@v2
with:
vs-version: '[17,18)'
msbuild-architecture: x64
Expand All @@ -33,21 +33,19 @@ jobs:
- name: cmake
uses: lukka/run-cmake@v10
with:
configurePreset: "ci-${{matrix.os}}"
buildPreset: "ci-${{matrix.os}}"
testPreset: "ci-${{matrix.os}}"
workflowPreset: "ci-${{matrix.os}}"
jadebenn marked this conversation as resolved.
Show resolved Hide resolved
- name: artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: build-${{matrix.os}}
path: |
build/*Server*
build/*.ini
build/*.so
build/*.dll
build/vanity/
build/navmeshes/
build/migrations/
build/*.dcf
!build/*.pdb
!build/d*/
build/*/*Server*
build/*/*.ini
build/*/*.so
build/*/*.dll
build/*/vanity/
build/*/navmeshes/
build/*/migrations/
build/*/*.dcf
!build/*/*.pdb
!build/*/d*/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,7 @@ docker/__pycache__
docker-compose.override.yml

!*Test.bin

# CMake scripts
!cmake/*
!cmake/toolchains/*
86 changes: 54 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.25)
project(Darkflame)
project(Darkflame
HOMEPAGE_URL "https://github.com/DarkflameUniverse/DarkflameServer"
LANGUAGES C CXX
)

# check if the path to the source directory contains a space
if("${CMAKE_SOURCE_DIR}" MATCHES " ")
Expand All @@ -8,8 +11,10 @@ endif()

include(CTest)

set(CMAKE_C_STANDARD 99)
jadebenn marked this conversation as resolved.
Show resolved Hide resolved
set(CMAKE_CXX_STANDARD 20)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Export the compile commands for debugging
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) # Set CMAKE visibility policy to NEW on project and subprojects
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) # Set C and C++ symbol visibility to hide inlined functions
Expand Down Expand Up @@ -61,35 +66,36 @@ set(RECASTNAVIGATION_EXAMPLES OFF CACHE BOOL "" FORCE)
# Disabled no-register
# Disabled unknown pragmas because Linux doesn't understand Windows pragmas.
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wuninitialized -fPIC")
add_compile_options("-fPIC")
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0 _GLIBCXX_USE_CXX17_ABI=0)

if(NOT APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -lstdc++fs")
# For all except Clang and Apple Clang
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options("-static-libgcc" "-lstdc++fs")
endif()

if(${DYNAMIC} AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
add_compile_options("-rdynamic")
endif()

if(${GGDB})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
add_compile_options("-ggdb")
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -O2 -fPIC")
elseif(MSVC)
# Skip warning for invalid conversion from size_t to uint32_t for all targets below for now
# Also disable non-portable MSVC volatile behavior
add_compile_options("/wd4267" "/utf-8" "/volatile:iso")
add_compile_options("/wd4267" "/utf-8" "/volatile:iso" "/Zc:inline")
elseif(WIN32)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()

# Our output dir
set(CMAKE_BINARY_DIR ${PROJECT_BINARY_DIR})
#set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) # unfortunately, forces all libraries to be built in series, which will slow down the build process

# TODO make this not have to override the build type directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR})
Expand All @@ -109,31 +115,39 @@ make_directory(${CMAKE_BINARY_DIR}/resServer)
# Create a /logs directory
make_directory(${CMAKE_BINARY_DIR}/logs)

# Get DLU config directory
if(DEFINED ENV{DLU_CONFIG_DIR})
set(DLU_CONFIG_DIR $ENV{DLU_CONFIG_DIR})
else()
set(DLU_CONFIG_DIR ${PROJECT_BINARY_DIR})
endif()
message(STATUS "Variable: DLU_CONFIG_DIR = ${DLU_CONFIG_DIR}")

# Copy resource files on first build
set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blocklist.dcf")
message(STATUS "Checking resource file integrity")

include(Utils)
UpdateConfigOption(${PROJECT_BINARY_DIR}/authconfig.ini "port" "auth_server_port")
UpdateConfigOption(${PROJECT_BINARY_DIR}/chatconfig.ini "port" "chat_server_port")
UpdateConfigOption(${PROJECT_BINARY_DIR}/masterconfig.ini "port" "master_server_port")
UpdateConfigOption(${DLU_CONFIG_DIR}/authconfig.ini "port" "auth_server_port")
UpdateConfigOption(${DLU_CONFIG_DIR}/chatconfig.ini "port" "chat_server_port")
UpdateConfigOption(${DLU_CONFIG_DIR}/masterconfig.ini "port" "master_server_port")

foreach(resource_file ${RESOURCE_FILES})
set(file_size 0)

if(EXISTS ${PROJECT_BINARY_DIR}/${resource_file})
file(SIZE ${PROJECT_BINARY_DIR}/${resource_file} file_size)
if(EXISTS ${DLU_CONFIG_DIR}/${resource_file})
file(SIZE ${DLU_CONFIG_DIR}/${resource_file} file_size)
endif()

if(${file_size} EQUAL 0)
configure_file(
${CMAKE_SOURCE_DIR}/resources/${resource_file} ${PROJECT_BINARY_DIR}/${resource_file}
${CMAKE_SOURCE_DIR}/resources/${resource_file} ${DLU_CONFIG_DIR}/${resource_file}
COPYONLY
)
message(STATUS "Moved " ${resource_file} " to project binary directory")
message(STATUS "Moved " ${resource_file} " to DLU config directory")
elseif(resource_file MATCHES ".ini")
message(STATUS "Checking " ${resource_file} " for missing config options")
file(READ ${PROJECT_BINARY_DIR}/${resource_file} current_file_contents)
file(READ ${DLU_CONFIG_DIR}/${resource_file} current_file_contents)
string(REPLACE "\\\n" "" current_file_contents ${current_file_contents})
string(REPLACE "\n" ";" current_file_contents ${current_file_contents})
set(parsed_current_file_contents "")
Expand Down Expand Up @@ -164,10 +178,10 @@ foreach(resource_file ${RESOURCE_FILES})
set(line_to_add ${line_to_add} ${line})

foreach(line_to_append ${line_to_add})
file(APPEND ${PROJECT_BINARY_DIR}/${resource_file} "\n" ${line_to_append})
file(APPEND ${DLU_CONFIG_DIR}/${resource_file} "\n" ${line_to_append})
endforeach()

file(APPEND ${PROJECT_BINARY_DIR}/${resource_file} "\n")
file(APPEND ${DLU_CONFIG_DIR}/${resource_file} "\n")
endif()

set(line_to_add "")
Expand Down Expand Up @@ -236,14 +250,15 @@ include_directories(
"tests/dGameTests"
"tests/dGameTests/dComponentsTests"

SYSTEM "thirdparty/magic_enum/include/magic_enum"
SYSTEM "thirdparty/raknet/Source"
SYSTEM "thirdparty/tinyxml2"
SYSTEM "thirdparty/recastnavigation"
SYSTEM "thirdparty/SQLite"
SYSTEM "thirdparty/cpplinq"
SYSTEM "thirdparty/cpp-httplib"
SYSTEM "thirdparty/MD5"
SYSTEM
"thirdparty/magic_enum/include/magic_enum"
"thirdparty/raknet/Source"
"thirdparty/tinyxml2"
"thirdparty/recastnavigation"
"thirdparty/SQLite"
"thirdparty/cpplinq"
"thirdparty/cpp-httplib"
"thirdparty/MD5"
)

# Add system specfic includes for Apple, Windows and Other Unix OS' (including Linux)
Expand All @@ -252,10 +267,17 @@ if(APPLE)
include_directories("/usr/local/include/")
endif()

# Add linking directories:
if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast -Werror") # Warning flags
# Set warning flags
if(MSVC)
# add_compile_options("/W4")
# Want to enable warnings eventually, but WAY too much noise right now
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
add_compile_options("-Wuninitialized" "-Wold-style-cast")
else()
message(WARNING "Unknown compiler: '${CMAKE_CXX_COMPILER_ID}' - No warning flags enabled.")
endif()

# Add linking directories:
file(
GLOB HEADERS_DZONEMANAGER
LIST_DIRECTORIES false
Expand Down
Loading
Loading