CMake generates invalid generator expression in ninja.build
under some strange circumstances CMake generates a build.ninja file with an unevaluated generator expression:
what I do in shortened form:
function(vcpkg_check_linkage OUTPUT_LINK_LIST)
if(something_in_vcpkg)
list(APPEND ${_tmp_list} debug "${VCPKG_LIBTRACK_${_vcpkg_libtrack_name}_DEBUG}")
list(APPEND ${_tmp_list} optimized "${VCPKG_LIBTRACK_${_vcpkg_libtrack_name}_RELEASE}")
endif()
set(${OUTPUT_LINK_LIST} ${_tmp_list} PARENT_SCOPE)
endfunction()
function(target_link_libraries)
vcpkg_target_link_libraries(${ARGV})
endfunction()
function(vcpkg_target_link_libraries _target_name)
cmake_parse_arguments ...
...
vcpkg_check_linkage(_vcpkg_check_linkage ${_vcpkg_tll_UNPARSED_ARGUMENTS})
_target_link_libraries(${_target_name} ${_vcpkg_check_linkage})
...
endfunction(vcpkg_target_link_libraries)
In the .build.ninja files I see:
LINK_LIBRARIES = $<$<CONFIG:DEBUG>:G:/vcpkg_test/vcpkg/installed/x64-windows/debug/lib/glib-2.0.lib> $<$<NOT:$<CONFIG:DEBUG>>:G:/vcpkg_test/vcpkg/installed/x64-windows/lib/glib-2.0.lib> $<$<CONFIG:DEBUG>:G:/vcpkg_test/vcpkg/installed/x64-windows/debug/lib/gthread-2.0.lib> $<$<NOT:$<CONFIG:DEBUG>>:G:/vcpkg_test/vcpkg/installed/x64-windows/lib/gthread-2.0.lib> ws2_32.lib dsound.lib winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib
which of course will generate an error because the $
must be $$
. I also tried replacing optimized/debug with generator expression without luck. The best I was able to get was: \$$<$$<CONFIG:DEBUG>
which is also wrong due to the extra \
.
Fun Facts:
- The above code seems to work for most of the vcpkg ports
- CMake seems to have understood the keywords optimized/debug but generated a failing ninja.build script nevertheless.
- The port failing has cmake_minimum_required ( VERSION 3.1.0 ) [dont know if this is relevant? bumped it to 3.5 without success]
- Changing the generator gives a successful build. So it seems the script is working correctly.