'CMake generator expression evaluated to "" instead of nothing
I'm using generator expressions in a custom command to compile hlsl shaders:
add_custom_command(TARGET Shaders
COMMAND vendor/shader-compiling/fxc.exe /nologo /Emain /Tvs_5_0 $<$<CONFIG:Debug>:/Od> /Zi /Fo ${TARGET_SHADER_PATH}/hlsl/${FILE_WE}_vs.cso /Fd ${CMAKE_BINARY_DIR}/${FILE_WE}_vs.pdb ${TARGET_SHADER_PATH}/hlsl/${FILE_WE}_vs.hlsl
COMMAND vendor/shader-compiling/fxc.exe /nologo /Emain /Tps_5_0 $<$<CONFIG:Debug>:/Od> /Zi /Fo ${TARGET_SHADER_PATH}/hlsl/${FILE_WE}_fs.cso /Fd ${CMAKE_BINARY_DIR}/${FILE_WE}_fs.pdb ${TARGET_SHADER_PATH}/hlsl/${FILE_WE}_fs.hlsl
MAIN_DEPENDENCY ${FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Compiling HLSL shader ${TARGET_SHADER_PATH}/hlsl/${FILE_WE}.hlsl"
VERBATIM)
and in debug mode everything works fine.
However, in release mode, my expected result is the /Od flag does not get included in the command at all. However, what ended up happening is $<$<CONFIG:Debug>:/Od> gets evaluated to two double quotes and the command doesn't work.
Any ideas on why this is happening?
Solution 1:[1]
Just in case anybody finds this useful, I solved the problem by adding COMMAND_EXPAND_LISTS to my add_custom_command command. Not sure why that works but it does get rid of the empty pair of quotes in the middle of the command therefore the command works.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SunnyMonster |
