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.
In my Doom source-port, I use WildMIDI as a CMake subproject. When running CMake for the first time, targeting MSVC, I do not set
CMAKE_BUILD_TYPE
as MSVC uses a multi-configuration generator, meaning that it should have no effect. However, if I make MSVC attempt to compile a Release build, it will fail, claiming that the WildMIDI binary could not be found. This seems to be caused by an odd combination of things:WildMIDI detects that
CMAKE_BUILD_TYPE
is not set, forcefully sets it to 'Debug', and then setsCMAKE_CONFIGURATION_TYPES
to match it, which presumably disables every other build type for multi-configuration generators.This state-mutilation should be unnecessary, as the setting (or lack thereof) of
CMAKE_BUILD_TYPE
should have no effect on multi-configuration generators in the first place. Likewise, forcingCMAKE_BUILD_TYPE
to 'Debug' in the absence of an explicit value is overbearing, as it is desirable to build software with no particular build type, as it causes the minimum amount of compiler flags to be automatically added by CMake. Notably, Arch Linux relies on this, opting instead to manually provide its own compiler flags for optimisation and hardening.https://wiki.archlinux.org/title/CMake_package_guidelines#CMake_can_automatically_override_the_default_compiler_optimization_flag
Later on,
CMAKE_RUNTIME_OUTPUT_DIRECTORY
is redundantly set to thewildmidi_BINARY_DIR
variable. This causes theautomatically-generated per-configuration
CMAKE_RUNTIME_OUTPUT_DIRECTORY_[CONFIG]
variables to become undefined.Finally, in an apparent attempt to counteract the above bug, the per-configuration
CMAKE_RUNTIME_OUTPUT_DIRECTORY_[CONFIG]
variables are manually redefined, usingCMAKE_CONFIGURATION_TYPES
. BecauseCMAKE_CONFIGURATION_TYPES
was forcefully set earlier, however, it only contains 'Debug', causing only the Debug configuration to have a valid output directory set. This causes all other configurations to fail to produce a binary, resulting in a build failure as the binary cannot be linked.Personally, my rule-of-thumb is to keep CMake scripts as simple as possible and trust that CMake has sane defaults. Seeing redundant logic like this strikes me as a code smell, and this bug seems to validate that.