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

Clean up CMake. #498

Merged
merged 7 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/build-games.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
tools: true
- preset: "vc6int"
tools: true
- preset: "vc6debug"
- preset: "vc6dbg"
tools: true
fail-fast: false
uses: ./.github/workflows/toolchain-common.yml
Expand All @@ -80,7 +80,7 @@ jobs:
tools: true
- preset: "vc6int"
tools: true
- preset: "vc6debug"
- preset: "vc6dbg"
tools: true
fail-fast: false
uses: ./.github/workflows/toolchain-common.yml
Expand Down
64 changes: 20 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,8 @@ endif()
# Top level project, doesn't really affect anything.
project(genzh LANGUAGES C CXX)

# Print some information
message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
if (DEFINED MSVC_VERSION)
message(STATUS "MSVC_VERSION: ${MSVC_VERSION}")
endif()

# Set variable for VS6 to handle special cases.
if (DEFINED MSVC_VERSION AND MSVC_VERSION LESS 1300)
set(IS_VS6_BUILD TRUE)
else()
set(IS_VS6_BUILD FALSE)
endif()

# Create PDB for Release as long as debug info was generated during compile.
if(MSVC)
string(APPEND CMAKE_EXE_LINKER_FLAGS_RELEASE " /DEBUG /OPT:REF /OPT:ICF")
string(APPEND CMAKE_SHARED_LINKER_FLAGS_RELEASE " /DEBUG /OPT:REF /OPT:ICF")
endif()
# This file handles extra settings wanted/needed for different compilers.
include(cmake/compilers.cmake)

include(FetchContent)

Expand All @@ -78,25 +59,12 @@ add_subdirectory(Dependencies/MaxSDK)
add_subdirectory(Dependencies/SafeDisc)
add_subdirectory(Dependencies/Utility)

if (NOT IS_VS6_BUILD)
# Set C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) # Ensures only ISO features are used

if (MSVC)
# Multithreaded build.
add_compile_options(/MP)
# Enforce strict __cplusplus version
add_compile_options(/Zc:__cplusplus)
endif()
endif()

# Do we want to build extra SDK stuff or just the game binary?
option(GENZH_BUILD_ZEROHOUR "Build Zero Hour code." ON)
option(GENZH_BUILD_GENERALS "Build Generals code." ON)
option(GENZH_BUILD_INTERNAL "Build code with the \"Internal\" configuration." OFF)
option(GENZH_BUILD_PROFILE "Build code with the \"Profile\" configuration." OFF)
option(GENZH_BUILD_DEBUG "Build code with the \"Debug\" configuration." OFF)

if(NOT GENZH_BUILD_ZEROHOUR AND NOT GENZH_BUILD_GENERALS)
set(GENZH_BUILD_ZEROHOUR TRUE)
Expand All @@ -107,24 +75,32 @@ add_feature_info(ZeroHourStuff GENZH_BUILD_ZEROHOUR "Build Zero Hour code")
add_feature_info(GeneralsStuff GENZH_BUILD_GENERALS "Build Generals code")
add_feature_info(InternalBuild GENZH_BUILD_INTERNAL "Building as an \"Internal\" build")
add_feature_info(ProfileBuild GENZH_BUILD_PROFILE "Building as a \"Profile\" build")
add_feature_info(DebugBuild GENZH_BUILD_DEBUG "Building as a \"Debug\" build")

add_library(gz_config INTERFACE)

target_compile_options(gz_config INTERFACE ${GENZH_FLAGS})
if(NOT IS_VS6_BUILD)
# Because we set CMAKE_CXX_STANDARD_REQUIRED and CMAKE_CXX_EXTENSIONS in the compilers.cmake this should be enforced.
target_compile_features(gz_config INTERFACE cxx_std_20)
endif()

target_compile_definitions(gz_config INTERFACE $<IF:$<CONFIG:Debug>,_DEBUG WWDEBUG DEBUG,_RELEASE>)
target_compile_options(gz_config INTERFACE ${GENZH_FLAGS})

