Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In my Doom source-port, I use WildMIDI as a CMake subproject. When running CMake for the first time, targetting 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 sets `CMAKE_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, forcing `CMAKE_BUILD_TYPE` to 'Debug' in the absense 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 optimisations 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 the `wildmidi_BINARY_DIR` variable. This causes the automatically-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, using `CMAKE_CONFIGURATION_TYPES`. Because `CMAKE_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.
- Loading branch information