forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 117
[GEN][ZH] Add cmake configurability for MemoryPool features and debugs, disable slow stack trace #542
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
Merged
xezon
merged 2 commits into
TheSuperHackers:main
from
xezon:xezon/fix-debug-memorypool-configurability
Mar 30, 2025
Merged
[GEN][ZH] Add cmake configurability for MemoryPool features and debugs, disable slow stack trace #542
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| ### BUILD OPTIONS ### | ||
|
|
||
| # 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) | ||
| message("You must select one project to build, building Zero Hour by default.") | ||
| endif() | ||
|
|
||
| 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") | ||
|
|
||
|
|
||
| ### MEMORY POOL OPTIONS ### | ||
|
|
||
| # Memory pool features | ||
| option(GENZH_MEMORYPOOL_OVERRIDE_MALLOC "Enables the Dynamic Memory Allocator for malloc calls." OFF) | ||
| option(GENZH_MEMORYPOOL_MPSB_DLINK "Adds a backlink to MemoryPoolSingleBlock. Makes it faster to free raw DMA blocks, but increases memory consumption." ON) | ||
|
|
||
| # Memory pool debugs | ||
| option(GENZH_MEMORYPOOL_DEBUG "Enables Memory Pool debug." ON) | ||
| option(GENZH_MEMORYPOOL_DEBUG_CUSTOM_NEW "Enables a custom new operator for the Memory Pool." ON) | ||
| option(GENZH_MEMORYPOOL_DEBUG_CHECKPOINTING "Records checkpoint information about the history of memory allocations." OFF) | ||
| option(GENZH_MEMORYPOOL_DEBUG_BOUNDINGWALL "Enables bounding wall checks around memory chunks to find memory trampling." ON) | ||
| option(GENZH_MEMORYPOOL_DEBUG_STACKTRACE "Enables stack trace collection for allocations. Reduces runtime performance significantly." OFF) | ||
| option(GENZH_MEMORYPOOL_DEBUG_INTENSE_VERIFY "Enables intensive verifications after nearly every memory operation. OFF by default, since it slows down things a lot, but is worth turning on for really obscure memory corruption issues." OFF) | ||
| option(GENZH_MEMORYPOOL_DEBUG_CHECK_BLOCK_OWNERSHIP "Enables debug to verify that a block actually belongs to the pool it is called with. This is great for debugging, but can be realllly slow, so is OFF by default." OFF) | ||
| option(GENZH_MEMORYPOOL_DEBUG_INTENSE_DMA_BOOKKEEPING "Prints statistics for memory usage of Memory Pools." OFF) | ||
|
|
||
| # Memory pool features | ||
| add_feature_info(MemoryPoolOverrideMalloc GENZH_MEMORYPOOL_OVERRIDE_MALLOC "Build with Memory Pool malloc") | ||
| add_feature_info(MemoryPoolMpsbDlink GENZH_MEMORYPOOL_MPSB_DLINK "Build with Memory Pool backlink") | ||
|
|
||
| # Memory pool debugs | ||
| add_feature_info(MemoryPoolDebug GENZH_MEMORYPOOL_DEBUG "Build with Memory Pool debug") | ||
| add_feature_info(MemoryPoolDebugCustomNew GENZH_MEMORYPOOL_DEBUG_CUSTOM_NEW "Build with Memory Pool custom new") | ||
| add_feature_info(MemoryPoolDebugCheckpointing GENZH_MEMORYPOOL_DEBUG_CHECKPOINTING "Build with Memory Pool checkpointing") | ||
| add_feature_info(MemoryPoolDebugBoundingwall GENZH_MEMORYPOOL_DEBUG_BOUNDINGWALL "Build with Memory Pool Bounding Wall") | ||
| add_feature_info(MemoryPoolDebugStacktrace GENZH_MEMORYPOOL_DEBUG_STACKTRACE "Build with Memory Pool Stacktrace") | ||
| add_feature_info(MemoryPoolDebugIntenseVerify GENZH_MEMORYPOOL_DEBUG_INTENSE_VERIFY "Build with Memory Pool intense verify") | ||
| add_feature_info(MemoryPoolDebugCheckBlockOwnership GENZH_MEMORYPOOL_DEBUG_CHECK_BLOCK_OWNERSHIP "Build with Memory Pool block ownership checks") | ||
| add_feature_info(MemoryPoolDebugIntenseDmaBookkeeping GENZH_MEMORYPOOL_DEBUG_INTENSE_DMA_BOOKKEEPING "Build with Memory Pool intense DMA bookkeeping") | ||
|
|
||
|
|
||
| ### INTERFACE LIBRARY SETUP ### | ||
|
|
||
| add_library(gz_config INTERFACE) | ||
|
|
||
| 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_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 $<$<CONFIG:DEBUG>:_DEBUG_CRT>) | ||
| endif() | ||
|
|
||
| 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) | ||
| endif() | ||
| if(GENZH_BUILD_PROFILE) | ||
| target_compile_definitions(gz_config INTERFACE _PROFILE) | ||
| endif() | ||
| endif() | ||
|
|
||
| # Memory pool features | ||
| if(GENZH_MEMORYPOOL_OVERRIDE_MALLOC) | ||
| target_compile_definitions(gz_config INTERFACE MEMORYPOOL_OVERRIDE_MALLOC=1) | ||
| endif() | ||
|
|
||
| if(NOT GENZH_MEMORYPOOL_MPSB_DLINK) | ||
| target_compile_definitions(gz_config INTERFACE DISABLE_MEMORYPOOL_MPSB_DLINK=1) | ||
| endif() | ||
|
|
||
| # Memory pool debugs | ||
| if(NOT GENZH_MEMORYPOOL_DEBUG) | ||
| target_compile_definitions(gz_config INTERFACE DISABLE_MEMORYPOOL_DEBUG=1) | ||
| else() | ||
| if(NOT GENZH_MEMORYPOOL_DEBUG_CUSTOM_NEW) | ||
| target_compile_definitions(gz_config INTERFACE DISABLE_MEMORYPOOL_DEBUG_CUSTOM_NEW=1) | ||
| endif() | ||
|
|
||
| if(GENZH_MEMORYPOOL_DEBUG_CHECKPOINTING) | ||
| # Set to 0 to override the default setting in code | ||
| target_compile_definitions(gz_config INTERFACE DISABLE_MEMORYPOOL_CHECKPOINTING=0) | ||
| else() | ||
| target_compile_definitions(gz_config INTERFACE DISABLE_MEMORYPOOL_CHECKPOINTING=1) | ||
| endif() | ||
Mauller marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if(NOT GENZH_MEMORYPOOL_DEBUG_BOUNDINGWALL) | ||
| target_compile_definitions(gz_config INTERFACE DISABLE_MEMORYPOOL_BOUNDINGWALL=1) | ||
| endif() | ||
|
|
||
| if(NOT GENZH_MEMORYPOOL_DEBUG_STACKTRACE) | ||
| target_compile_definitions(gz_config INTERFACE DISABLE_MEMORYPOOL_STACKTRACE=1) | ||
| endif() | ||
|
|
||
| if(GENZH_MEMORYPOOL_DEBUG_INTENSE_VERIFY) | ||
| target_compile_definitions(gz_config INTERFACE MEMORYPOOL_INTENSE_VERIFY=1) | ||
| endif() | ||
|
|
||
| if(GENZH_MEMORYPOOL_DEBUG_CHECK_BLOCK_OWNERSHIP) | ||
| target_compile_definitions(gz_config INTERFACE MEMORYPOOL_CHECK_BLOCK_OWNERSHIP=1) | ||
| endif() | ||
|
|
||
| if(GENZH_MEMORYPOOL_DEBUG_INTENSE_DMA_BOOKKEEPING) | ||
| target_compile_definitions(gz_config INTERFACE INTENSE_DMA_BOOKKEEPING=1) | ||
| endif() | ||
| endif() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.