# This disables a lot of warnings steering developers to use windows only functions/function names.
if(MSVC)
target_compile_definitions(gz_config INTERFACE _CRT_NONSTDC_NO_WARNINGS _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(gz_config INTERFACE _CRT_NONSTDC_NO_WARNINGS _CRT_SECURE_NO_WARNINGS $<$<CONFIG:DEBUG>:_DEBUG_CRT>)
endif()

if(GENZH_BUILD_PROFILE)
target_compile_definitions(gz_config INTERFACE _PROFILE)
endif()

if(GENZH_BUILD_INTERNAL)
target_compile_definitions(gz_config INTERFACE _INTERNAL)
if(GENZH_BUILD_DEBUG)
target_compile_definitions(gz_config INTERFACE _DEBUG WWDEBUG DEBUG)
else()
target_compile_definitions(gz_config INTERFACE _RELEASE)

if(GENZH_BUILD_INTERNAL)
target_compile_definitions(gz_config INTERFACE _INTERNAL)
elseif(GENZH_BUILD_PROFILE)
target_compile_definitions(gz_config INTERFACE _PROFILE)
endif()
endif()

# Add main build targets
Expand Down
177 changes: 147 additions & 30 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"CMAKE_MSVC_DEBUG_INFORMATION_FORMAT": "$<$<CONFIG:Release,Debug,RelWithDebInfo>:ProgramDatabase>",
"CMAKE_BUILD_TYPE": "Release",
"GENZH_FLAGS": "/W3"
},
"vendor": {
"jetbrains.com/clion": {
"toolchain": "Visual Studio 6"
}
}
},
{
Expand All @@ -38,12 +43,13 @@
}
},
{
"name": "vc6debug",
"name": "vc6dbg",
"displayName": "Build Debug Binaries with NMake",
"hidden": false,
"inherits": "vc6",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
"CMAKE_BUILD_TYPE": "Debug",
"GENZH_BUILD_DEBUG": "ON"
}
},
{
Expand All @@ -59,58 +65,52 @@
}
},
{
"name": "msvc32",
"architecture": "Win32",
"name": "win32",
"inherits": "default",
"generator": "Visual Studio 17 2022",
"hidden": false,
"displayName": "Visual Studio Win32 build",
"displayName": "Windows 32bit build",
"architecture": {
"value": "Win32",
"strategy": "external"
},
"cacheVariables": {
"GENZH_FLAGS": "/W3"
},
"vendor": {
"jetbrains.com/clion": {
"toolchain": "Visual Studio"
}
}
},
{
"name": "msvc32prof",
"inherits": "msvc32",
"displayName": "Visual Studio Win32 Profile build",
"name": "win32prof",
"inherits": "win32",
"displayName": "Windows 32bit Profile build",
"cacheVariables": {
"GENZH_BUILD_PROFILE": "ON"
}
},
{
"name": "msvc32int",
"inherits": "msvc32",
"displayName": "Visual Studio Win32 Internal build",
"name": "win32int",
"inherits": "win32",
"displayName": "Windows 32bit Internal build",
"cacheVariables": {
"GENZH_BUILD_INTERNAL": "ON"
}
},
{
"name": "msvc32debug",
"inherits": "msvc32",
"displayName": "Visual Studio Win32 Debug build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "win32",
"inherits": "default",
"hidden": false,
"displayName": "Win32 build",
"name": "win32dbg",
"inherits": "win32",
"displayName": "Windows 32bit Debug build",
"cacheVariables": {
"GENZH_FLAGS": "/W3"
"GENZH_BUILD_DEBUG": "ON"
}
},
{
"name": "unix",
"inherits": "default",
"hidden": false,
"displayName": "Non-Windows build",
"cacheVariables": {
"CMAKE_CXX_FLAGS_RELEASE": "-O2 -g -DNDEBUG",
"CMAKE_C_FLAGS_RELEASE": "-O2 -g -DNDEBUG"
}
"displayName": "Non-Windows build"
}
],
"buildPresets": [
Expand All @@ -120,13 +120,52 @@
"displayName": "Build VC6 Windows build",
"description": "Build VC6 Windows build"
},
{
"name": "vc6int",
"configurePreset": "vc6int",
"displayName": "Build VC6 Windows Internal build",
"description": "Build VC6 Windows Internal build"
},
{
"name": "vc6prof",
"configurePreset": "vc6prof",
"displayName": "Build VC6 Windows Profile build",
"description": "Build VC6 Windows Profile build"
},
{
"name": "vc6dbg",
"configurePreset": "vc6dbg",
"displayName": "Build VC6 Windows Debug build",
"description": "Build VC6 Windows Debug build"
},
{
"name": "win32",
"configurePreset": "win32",
"displayName": "Build Windows build",
"description": "Build Windows build",
"configuration": "Release"
},
{
"name": "win32int",
"configurePreset": "win32int",
"displayName": "Build Windows Internal build",
"description": "Build Windows Internal build",
"configuration": "Release"
},
{
"name": "win32prof",
"configurePreset": "win32prof",
"displayName": "Build Windows Profiling build",
"description": "Build Windows Profiling build",
"configuration": "Release"
},
{
"name": "win32dbg",
"configurePreset": "win32dbg",
"displayName": "Build Windows Debug build",
"description": "Build Windows Debug build",
"configuration": "Debug"
},
{
"name": "unix",
"configurePreset": "unix",
Expand All @@ -149,6 +188,45 @@
}
]
},
{
"name": "vc6dbg",
"steps": [
{
"type": "configure",
"name": "vc6dbg"
},
{
"type": "build",
"name": "vc6dbg"
}
]
},
{
"name": "vc6int",
"steps": [
{
"type": "configure",
"name": "vc6int"
},
{
"type": "build",
"name": "vc6int"
}
]
},
{
"name": "vc6prof",
"steps": [
{
"type": "configure",
"name": "vc6prof"
},
{
"type": "build",
"name": "vc6prof"
}
]
},
{
"name": "win32",
"steps": [
Expand All @@ -162,6 +240,45 @@
}
]
},
{
"name": "win32int",
"steps": [
{
"type": "configure",
"name": "win32int"
},
{
"type": "build",
"name": "win32int"
}
]
},
{
"name": "win32prof",
"steps": [
{
"type": "configure",
"name": "win32prof"
},
{
"type": "build",
"name": "win32prof"
}
]
},
{
"name": "win32dbg",
"steps": [
{
"type": "configure",
"name": "win32dbg"
},
{
"type": "build",
"name": "win32dbg"
}
]
},
{
"name": "unix",
"steps": [
Expand Down
4 changes: 0 additions & 4 deletions Dependencies/Benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
cmake_minimum_required(VERSION 3.5.0)

project(benchmark VERSION 1.0.0 LANGUAGES C)

add_library(benchmark INTERFACE)
target_include_directories(benchmark INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand Down
Loading