From 6fe8ba59b7eb9af3e5fb1f7f2ddc3a3c27d3578c Mon Sep 17 00:00:00 2001 From: tooomm Date: Sat, 29 Aug 2026 16:49:37 +0200 Subject: [PATCH 01/13] Update compile.sh --- .ci/compile.sh | 151 ++++++++++++++++++++++++++++--------------------- 1 file changed, 85 insertions(+), 66 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index 8a16d3243..ef0a3faef 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -122,51 +122,53 @@ done set -e -# Setup -./servatrice/check_schema_version.sh -if [[ ! $BUILDTYPE ]]; then +# Schema version consistency +if [[ $MAKE_SERVER == "1" ]]; then + ./servatrice/check_schema_version.sh +fi + +# Use default values if unset +if [[ -z $BUILDTYPE ]]; then BUILDTYPE=Release fi -if [[ ! $BUILD_DIR ]]; then +if [[ -z $BUILD_DIR ]]; then BUILD_DIR="build" fi mkdir -p "$BUILD_DIR" cd "$BUILD_DIR" -# Set minimum CMake Version -export CMAKE_POLICY_VERSION_MINIMUM=3.10 - -# Add cmake flags +# CMake options flags=("-DCMAKE_BUILD_TYPE=$BUILDTYPE") -if [[ $MAKE_SERVER ]]; then +if [[ $MAKE_SERVER == "1" ]]; then flags+=("-DWITH_SERVER=1") fi -if [[ $MAKE_NO_CLIENT ]]; then +if [[ $MAKE_NO_CLIENT == "1" ]]; then flags+=("-DWITH_CLIENT=0" "-DWITH_ORACLE=0") fi -if [[ $MAKE_TEST ]]; then +if [[ $MAKE_TEST == "1" ]]; then flags+=("-DTEST=1") fi -if [[ $USE_CCACHE ]]; then +if [[ $USE_CCACHE == "1" ]]; then flags+=("-DUSE_CCACHE=1") - if [[ $CCACHE_SIZE ]]; then - # note, this setting persists after running the script + if [[ -n $CCACHE_SIZE ]]; then + # This setting persists after running the script ccache --max-size "$CCACHE_SIZE" fi fi -if [[ $PACKAGE_TYPE ]]; then +if [[ -n $PACKAGE_TYPE ]]; then flags+=("-DCPACK_GENERATOR=$PACKAGE_TYPE") fi -if [[ $USE_VCPKG ]]; then +if [[ $USE_VCPKG == "1" ]]; then flags+=("-DUSE_VCPKG=1") flags+=("-DVCPKG_INSTALL_OPTIONS=--x-abi-tools-use-exact-versions") fi -# Add cmake --build flags +# CMake --build options buildflags=(--config "$BUILDTYPE") function ccachestatsverbose() { - # note, verbose only works on newer ccache, discard the error + ccache --version + # Verbose only works on newer ccache, discard the error local got if got="$(ccache --show-stats --verbose 2>/dev/null)"; then echo "$got" @@ -175,8 +177,8 @@ function ccachestatsverbose() { fi } -# Compile -if [[ $RUNNER_OS == macOS ]]; then +# Prepare compilation +if [[ $RUNNER_OS == "macOS" ]]; then # QTDIR is needed for macOS since we actually only use the cached thin Qt binaries instead of the install-qt-action, # which sets a few environment variables if QTDIR=$(find "$GITHUB_WORKSPACE/Qt" -depth -maxdepth 2 -name macos -type d -print -quit); then @@ -185,42 +187,51 @@ if [[ $RUNNER_OS == macOS ]]; then echo "could not find QTDIR!" exit 2 fi - # the qtdir is located at Qt/[qtversion]/macos - # we use find to get the first subfolder with the name "macos" - # this works independent of the qt version as there should be only one version installed on the runner at a time + # QTDIR is located at Qt//macos + # We use find to get the first subfolder with the name "macos" + # This works independent of the Qt version as there should be only one version installed on the runner at a time export QTDIR - if [[ $TARGET_MACOS_VERSION ]]; then - # CMAKE_OSX_DEPLOYMENT_TARGET is a vanilla cmake flag needed to compile to target macOS version + if [[ -n $TARGET_MACOS_VERSION ]]; then + # CMAKE_OSX_DEPLOYMENT_TARGET is a vanilla CMake option needed to compile to target macOS version flags+=("-DCMAKE_OSX_DEPLOYMENT_TARGET=$TARGET_MACOS_VERSION") - # vcpkg dependencies need a vcpkg triplet file to compile to the target macOS version - # an easy way is to copy the x64-osx.cmake file and modify it - triplets_dir="/tmp/cmake/triplets" - triplet_version="custom-triplet" - triplet_file="$triplets_dir/$triplet_version.cmake" - arch=$(uname -m) - if [[ $arch == x86_64 ]]; then - arch="x64" + if [[ $USE_VCPKG == "1" ]]; then + # vcpkg dependencies need a vcpkg triplet file to compile to the target macOS version + # An easy way is to copy the x64-osx.cmake file and modify it + echo "::group::vcpkg triplet" + triplets_dir="/tmp/cmake/triplets" + triplet_version="custom-triplet" + triplet_file="$triplets_dir/$triplet_version.cmake" + arch=$(uname -m) + + if [[ $arch == x86_64 ]]; then + arch="x64" + fi + + mkdir -p "$triplets_dir" + triplet_source="../vcpkg/triplets/$arch-osx.cmake" + + if [[ ! -f "$triplet_source" ]]; then + triplet_source="../vcpkg/triplets/community/$arch-osx.cmake" + fi + + cp "$triplet_source" "$triplet_file" + echo "set(VCPKG_CMAKE_SYSTEM_VERSION $TARGET_MACOS_VERSION)" >>"$triplet_file" + echo "set(VCPKG_OSX_DEPLOYMENT_TARGET $TARGET_MACOS_VERSION)" >>"$triplet_file" + flags+=("-DVCPKG_OVERLAY_TRIPLETS=$triplets_dir") + flags+=("-DVCPKG_HOST_TRIPLET=$triplet_version") + flags+=("-DVCPKG_TARGET_TRIPLET=$triplet_version") + echo "::endgroup::" + + echo "::group::Generated triplet $triplet_file" + cat "$triplet_file" + echo "::endgroup::" fi - mkdir -p "$triplets_dir" - triplet_source="../vcpkg/triplets/$arch-osx.cmake" - if [[ ! -f "$triplet_source" ]]; then - triplet_source="../vcpkg/triplets/community/$arch-osx.cmake" - fi - cp "$triplet_source" "$triplet_file" - echo "set(VCPKG_CMAKE_SYSTEM_VERSION $TARGET_MACOS_VERSION)" >>"$triplet_file" - echo "set(VCPKG_OSX_DEPLOYMENT_TARGET $TARGET_MACOS_VERSION)" >>"$triplet_file" - flags+=("-DVCPKG_OVERLAY_TRIPLETS=$triplets_dir") - flags+=("-DVCPKG_HOST_TRIPLET=$triplet_version") - flags+=("-DVCPKG_TARGET_TRIPLET=$triplet_version") - echo "::group::Generated triplet $triplet_file" - cat "$triplet_file" - echo "::endgroup::" fi - echo "::group::Signing Certificate" - if [[ -n "$MACOS_CERTIFICATE_NAME" ]]; then + echo "::group::Setup signing certificate" + if [[ -n $MACOS_CERTIFICATE_NAME ]]; then echo "$MACOS_CERTIFICATE" | base64 --decode >"certificate.p12" security create-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain security default-keychain -s build.keychain @@ -234,9 +245,9 @@ if [[ $RUNNER_OS == macOS ]]; then fi echo "::endgroup::" - if [[ $MAKE_PACKAGE ]]; then + if [[ $MAKE_PACKAGE == "1" ]]; then # Workaround https://github.com/actions/runner-images/issues/7522 - # have hdiutil repeat the command 10 times in hope of success + # Have hdiutil repeat the command 10 times in hope of success hdiutil_script="/tmp/hdiutil.sh" # shellcheck disable=SC2016 echo '#!/bin/bash @@ -252,43 +263,46 @@ if [[ $RUNNER_OS == macOS ]]; then flags+=(-DCPACK_COMMAND_HDIUTIL="$hdiutil_script") fi -elif [[ $RUNNER_OS == Windows ]]; then - # Enable MTT, see https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/ +elif [[ $RUNNER_OS == "Windows" ]]; then + # Enable MSBuild switches for MTT, see https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/ # and https://devblogs.microsoft.com/cppblog/cpp-build-throughput-investigation-and-tune-up/#multitooltask-mtt buildflags+=(-- -p:UseMultiToolTask=true -p:EnableClServerMode=true) fi -if [[ $USE_CCACHE ]]; then +if [[ $USE_CCACHE == "1" ]]; then echo "::group::Show ccache stats" ccachestatsverbose echo "::endgroup::" fi -echo "::group::Configure cmake" +# Configure CMake +echo "::group::Generate build system" cmake --version -echo "Running cmake with flags: ${flags[*]}" +echo "Running CMake configuration with following flags: ${flags[*]}" cmake .. "${flags[@]}" echo "::endgroup::" +# Build echo "::group::Build project" -echo "Running cmake --build with flags: ${buildflags[*]}" +echo "Running CMake with following build flags: ${buildflags[*]}" cmake --build . "${buildflags[@]}" echo "::endgroup::" -if [[ $USE_CCACHE ]]; then - if [[ $CCACHE_EVICTION_AGE ]]; then - echo "::group::evict ccache files older than $CCACHE_EVICTION_AGE" +# Post-build +if [[ $USE_CCACHE == "1" ]]; then + if [[ -n $CCACHE_EVICTION_AGE ]]; then + echo "::group::Evict ccache files older than $CCACHE_EVICTION_AGE" ccache --evict-older-than "$CCACHE_EVICTION_AGE" echo "::endgroup::" fi echo "::group::Show ccache stats again" ccachestatsverbose echo "::endgroup::" -elif [[ $CCACHE_EVICTION_AGE ]]; then +elif [[ -n $CCACHE_EVICTION_AGE ]]; then echo "::error file=$0::ccache eviction is enabled while ccache is disabled!" fi -if [[ $RUNNER_OS == macOS ]]; then +if [[ $RUNNER_OS == "macOS" ]]; then echo "::group::Inspect Mach-O binaries" for app in cockatrice oracle servatrice; do binary="$GITHUB_WORKSPACE/build/$app/$app.app/Contents/MacOS/$app" @@ -301,24 +315,29 @@ if [[ $RUNNER_OS == macOS ]]; then echo "::endgroup::" fi -if [[ $MAKE_TEST ]]; then +# Test +if [[ $MAKE_TEST == "1" ]]; then echo "::group::Run tests" + ctest --version ctest -C "$BUILDTYPE" --output-on-failure echo "::endgroup::" fi -if [[ $MAKE_INSTALL ]]; then +# Install +if [[ $MAKE_INSTALL == "1" ]]; then echo "::group::Install" cmake --build . --target install --config "$BUILDTYPE" echo "::endgroup::" fi -if [[ $MAKE_PACKAGE ]]; then +# Package +if [[ $MAKE_PACKAGE == "1" ]]; then echo "::group::Create package" + cpack --version cmake --build . --target package --config "$BUILDTYPE" echo "::endgroup::" - if [[ $PACKAGE_SUFFIX ]]; then + if [[ -n $PACKAGE_SUFFIX ]]; then echo "::group::Update package name" cd .. BUILD_DIR="$BUILD_DIR" .ci/name_build.sh "$PACKAGE_SUFFIX" From 722e8effa21171a5240ffb61440f5eca0acaf33a Mon Sep 17 00:00:00 2001 From: tooomm Date: Sat, 29 Aug 2026 17:20:22 +0200 Subject: [PATCH 02/13] Update check_schema_version.sh --- servatrice/check_schema_version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servatrice/check_schema_version.sh b/servatrice/check_schema_version.sh index c4aadf356..8b645b5d2 100755 --- a/servatrice/check_schema_version.sh +++ b/servatrice/check_schema_version.sh @@ -10,7 +10,7 @@ declare -i schema_ver="${version_line%%)*}" latest_migration="$(ls -1 servatrice/migrations/ | tail -n1)" xtoysql="${latest_migration#servatrice_}" xtoy="${xtoysql%.sql}" -declare -i old_ver="10#${xtoy%_to_*}" #declare as integer with base 10, numbers with a leading 0 are normally interpreted as base 16 +declare -i old_ver="10#${xtoy%_to_*}" # declare as integer with base 10, numbers with a leading 0 are normally interpreted as base 16 declare -i new_ver="10#${xtoy#*_to_}" if ((old_ver >= new_ver)); then From efe7a8234baa83d1dd91430f24b166eb766cfd3b Mon Sep 17 00:00:00 2001 From: tooomm Date: Sat, 29 Aug 2026 19:00:05 +0200 Subject: [PATCH 03/13] Update CMakeLists.txt --- CMakeLists.txt | 173 ++++++++++++++++++++++++++----------------------- 1 file changed, 92 insertions(+), 81 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bac46c2bc..1f98051e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,12 @@ # Cockatrice's main CMakeLists.txt # -# This is basically a wrapper to enable/disable the compilation -# of the different projects: servatrice, cockatrice, test -# This file sets all the variables shared between the projects -# like the installation path, compilation flags etc.. +# This is basically a wrapper to enable/disable the compilation of the different projects: +# Cockatrice, Oracle, Servatrice, Test +# This file sets all the variables shared between the projects like the installation path, compilation flags etc.. -# cmake 3.16 is required if using qt6 +# CMake 3.16 is required if using Qt6 cmake_minimum_required(VERSION 3.10) -# Use compiler cache (ccache) -option(USE_CCACHE "Cache the build results with ccache" OFF) -# Treat warnings as errors (Debug builds only) -option(WARNING_AS_ERROR "Treat warnings as errors in debug builds" ON) -# Check for translation updates -option(UPDATE_TRANSLATIONS "Update translations on compile" OFF) # Compile Cockatrice option(WITH_CLIENT "Build Cockatrice client" ON) # Compile Oracle @@ -22,15 +15,21 @@ option(WITH_ORACLE "Build Cockatrice card database tool (Oracle)" ON) option(WITH_SERVER "Build Cockatrice server (Servatrice)" OFF) # Compile tests option(TEST "Build tests" OFF) +# Treat warnings as errors (Debug builds only) +option(WARNING_AS_ERROR "Treat warnings as errors in debug builds" ON) +# Check for translation updates +option(UPDATE_TRANSLATIONS "Update translations on compile" OFF) # Use vcpkg regardless of OS option(USE_VCPKG "Use vcpkg regardless of OS" OFF) +# Use compiler cache (ccache) +option(USE_CCACHE "Cache the build results with ccache" OFF) # Default to "Release" build type # User-provided value for CMAKE_BUILD_TYPE must be checked before the PROJECT() call -if(DEFINED CMAKE_BUILD_TYPE) +if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE - ${CMAKE_BUILD_TYPE} - CACHE STRING "Type of build" + Release + CACHE STRING "Build type" ) else() set(CMAKE_BUILD_TYPE @@ -77,22 +76,23 @@ endif() # Version can be overriden by git tags, see cmake/getversion.cmake project("Cockatrice" VERSION 3.1.0) -# Set release name if not provided via env/cmake var +# Set release name if not provided via ENV/CMake var if(NOT DEFINED GIT_TAG_RELEASENAME) set(GIT_TAG_RELEASENAME "Graduation Day") endif() -# Use c++20 for all targets +# Use C++20 for all targets set(CMAKE_CXX_STANDARD 20 CACHE STRING "C++ ISO Standard" ) set(CMAKE_CXX_STANDARD_REQUIRED True) +set(CMAKE_CXX_EXTENSIONS OFF) # Set conventional loops set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) -# Search path for cmake modules +# Search path for CMake modules set(COCKATRICE_CMAKE_PATH "${PROJECT_SOURCE_DIR}/cmake") list(INSERT CMAKE_MODULE_PATH 0 "${COCKATRICE_CMAKE_PATH}") @@ -103,31 +103,31 @@ include(createversionfile) # Define a proper install path if(UNIX) - if(APPLE) - # macOS - # Due to the special bundle structure ignore - # the prefix eventually set by the user. + if(APPLE) # macOS + # Due to the special bundle structure ignore the prefix eventually set by the user set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/release) # Force ccache usage if available - get_property(RULE_LAUNCH_COMPILE GLOBAL PROPERTY RULE_LAUNCH_COMPILE) - if(RULE_LAUNCH_COMPILE) - message(STATUS "Force enabling CCache usage under macOS") - # Set up wrapper scripts - configure_file("${COCKATRICE_CMAKE_PATH}/launch-c.in" launch-c) - configure_file("${COCKATRICE_CMAKE_PATH}/launch-cxx.in" launch-cxx) - execute_process(COMMAND chmod a+rx "${CMAKE_BINARY_DIR}/launch-c" "${CMAKE_BINARY_DIR}/launch-cxx") + if(USE_CCACHE) + get_property(RULE_LAUNCH_COMPILE GLOBAL PROPERTY RULE_LAUNCH_COMPILE) + if(RULE_LAUNCH_COMPILE) + message(STATUS "Force enabling ccache usage") - # Set Xcode project attributes to route compilation through our scripts - set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/launch-c") - set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/launch-cxx") - set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/launch-c") - set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/launch-cxx") + # Set up wrapper scripts + configure_file("${COCKATRICE_CMAKE_PATH}/launch-c.in" launch-c) + configure_file("${COCKATRICE_CMAKE_PATH}/launch-cxx.in" launch-cxx) + execute_process(COMMAND chmod a+rx "${CMAKE_BINARY_DIR}/launch-c" "${CMAKE_BINARY_DIR}/launch-cxx") + + # Set Xcode project attributes to route compilation through our scripts + set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/launch-c") + set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/launch-cxx") + set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/launch-c") + set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/launch-cxx") + endif() endif() - else() - # Linux / BSD + else() # Linux / BSD if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - #fix package build + # Fix package build if(PREFIX) set(CMAKE_INSTALL_PREFIX ${PREFIX}) else() @@ -135,36 +135,45 @@ if(UNIX) endif() endif() endif() -elseif(WIN32) +elseif(WIN32) # Windows (including 64bit) set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/rundir/${CMAKE_BUILD_TYPE}) endif() # Define proper compilation flags -if(MSVC) - # Disable Warning C4251, C++20 compatibility, Multi-threaded Builds, Warn Detection, Unwind Semantics, Debug Symbols - set(CMAKE_CXX_FLAGS "/wd4251 /Zc:__cplusplus /std:c++20 /permissive- /W4 /MP /EHsc /Zi") - # Visual Studio: Maximum Optimization, Multi-threaded DLL +if(MSVC) # MS Visual C++ compiler + # /EHsc Enable standard C++ exception handling + # /MP Enable parallel compilation + # /wd4251 Suppress C4251 (DLL interface) warnings + # /W4 Enable warning level 4 + # /Zi Generate debugging information (Program Database, PDB) + set(CMAKE_CXX_FLAGS "/EHsc /MP /wd4251 /W4 /Zi") + + # /Ox Enable maximum optimization + # /MD Link against the multi-threaded DLL runtime library (Release CRT) set(CMAKE_CXX_FLAGS_RELEASE "/Ox /MD") - # Visual Studio: No Optimization, Multi-threaded Debug DLL + + # /Od Disable optimization + # /MDd Link against the multi-threaded Debug DLL runtime library (Debug CRT) set(CMAKE_CXX_FLAGS_DEBUG "/Od /MDd") - # Generate PDB, even when in release (So developers can better analyze crash logs) + # Generate PDBs, even when building release target to allow developers to better analyze crash logs set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") add_compile_definitions(_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING) -elseif(CMAKE_COMPILER_IS_GNUCXX) - # linux/gcc, bsd/gcc, windows/mingw + +elseif(CMAKE_COMPILER_IS_GNUCXX) # Linux/GCC, BSD/GCC, Windows/MinGW include(CheckCXXCompilerFlag) set(CMAKE_CXX_FLAGS_RELEASE "-s -O2") + if(WARNING_AS_ERROR) set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0 -Wall -Wextra -Werror") else() set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0 -Wall -Wextra") endif() - if(APPLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++20") + if(APPLE) # macOS + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++20") # still needed? endif() set(ADDITIONAL_DEBUG_FLAGS @@ -175,7 +184,7 @@ elseif(CMAKE_COMPILER_IS_GNUCXX) -Wno-error=delete-non-virtual-dtor -Wno-error=sign-compare -Wno-error=missing-declarations - -Wno-error=sfinae-incomplete # GCC 16+: Qt MOC + protobuf forward decls trigger this + -Wno-error=sfinae-incomplete # GCC 16+: Qt MOC + protobuf forward declarations trigger this ) foreach(FLAG ${ADDITIONAL_DEBUG_FLAGS}) @@ -184,8 +193,7 @@ elseif(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}") endif() endforeach() -else() - # other: osx/llvm, bsd/llvm +else() # Other: macOS/LLVM, BSD/LLVM set(CMAKE_CXX_FLAGS_RELEASE "-O2") if(WARNING_AS_ERROR) set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wextra -Werror -Wno-unused-parameter") @@ -194,7 +202,7 @@ else() endif() endif() -# GNU systems need to define the Mersenne exponent for the RNG to compile w/o warning +# GNU systems need to define the Mersenne Exponent for SFMT for the RNG to compile without warning if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") add_definitions("-DSFMT_MEXP=19937") endif() @@ -203,9 +211,9 @@ find_package(Threads REQUIRED) # Determine 32 or 64 bit build if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(_lib_suffix 64) + set(_lib_suffix 64) # 64bit else() - set(_lib_suffix 32) + set(_lib_suffix 32) # 32bit endif() if(DEFINED QTDIR${_lib_suffix}) @@ -234,8 +242,8 @@ if(${Protobuf_VERSION} VERSION_LESS "3.21.0.0" AND NOT EXISTS "${Protobuf_PROTOC message(FATAL_ERROR "No protoc command found!") endif() -#Find OpenSSL -if(WIN32) +# Find OpenSSL +if(WIN32) # Windows (including 64bit) find_package(OpenSSL REQUIRED) if(OPENSSL_FOUND) include_directories(${OPENSSL_INCLUDE_DIRS}) @@ -247,8 +255,8 @@ if(WIN32) endif() endif() -#Find VCredist -if(MSVC) +# Find Visual C++ Redistributable +if(MSVC) # MS Visual C++ compiler find_package(VCredistRuntime) endif() @@ -257,7 +265,9 @@ set(CPACK_PACKAGE_CONTACT "Zach Halpern ") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_NAME}") set(CPACK_PACKAGE_VENDOR "Cockatrice Development Team") set(CPACK_PACKAGE_DESCRIPTION - "Cockatrice is an open-source, multiplatform application for playing tabletop card games over a network. The program's server design prevents users from manipulating the game for unfair advantage. The client also provides a single-player mode, which allows users to brew while offline." + "Cockatrice is an open-source, multiplatform application for playing tabletop card games over a network. \ + The program's server design prevents users from manipulating the game for unfair advantage. \ + The client also provides a single-player mode, which allows users to brew while offline." ) set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE") set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") @@ -266,7 +276,7 @@ set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") set(CPACK_PACKAGE_FILE_NAME "${PROJECT_VERSION_FILENAME}") if(UNIX) - if(APPLE) + if(APPLE) # macOS set(CPACK_GENERATOR DragNDrop ${CPACK_GENERATOR}) set(CPACK_GENERATOR "DragNDrop") set(CPACK_DMG_FORMAT "UDBZ") @@ -276,15 +286,14 @@ if(UNIX) set(CPACK_DMG_DS_STORE_SETUP_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeDMGSetup.script") set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/dmgBackground.tif") set(CPACK_PRE_BUILD_SCRIPTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignMacApplications.cmake") - else() - # linux + else() # Linux if(CPACK_GENERATOR STREQUAL "RPM") set(CPACK_RPM_PACKAGE_LICENSE "GPLv2") set(CPACK_RPM_MAIN_COMPONENT "cockatrice") set(CPACK_RPM_PACKAGE_REQUIRES "protobuf, qt6-qttools, qt6-qtsvg, qt6-qtmultimedia, qt6-qtimageformats") set(CPACK_RPM_PACKAGE_GROUP "Amusements/Games") set(CPACK_RPM_PACKAGE_URL "http://github.com/Cockatrice/Cockatrice") - # stop directories from making package conflicts + # Stop directories from creating package conflicts set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /usr/share/applications /usr/share/icons @@ -300,21 +309,21 @@ if(UNIX) set(CPACK_DEBIAN_PACKAGE_SECTION "games") set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://github.com/Cockatrice/Cockatrice") set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt6multimedia6, libqt6svg6, qt6-qpa-plugins, qt6-image-formats-plugins") - set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libqt6sql6-mysql") # for connecting servatrice to a mysql db + set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libqt6sql6-mysql") # for connecting Servatrice to a MySQL DB endif() endif() -elseif(WIN32) +elseif(WIN32) # Windows (including 64bit) set(CPACK_GENERATOR NSIS ${CPACK_GENERATOR}) - if("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(x64)") - set(TRICE_IS_64_BIT 1) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(TRICE_IS_64_BIT 1) # 64bit else() - set(TRICE_IS_64_BIT 0) + set(TRICE_IS_64_BIT 0) # 32bit endif() - # Configure file with custom definitions for NSIS. + # Configure file with custom definitions for NSIS configure_file("${COCKATRICE_CMAKE_PATH}/NSIS.definitions.nsh.in" "${PROJECT_BINARY_DIR}/NSIS.definitions.nsh") - # include vcredist into the package; NSIS will take care of running it + # Include vcredist into the package; NSIS will take care of running it if(VCREDISTRUNTIME_FOUND) install(FILES "${VCREDISTRUNTIME_FILE}" DESTINATION ./) endif() @@ -322,29 +331,26 @@ endif() include(CPack) +add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_card ${CMAKE_BINARY_DIR}/libcockatrice_card) +add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_deck_list ${CMAKE_BINARY_DIR}/libcockatrice_deck_list) add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_interfaces ${CMAKE_BINARY_DIR}/libcockatrice_interfaces) add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_protocol ${CMAKE_BINARY_DIR}/libcockatrice_protocol) +add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_rng ${CMAKE_BINARY_DIR}/libcockatrice_rng) +add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_utility ${CMAKE_BINARY_DIR}/libcockatrice_utility) + if(WITH_CLIENT - OR WITH_SERVER OR WITH_ORACLE + OR WITH_SERVER ) add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_network ${CMAKE_BINARY_DIR}/libcockatrice_network) endif() -add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_deck_list ${CMAKE_BINARY_DIR}/libcockatrice_deck_list) -add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_rng ${CMAKE_BINARY_DIR}/libcockatrice_rng) -add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_card ${CMAKE_BINARY_DIR}/libcockatrice_card) -add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_utility ${CMAKE_BINARY_DIR}/libcockatrice_utility) -if(WITH_ORACLE OR WITH_CLIENT) + +if(WITH_CLIENT OR WITH_ORACLE) add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_settings ${CMAKE_BINARY_DIR}/libcockatrice_settings) add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_models ${CMAKE_BINARY_DIR}/libcockatrice_models) add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_filters ${CMAKE_BINARY_DIR}/libcockatrice_filters) endif() -if(WITH_SERVER) - add_subdirectory(servatrice) - set(CPACK_INSTALL_CMAKE_PROJECTS "Servatrice;Servatrice;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS}) -endif() - if(WITH_CLIENT) add_subdirectory(cockatrice) set(CPACK_INSTALL_CMAKE_PROJECTS "Cockatrice;Cockatrice;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS}) @@ -355,12 +361,17 @@ if(WITH_ORACLE) set(CPACK_INSTALL_CMAKE_PROJECTS "Oracle;Oracle;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS}) endif() +if(WITH_SERVER) + add_subdirectory(servatrice) + set(CPACK_INSTALL_CMAKE_PROJECTS "Servatrice;Servatrice;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS}) +endif() + if(TEST) include(CTest) add_subdirectory(tests) endif() if(Qt6_FOUND AND Qt6_VERSION_MINOR GREATER_EQUAL 3) - # Qt6.3+ requires project finalization to support translations + # Qt 6.3+ requires project finalization to support translations qt6_finalize_project() endif() From 88b1d753c6ecb4adb8127386ecdbed55df5e401b Mon Sep 17 00:00:00 2001 From: tooomm Date: Sat, 29 Aug 2026 19:08:30 +0200 Subject: [PATCH 04/13] Update tests/CMakeLists.txt --- tests/CMakeLists.txt | 59 ++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 34784538b..3563f8434 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,38 +3,49 @@ enable_testing() add_test(NAME dummy_test COMMAND dummy_test) -add_test(NAME expression_test COMMAND expression_test) +add_executable(dummy_test dummy_test.cpp) +# Add timeout to prevent hanging if there is any issue with the general GTest setup +set_tests_properties(dummy_test PROPERTIES TIMEOUT 5) + add_test(NAME clamped_arithmetic_test COMMAND clamped_arithmetic_test) -add_test(NAME test_age_formatting COMMAND test_age_formatting) -add_test(NAME password_hash_test COMMAND password_hash_test) -add_test(NAME playmat_resolver_test COMMAND playmat_resolver_test) -add_test(NAME server_card_counter_test COMMAND server_card_counter_test) -add_test(NAME server_counter_test COMMAND server_counter_test) -add_test(NAME server_rate_limiter_test COMMAND server_rate_limiter_test) -add_test(NAME warning_categories_test COMMAND warning_categories_test) -add_test(NAME lag_monitor_test COMMAND lag_monitor_test) -add_test(NAME latency_tracker_test COMMAND latency_tracker_test) +add_executable(clamped_arithmetic_test clamped_arithmetic_test.cpp) add_test(NAME deck_hash_performance_test COMMAND deck_hash_performance_test) -set_tests_properties(deck_hash_performance_test PROPERTIES TIMEOUT 15) - -# Find GTest - -add_executable(dummy_test dummy_test.cpp) -add_executable(expression_test expression_test.cpp) -add_executable(clamped_arithmetic_test clamped_arithmetic_test.cpp) -add_executable(test_age_formatting test_age_formatting.cpp) -add_executable(password_hash_test password_hash_test.cpp) -add_executable(playmat_resolver_test playmat_resolver_test.cpp) add_executable(deck_hash_performance_test deck_hash_performance_test.cpp) -add_executable(server_card_counter_test server_card_counter_test.cpp) -add_executable(server_counter_test server_counter_test.cpp) -add_executable(server_rate_limiter_test server_rate_limiter_test.cpp) -add_executable(warning_categories_test warning_categories_test.cpp) +set_tests_properties(deck_hash_performance_test PROPERTIES TIMEOUT 10) + +add_test(NAME expression_test COMMAND expression_test) +add_executable(expression_test expression_test.cpp) + +add_test(NAME lag_monitor_test COMMAND lag_monitor_test) add_executable(lag_monitor_test ${CMAKE_SOURCE_DIR}/cockatrice/src/client/lag_monitor.cpp lag_monitor_test.cpp) target_include_directories(lag_monitor_test PRIVATE ${CMAKE_SOURCE_DIR}/cockatrice/src) + +add_test(NAME latency_tracker_test COMMAND latency_tracker_test) add_executable(latency_tracker_test latency_tracker_test.cpp) +add_test(NAME password_hash_test COMMAND password_hash_test) +add_executable(password_hash_test password_hash_test.cpp) + +add_test(NAME playmat_resolver_test COMMAND playmat_resolver_test) +add_executable(playmat_resolver_test playmat_resolver_test.cpp) + +add_test(NAME server_card_counter_test COMMAND server_card_counter_test) +add_executable(server_card_counter_test server_card_counter_test.cpp) + +add_test(NAME server_counter_test COMMAND server_counter_test) +add_executable(server_counter_test server_counter_test.cpp) + +add_test(NAME server_rate_limiter_test COMMAND server_rate_limiter_test) +add_executable(server_rate_limiter_test server_rate_limiter_test.cpp) + +add_test(NAME test_age_formatting COMMAND test_age_formatting) +add_executable(test_age_formatting test_age_formatting.cpp) + +add_test(NAME warning_categories_test COMMAND warning_categories_test) +add_executable(warning_categories_test warning_categories_test.cpp) + +# Find GTest find_package(GTest) if(NOT GTEST_FOUND) From 7b452b923f6f308219f5f920558af62424794646 Mon Sep 17 00:00:00 2001 From: tooomm Date: Sat, 29 Aug 2026 23:15:56 +0200 Subject: [PATCH 05/13] Update desktop-build.yml --- .github/workflows/desktop-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml index 04037a74e..3ad86b66f 100644 --- a/.github/workflows/desktop-build.yml +++ b/.github/workflows/desktop-build.yml @@ -419,7 +419,7 @@ jobs: - name: "[Windows] Install NSIS" if: matrix.os == 'Windows' shell: bash - run: choco install nsis + run: choco install nsis --no-progress - name: "Setup vcpkg cache" id: vcpkg-cache From fa0d954afaaae4e564fd843efdcddfa1e109c1ff Mon Sep 17 00:00:00 2001 From: tooomm Date: Sat, 29 Aug 2026 23:14:54 +0200 Subject: [PATCH 06/13] Enable verbose compilation logging --- .ci/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index ef0a3faef..0d65f9652 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -285,7 +285,7 @@ echo "::endgroup::" # Build echo "::group::Build project" echo "Running CMake with following build flags: ${buildflags[*]}" -cmake --build . "${buildflags[@]}" +cmake --build . --verbose "${buildflags[@]}" echo "::endgroup::" # Post-build From 8990b6103f41e830e7bce45ac6acad8eda323c05 Mon Sep 17 00:00:00 2001 From: tooomm Date: Sun, 30 Aug 2026 02:17:42 +0200 Subject: [PATCH 07/13] Remove dedicated macOS gnu++20 flag --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f98051e7..3a70f1d04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,10 +172,6 @@ elseif(CMAKE_COMPILER_IS_GNUCXX) # Linux/GCC, BSD/GCC, Windows/MinGW set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0 -Wall -Wextra") endif() - if(APPLE) # macOS - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++20") # still needed? - endif() - set(ADDITIONAL_DEBUG_FLAGS -Wcast-align -Wmissing-declarations From 5d2fff5a54b95bcb65b156b45487aa25c753cc80 Mon Sep 17 00:00:00 2001 From: tooomm Date: Sun, 30 Aug 2026 23:48:35 +0200 Subject: [PATCH 08/13] adjust compiler flags + comment them --- CMakeLists.txt | 85 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a70f1d04..e9808a236 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,16 +13,17 @@ option(WITH_CLIENT "Build Cockatrice client" ON) option(WITH_ORACLE "Build Cockatrice card database tool (Oracle)" ON) # Compile Servatrice option(WITH_SERVER "Build Cockatrice server (Servatrice)" OFF) -# Compile tests +# Compile Tests option(TEST "Build tests" OFF) -# Treat warnings as errors (Debug builds only) -option(WARNING_AS_ERROR "Treat warnings as errors in debug builds" ON) + # Check for translation updates option(UPDATE_TRANSLATIONS "Update translations on compile" OFF) # Use vcpkg regardless of OS option(USE_VCPKG "Use vcpkg regardless of OS" OFF) # Use compiler cache (ccache) option(USE_CCACHE "Cache the build results with ccache" OFF) +# Treat warnings as errors (Debug builds only) +option(WARNING_AS_ERROR "Treat warnings as errors in debug builds" ON) # Default to "Release" build type # User-provided value for CMAKE_BUILD_TYPE must be checked before the PROJECT() call @@ -89,6 +90,9 @@ set(CMAKE_CXX_STANDARD set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_EXTENSIONS OFF) +# try target_compile_features(cockatrice PRIVATE cxx_std_20) +# -fexperimental-library for gcc/clang, libstdc++, gate with compiler_is_gnucxx or cxx_compiler_id matches clang + # Set conventional loops set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) @@ -139,48 +143,65 @@ elseif(WIN32) # Windows (including 64bit) set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/rundir/${CMAKE_BUILD_TYPE}) endif() -# Define proper compilation flags +# Define compiler flags if(MSVC) # MS Visual C++ compiler - # /EHsc Enable standard C++ exception handling - # /MP Enable parallel compilation - # /wd4251 Suppress C4251 (DLL interface) warnings - # /W4 Enable warning level 4 - # /Zi Generate debugging information (Program Database, PDB) - set(CMAKE_CXX_FLAGS "/EHsc /MP /wd4251 /W4 /Zi") + # /EHsc Enable standard C++ exception handling + # /MP Enable parallel compilation + # /permissive- Enable strict standards compliance + # /utf-8 Set source file encoding and execution char set to UTF-8 + # /wd4251 Suppress C4251 (DLL interface) warnings around DLL exports <-- removed to see how Qt6 handles it + # /W4 Enable warning level 4 + # /Zc:__cplusplus Enable C++20 detection in headers + # /Zi Generate debugging information (Program Database, PDB) + set(CMAKE_CXX_FLAGS "/EHsc /MP /permissive- /utf-8 /W4 /Zc:__cplusplus /Zi") - # /Ox Enable maximum optimization - # /MD Link against the multi-threaded DLL runtime library (Release CRT) + # /Ox Enable maximum optimization + # /MD Link against the multi-threaded DLL runtime library (Release CRT) set(CMAKE_CXX_FLAGS_RELEASE "/Ox /MD") - # /Od Disable optimization - # /MDd Link against the multi-threaded Debug DLL runtime library (Debug CRT) + # /Od Disable optimization + # /MDd Link against the multi-threaded Debug DLL runtime library (Debug CRT) set(CMAKE_CXX_FLAGS_DEBUG "/Od /MDd") # Generate PDBs, even when building release target to allow developers to better analyze crash logs + # /DEBUG Enable PDB generation also for Release builds + # /OPT:REF Remove unused references + # /OPT:ICF Fold identical code set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") - add_compile_definitions(_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING) + add_compile_definitions(_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING) # check if this is still needed with C++20 elseif(CMAKE_COMPILER_IS_GNUCXX) # Linux/GCC, BSD/GCC, Windows/MinGW include(CheckCXXCompilerFlag) - set(CMAKE_CXX_FLAGS_RELEASE "-s -O2") + # -O2 Balanced optimization + # -s Remove debug info from the binary (strip symbols) + set(CMAKE_CXX_FLAGS_RELEASE "-O2 -s") + # -ggdb Produce GDB debugging symbols + # -O0 No optimization + # -Wall Enable all warnings + # -Wextra Enable extra warnings + # -Werror Treat warnings as compilation errors if(WARNING_AS_ERROR) set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0 -Wall -Wextra -Werror") else() set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0 -Wall -Wextra") endif() + # -std=gnu++20 Enable GNU C++20 extensions + if(APPLE) # macOS/GCC + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++20") + endif() + set(ADDITIONAL_DEBUG_FLAGS - -Wcast-align - -Wmissing-declarations - -Wno-long-long - -Wno-error=extra - -Wno-error=delete-non-virtual-dtor - -Wno-error=sign-compare - -Wno-error=missing-declarations - -Wno-error=sfinae-incomplete # GCC 16+: Qt MOC + protobuf forward declarations trigger this + -Wcast-align # Catch unsafe pointer casts + -Wmissing-declarations # Catch defined functions without prior declaration + -Wno-error=extra # Downgrade some -Wextra warnings from errors to warnings + -Wno-error=delete-non-virtual-dtor # <-- see if still needed? + -Wno-error=sign-compare # Downgrade comparing signed vs. unsigned integers from errors to warnings + -Wno-error=missing-declarations # Downgrade -Wmissing-declarations from errors to warnings + -Wno-error=sfinae-incomplete # GCC 16+: Qt MOC + protobuf forward declarations trigger this ) foreach(FLAG ${ADDITIONAL_DEBUG_FLAGS}) @@ -189,8 +210,16 @@ elseif(CMAKE_COMPILER_IS_GNUCXX) # Linux/GCC, BSD/GCC, Windows/MinGW set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}") endif() endforeach() -else() # Other: macOS/LLVM, BSD/LLVM +else() # Other: macOS/LLVM, BSD/LLVM, "Clang-specific" + # -O2 Balanced optimization set(CMAKE_CXX_FLAGS_RELEASE "-O2") + + # -g Include debug information (equivalent to -ggdb for GCC) + # -O0 No optimization + # -Wall Enable all warnings + # -Wextra Enable extra warnings + # -Werror Treat warnings as compiler errors + # -Wno-unused-parameter Suppress warnings about unused function parameters (common in Qt callbacks) if(WARNING_AS_ERROR) set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wextra -Werror -Wno-unused-parameter") else() @@ -319,7 +348,7 @@ elseif(WIN32) # Windows (including 64bit) # Configure file with custom definitions for NSIS configure_file("${COCKATRICE_CMAKE_PATH}/NSIS.definitions.nsh.in" "${PROJECT_BINARY_DIR}/NSIS.definitions.nsh") - # Include vcredist into the package; NSIS will take care of running it + # Include vcredist into the package - NSIS will take care of running it if(VCREDISTRUNTIME_FOUND) install(FILES "${VCREDISTRUNTIME_FILE}" DESTINATION ./) endif() @@ -342,9 +371,9 @@ if(WITH_CLIENT endif() if(WITH_CLIENT OR WITH_ORACLE) - add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_settings ${CMAKE_BINARY_DIR}/libcockatrice_settings) - add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_models ${CMAKE_BINARY_DIR}/libcockatrice_models) add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_filters ${CMAKE_BINARY_DIR}/libcockatrice_filters) + add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_models ${CMAKE_BINARY_DIR}/libcockatrice_models) + add_subdirectory(${CMAKE_SOURCE_DIR}/libcockatrice_settings ${CMAKE_BINARY_DIR}/libcockatrice_settings) endif() if(WITH_CLIENT) From aa330f6a5948e8f1a3b03491e30eba9afdeab5cd Mon Sep 17 00:00:00 2001 From: tooomm Date: Mon, 31 Aug 2026 12:12:48 +0200 Subject: [PATCH 09/13] format --- CMakeLists.txt | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e9808a236..f6a6ca586 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,14 +194,21 @@ elseif(CMAKE_COMPILER_IS_GNUCXX) # Linux/GCC, BSD/GCC, Windows/MinGW set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++20") endif() + # -Wcast-align Catch unsafe pointer casts + # -Wmissing-declarations Catch defined functions without prior declaration + # -Wno-error=extra Downgrade some -Wextra warnings from errors to warnings + # -Wno-error=delete-non-virtual-dtor <-- see if still needed? + # -Wno-error=sign-compare Downgrade comparing signed vs. unsigned integers from errors to warnings + # -Wno-error=missing-declarations Downgrade -Wmissing-declarations from errors to warnings + # -Wno-error=sfinae-incomplete GCC 16+: Qt MOC + protobuf forward declarations trigger this set(ADDITIONAL_DEBUG_FLAGS - -Wcast-align # Catch unsafe pointer casts - -Wmissing-declarations # Catch defined functions without prior declaration - -Wno-error=extra # Downgrade some -Wextra warnings from errors to warnings - -Wno-error=delete-non-virtual-dtor # <-- see if still needed? - -Wno-error=sign-compare # Downgrade comparing signed vs. unsigned integers from errors to warnings - -Wno-error=missing-declarations # Downgrade -Wmissing-declarations from errors to warnings - -Wno-error=sfinae-incomplete # GCC 16+: Qt MOC + protobuf forward declarations trigger this + -Wcast-align + -Wmissing-declarations + -Wno-error=extra + -Wno-error=delete-non-virtual-dtor + -Wno-error=sign-compare + -Wno-error=missing-declarations + -Wno-error=sfinae-incomplete ) foreach(FLAG ${ADDITIONAL_DEBUG_FLAGS}) From 49170d1af463e92fcac4a749ea6b31fee7c73014 Mon Sep 17 00:00:00 2001 From: tooomm Date: Mon, 31 Aug 2026 12:28:39 +0200 Subject: [PATCH 10/13] clenaup --- CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6a6ca586..273e3fe21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,7 +149,6 @@ if(MSVC) # MS Visual C++ compiler # /MP Enable parallel compilation # /permissive- Enable strict standards compliance # /utf-8 Set source file encoding and execution char set to UTF-8 - # /wd4251 Suppress C4251 (DLL interface) warnings around DLL exports <-- removed to see how Qt6 handles it # /W4 Enable warning level 4 # /Zc:__cplusplus Enable C++20 detection in headers # /Zi Generate debugging information (Program Database, PDB) @@ -169,8 +168,6 @@ if(MSVC) # MS Visual C++ compiler # /OPT:ICF Fold identical code set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") - add_compile_definitions(_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING) # check if this is still needed with C++20 - elseif(CMAKE_COMPILER_IS_GNUCXX) # Linux/GCC, BSD/GCC, Windows/MinGW include(CheckCXXCompilerFlag) From a79be1ca12ab1f9b1e89b69d218d0b2b2409709c Mon Sep 17 00:00:00 2001 From: tooomm Date: Sun, 6 Sep 2026 11:28:44 +0200 Subject: [PATCH 11/13] cleanup --- CMakeLists.txt | 89 ++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 273e3fe21..630b77eda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,11 +32,6 @@ if(NOT CMAKE_BUILD_TYPE) Release CACHE STRING "Build type" ) -else() - set(CMAKE_BUILD_TYPE - Release - CACHE STRING "Type of build" - ) endif() if(USE_CCACHE) @@ -82,19 +77,13 @@ if(NOT DEFINED GIT_TAG_RELEASENAME) set(GIT_TAG_RELEASENAME "Graduation Day") endif() -# Use C++20 for all targets -set(CMAKE_CXX_STANDARD - 20 - CACHE STRING "C++ ISO Standard" -) -set(CMAKE_CXX_STANDARD_REQUIRED True) +# Requires ISO C++20 standard (without compiler-specific extensions) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -# try target_compile_features(cockatrice PRIVATE cxx_std_20) -# -fexperimental-library for gcc/clang, libstdc++, gate with compiler_is_gnucxx or cxx_compiler_id matches clang - # Set conventional loops -set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) +set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) # Search path for CMake modules set(COCKATRICE_CMAKE_PATH "${PROJECT_SOURCE_DIR}/cmake") @@ -144,41 +133,41 @@ elseif(WIN32) # Windows (including 64bit) endif() # Define compiler flags -if(MSVC) # MS Visual C++ compiler +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # MS Visual C++ compiler # /EHsc Enable standard C++ exception handling # /MP Enable parallel compilation - # /permissive- Enable strict standards compliance + # /permissive- Enable more standards-conforming behavior # /utf-8 Set source file encoding and execution char set to UTF-8 # /W4 Enable warning level 4 # /Zc:__cplusplus Enable C++20 detection in headers # /Zi Generate debugging information (Program Database, PDB) set(CMAKE_CXX_FLAGS "/EHsc /MP /permissive- /utf-8 /W4 /Zc:__cplusplus /Zi") - # /Ox Enable maximum optimization + # /O2 Balanced optimization # /MD Link against the multi-threaded DLL runtime library (Release CRT) - set(CMAKE_CXX_FLAGS_RELEASE "/Ox /MD") + set(CMAKE_CXX_FLAGS_RELEASE "/O2 /MD") # /Od Disable optimization # /MDd Link against the multi-threaded Debug DLL runtime library (Debug CRT) set(CMAKE_CXX_FLAGS_DEBUG "/Od /MDd") # Generate PDBs, even when building release target to allow developers to better analyze crash logs - # /DEBUG Enable PDB generation also for Release builds - # /OPT:REF Remove unused references - # /OPT:ICF Fold identical code + # /DEBUG Enable debug symbols and PDB generation + # /OPT:REF Remove unreferenced functions/data + # /OPT:ICF Fold identical COMDAT functions/data set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") -elseif(CMAKE_COMPILER_IS_GNUCXX) # Linux/GCC, BSD/GCC, Windows/MinGW +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # GCC compiler include(CheckCXXCompilerFlag) # -O2 Balanced optimization - # -s Remove debug info from the binary (strip symbols) + # -s Remove symbols from the executable <-- do we want that? we add symbols to windows builds explicitly. Check pdb's and how debug symbols work & can be striped during packaging // non-gcc & clang section also does not have it set(CMAKE_CXX_FLAGS_RELEASE "-O2 -s") # -ggdb Produce GDB debugging symbols - # -O0 No optimization - # -Wall Enable all warnings - # -Wextra Enable extra warnings + # -O0 Disable optimization + # -Wall Enable broad set of useful warnings + # -Wextra Enable set of extra warnings # -Werror Treat warnings as compilation errors if(WARNING_AS_ERROR) set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0 -Wall -Wextra -Werror") @@ -186,26 +175,27 @@ elseif(CMAKE_COMPILER_IS_GNUCXX) # Linux/GCC, BSD/GCC, Windows/MinGW set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0 -Wall -Wextra") endif() + # Test without, CMAKE_CXX-ESTENSIONS are defined as OFF, so no sense to add them here but not turning the general setting ON? # -std=gnu++20 Enable GNU C++20 extensions - if(APPLE) # macOS/GCC - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++20") - endif() + # if(APPLE) # macOS/GCC + # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++20") + # endif() # -Wcast-align Catch unsafe pointer casts # -Wmissing-declarations Catch defined functions without prior declaration # -Wno-error=extra Downgrade some -Wextra warnings from errors to warnings - # -Wno-error=delete-non-virtual-dtor <-- see if still needed? + # -Wno-error=delete-non-virtual-dtor xxx # -Wno-error=sign-compare Downgrade comparing signed vs. unsigned integers from errors to warnings # -Wno-error=missing-declarations Downgrade -Wmissing-declarations from errors to warnings # -Wno-error=sfinae-incomplete GCC 16+: Qt MOC + protobuf forward declarations trigger this set(ADDITIONAL_DEBUG_FLAGS -Wcast-align -Wmissing-declarations - -Wno-error=extra - -Wno-error=delete-non-virtual-dtor - -Wno-error=sign-compare - -Wno-error=missing-declarations - -Wno-error=sfinae-incomplete + -Wno-error=extra # <-- consider removing this, check without as it makes most of added -Wextra warnings non-fatal + -Wno-error=delete-non-virtual-dtor # <-- see if still needed? + -Wno-error=sign-compare # <-- test without + -Wno-error=missing-declarations # <-- test without + -Wno-error=sfinae-incomplete # <-- test again without and see if comment still holds true ) foreach(FLAG ${ADDITIONAL_DEBUG_FLAGS}) @@ -214,26 +204,34 @@ elseif(CMAKE_COMPILER_IS_GNUCXX) # Linux/GCC, BSD/GCC, Windows/MinGW set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}") endif() endforeach() -else() # Other: macOS/LLVM, BSD/LLVM, "Clang-specific" + +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Clang compiler # -O2 Balanced optimization set(CMAKE_CXX_FLAGS_RELEASE "-O2") # -g Include debug information (equivalent to -ggdb for GCC) - # -O0 No optimization - # -Wall Enable all warnings - # -Wextra Enable extra warnings - # -Werror Treat warnings as compiler errors + # -O0 Disable optimization + # -Wall Enable broad set of useful warnings + # -Wextra Enable set of extra warnings + # -Werror Treat warnings as compilation errors # -Wno-unused-parameter Suppress warnings about unused function parameters (common in Qt callbacks) if(WARNING_AS_ERROR) set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wextra -Werror -Wno-unused-parameter") else() set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wextra") endif() + +else() # Undefined compiler + message(WARNING + "Unknown C++ compiler: ${CMAKE_CXX_COMPILER_ID}" + ) + endif() # GNU systems need to define the Mersenne Exponent for SFMT for the RNG to compile without warning +# Consider making this target specific --> target_compile_definitions(libcockatrice_rng PRIVATE SFMT_MEXP=19937) if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - add_definitions("-DSFMT_MEXP=19937") + add_compile_definitions(SFMT_MEXP=19937) endif() find_package(Threads REQUIRED) @@ -404,3 +402,10 @@ if(Qt6_FOUND AND Qt6_VERSION_MINOR GREATER_EQUAL 3) # Qt 6.3+ requires project finalization to support translations qt6_finalize_project() endif() + +# Print compiler identification at configuration time +message(STATUS "C++ compiler: ${CMAKE_CXX_COMPILER_ID}") +message(STATUS "C++ compiler version: ${CMAKE_CXX_COMPILER_VERSION}") +message(STATUS "C++ compiler path: ${CMAKE_CXX_COMPILER}") +message(STATUS "C++ standard: ${CMAKE_CXX_STANDARD}") +message(STATUS "C++ extensions: ${CMAKE_CXX_EXTENSIONS}") From d8fa4af3932785198971e625ed574e8695009e06 Mon Sep 17 00:00:00 2001 From: tooomm Date: Sat, 12 Sep 2026 16:38:52 +0200 Subject: [PATCH 12/13] format --- CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bca36ef9a..212241804 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,9 +239,8 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Clang compiler set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe") # <-- required for clang? see adding pr description again else() # Undefined compiler - message(WARNING - "Unknown C++ compiler: ${CMAKE_CXX_COMPILER_ID}" - ) + message(WARNING "Unknown C++ compiler: ${CMAKE_CXX_COMPILER_ID}") + endif() # GNU systems need to define the Mersenne Exponent for SFMT for the RNG to compile without warning From 024f1c6eb08a533370dfb94e948b25b3d3729081 Mon Sep 17 00:00:00 2001 From: tooomm Date: Sat, 19 Sep 2026 15:51:28 +0200 Subject: [PATCH 13/13] lint --- tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d03743955..5c100c94e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,13 +27,13 @@ add_executable(latency_tracker_test latency_tracker_test.cpp) add_test(NAME loader_local_matching_test COMMAND loader_local_matching_test) add_executable( ${VERSION_STRING_CPP} - loader_local_matching_test - loader_local_matching_test.cpp ${CMAKE_SOURCE_DIR}/cockatrice/src/client/network/update/client/release_channel.cpp ${CMAKE_SOURCE_DIR}/cockatrice/src/client/settings/cache_settings.cpp ${CMAKE_SOURCE_DIR}/cockatrice/src/client/settings/card_counter_settings.cpp ${CMAKE_SOURCE_DIR}/cockatrice/src/client/settings/shortcuts_settings.cpp ${CMAKE_SOURCE_DIR}/cockatrice/src/interface/card_picture_loader/card_picture_loader_local.cpp + loader_local_matching_test + loader_local_matching_test.cpp ) target_include_directories(loader_local_matching_test PRIVATE ${CMAKE_SOURCE_DIR}/cockatrice/src)