COMPILE_DEFINITIONS: Definition values with percent signs on Windows
Consider a target with compile definitions like this
target_compile_definitions(myapp PRIVATE
TESTCASE_BUILDDIR="${CMAKE_BINARY_DIR}/foo%2bar"))
This works fine on Linux, but on Windows there will be errors. For example, MSVC’s cl.exe yields “cl : Command line error D8038 : invalid argument”.
According to MS docs at https://docs.microsoft.com/en-us/cpp/build/reference/d-preprocessor-definitions?view=msvc-160#remarks percent sign should be written as doubled percent sign when passing it to the compiler with -D.
Given that target_compile_definitions
already does some escaping, it should probably also take care of doubling the percent sign on Windows.
Discourse link: https://discourse.cmake.org/t/percent-signs-in-target-compile-definitions-on-windows/4489