windows fails to quote vs path in cmake

100 views
Skip to first unread message

Clark Kent

unread,
Mar 6, 2024, 12:39:24 AM3/6/24
to skia-discuss
# CMAKE_CXX_COMPILER is an absolute path
# CMAKE_CXX_COMPILER = C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/Llvm/x64/bin/clang-cl.exe
#
# we need to chop it at the end
#
string(LENGTH "${CMAKE_CXX_COMPILER}" SKIA_ARGS_CLANG_WIN_TMP_LENGTH)
string(LENGTH "/bin/clang-cl.exe" SKIA_ARGS_CLANG_WIN_TMP_LENGTH_UNWANTED)
math(EXPR SKIA_ARGS_CLANG_WIN_TMP_LENGTH_ADJUSTED "${SKIA_ARGS_CLANG_WIN_TMP_LENGTH} - ${SKIA_ARGS_CLANG_WIN_TMP_LENGTH_UNWANTED}" OUTPUT_FORMAT DECIMAL)
string(SUBSTRING "${CMAKE_CXX_COMPILER}" 0 ${SKIA_ARGS_CLANG_WIN_TMP_LENGTH_ADJUSTED} SKIA_ARGS_CLANG_WIN_TMP)
message(STATUS "LLVM DIR = ${SKIA_ARGS_CLANG_WIN_TMP}")
set(SKIA_ARGS "${SKIA_ARGS} clang_win=\"${SKIA_ARGS_CLANG_WIN_TMP}\"")

set(SKIA_ARGS "${SKIA_ARGS} clang_win_version=\"${CMAKE_CXX_COMPILER_VERSION}\"")

# SKIA_ARGS_CLANG_WIN_TMP is an absolute path
# SKIA_ARGS_CLANG_WIN_TMP = C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/Llvm/x64
#
# we need to chop it at the end
#
string(LENGTH "${SKIA_ARGS_CLANG_WIN_TMP}" SKIA_ARGS_WIN_VC_TMP_LENGTH)
string(LENGTH "/Tools/Llvm/64" SKIA_ARGS_WIN_VC_TMP_LENGTH_UNWANTED)
# for some reason 'string(LENGTH "/Tools/Llvm/64") == string(LENGTH "Tools/Llvm/64")'
math(EXPR SKIA_ARGS_WIN_VC_TMP_LENGTH_ADJUSTED "${SKIA_ARGS_WIN_VC_TMP_LENGTH} - (${SKIA_ARGS_WIN_VC_TMP_LENGTH_UNWANTED}+1)" OUTPUT_FORMAT DECIMAL)
string(SUBSTRING "${SKIA_ARGS_CLANG_WIN_TMP}" 0 ${SKIA_ARGS_WIN_VC_TMP_LENGTH_ADJUSTED} SKIA_ARGS_WIN_VC_TMP)
message(STATUS "Visual Studio DIR = ${SKIA_ARGS_WIN_VC_TMP}")
set(SKIA_ARGS "${SKIA_ARGS} win_vc=\"${SKIA_ARGS_WIN_VC_TMP}\"")

1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PREVIEW\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_C_COMPILER:STRING="clang-cl.exe" -DCMAKE_CXX_COMPILER:STRING="clang-cl.exe" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:/Users/konek/source/repos/Multi-Platform-OpenGL-App/Windows-OS/out/install/x64-debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PREVIEW\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\konek\source\repos\Multi-Platform-OpenGL-App\Windows-OS" 2>&1"
1> Working directory: C:/Users/konek/source/repos/Multi-Platform-OpenGL-App/Windows-OS/out/build/x64-debug
1> [CMake] -- CMAKE_CXX_COMPILER = C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/Llvm/x64/bin/clang-cl.exe
1> [CMake] -- CMAKE_CXX_COMPILER_VERSION = 17.0.3
1> [CMake] -- CMAKE_CXX_COMPILER_VERSION_INTERNAL =
1> [CMake] -- CMAKE_CACHE_MAJOR_VERSION = 3
1> [CMake] -- LLVM DIR = C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/Llvm/x64
1> [CMake] -- Visual Studio DIR = C:/Program Files/Microsoft Visual Studio/2022/Preview/VC
1> [CMake] -- GN_OUTPUT_STDOUT.txt = C:/Users/konek/source/repos/Multi-Platform-OpenGL-App/Windows-OS/.CMAKE_TEMP_OUTPUT_GN_OUTPUT_STDOUT.txt
1> [CMake] -- GN_OUTPUT_STDERR.txt = C:/Users/konek/source/repos/Multi-Platform-OpenGL-App/Windows-OS/.CMAKE_TEMP_OUTPUT_GN_OUTPUT_STDERR.txt
1> [CMake] ninja: Entering directory `C:/Users/konek/source/repos/Multi-Platform-OpenGL-App/skia/cmake_generated/windows/Debug/'
1> [CMake] ninja: no work to do.
1> [CMake] -- Configuring done (11.9s)
1> [CMake] -- Generating done (1.5s)
1> [CMake] -- Build files have been written to: C:/Users/konek/source/repos/Multi-Platform-OpenGL-App/Windows-OS/out/build/x64-debug
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted toolchain configurations.
1> Extracted includes paths.
1> CMake generation finished.

>------ Build started: Project: CMakeLists, Configuration: Debug ------
[1/1119] Building CXX object C:/skia/Debug/windows/CMakeFiles/fontmgr_FontConfigInterface.dir/empty.cpp.obj
FAILED: C:/skia/Debug/windows/CMakeFiles/fontmgr_FontConfigInterface.dir/empty.cpp.obj
C:\PROGRA~1\MICROS~4\2022\Preview\VC\Tools\Llvm\x64\bin\clang-cl.exe /nologo -TP -DNDEBUG -DNOMINMAX -DSKIA_IMPLEMENTATION=1 -DSK_CODEC_DECODES_BMP -DSK_CODEC_DECODES_WBMP -DSK_DISABLE_LEGACY_VULKAN_MUTABLE_TEXTURE_STATE -DSK_DISABLE_TRACING -DSK_ENABLE_AVX512_OPTS -DSK_ENABLE_PRECOMPILE -DSK_GAMMA_APPLY_TO_A8 -DSK_GANESH -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_WARNINGS -D_HAS_EXCEPTIONS=0 -IC:/Users/konek/source/repos/Multi-Platform-OpenGL-App/Windows-OS/../skia -IC:/Users/konek/source/repos/Multi-Platform-OpenGL-App/skia -imsvc/upstream/emscripten/system/include --target=amd64-pc-windows-msvc -fdiagnostics-absolute-paths /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 -Wno-attributes /bigobj /utf-8 -imsvc C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.40.33521/include -imsvc C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/shared -imsvc C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/ucrt -imsvc C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/um -imsvc C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/winrt /O2 /Zc:inline /std:c++17 /GR- /showIncludes /FoC:/skia/Debug/windows/CMakeFiles/fontmgr_FontConfigInterface.dir/empty.cpp.obj /FdC:\skia\Debug\windows\CMakeFiles\fontmgr_FontConfigInterface.dir\ -c -- C:/Users/konek/source/repos/Multi-Platform-OpenGL-App/skia/cmake_generated/windows/Debug/empty.cpp
C:\...\clang-cl : error : no such file or directory: 'Files/Microsoft'
C:\...\clang-cl : error : no such file or directory: 'Visual'
C:\...\clang-cl : error : no such file or directory: 'Studio/2022/Preview/VC/Tools/MSVC/14.40.33521/include'
C:\...\clang-cl : error : no such file or directory: 'Files'
C:\...\clang-cl : error : no such file or directory: '(x86)/Windows'
C:\...\clang-cl : error : no such file or directory: 'Kits/10/Include/10.0.22621.0/shared'
C:\...\clang-cl : error : no such file or directory: 'Files'
C:\...\clang-cl : error : no such file or directory: '(x86)/Windows'
C:\...\clang-cl : error : no such file or directory: 'Kits/10/Include/10.0.22621.0/ucrt'
C:\...\clang-cl : error : no such file or directory: 'Files'
C:\...\clang-cl : error : no such file or directory: '(x86)/Windows'
C:\...\clang-cl : error : no such file or directory: 'Kits/10/Include/10.0.22621.0/um'
C:\...\clang-cl : error : no such file or directory: 'Files'
C:\...\clang-cl : error : no such file or directory: '(x86)/Windows'
C:\...\clang-cl : error : no such file or directory: 'Kits/10/Include/10.0.22621.0/winrt'
[2/1119] Building CXX object C:/skia/Debug/windows/CMakeFiles/avif.dir/empty.cpp.obj
FAILED: C:/skia/Debug/windows/CMakeFiles/avif.dir/empty.cpp.obj

Clark Kent

unread,
Mar 6, 2024, 1:00:34 AM3/6/24
to skia-discuss
SKIA_ARGS =  is_trivial_abi=false is_official_build=true is_debug=false skia_use_system_expat=false skia_use_system_harfbuzz=false skia_use_system_icu=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false clang_win="C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/Llvm/x64" clang_win_version="17.0.3" win_vc="C:/Program Files/Microsoft Visual Studio/2022/Preview/VC"

Clark Kent

unread,
Mar 6, 2024, 1:06:29 AM3/6/24
to skia-discuss
skia/bin/gn --root=skia gen skia/out/cmake '--args= is_trivial_abi=false is_official_build=true is_debug=false skia_use_system_expat=false skia_use_system_harfbuzz=false skia_use_system_icu=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false clang_win="C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/Llvm/x64" clang_win_version="17.0.3" win_vc="C:/Program Files/Microsoft Visual Studio/2022/Preview/VC"' --ide-json --json-ide-script=skia/gn/gn_to_cmake.py

Ben Wagner

unread,
Mar 6, 2024, 10:47:35 AM3/6/24
to skia-d...@googlegroups.com
Not sure what your setup is, and gn_to_cmake.py isn't used a lot these
days, but it looks like your issue is to do with the arguments
following "-imsvc" not being quoted or escaped? These will be set
through a set_target_properties and properly escaped for CMake, but I
would have expected CMake to properly escape these as command line
arguments (this is somewhat complicated as it must also escape them
for ninja). Interestingly, it looks like CMake is instead not escaping
anything here but instead attempting to rely on all file names being
the 8.3 compatibility names? It might make sense on Windows due to the
impossibility of escaping some sequences. Does this fail with other
CMake generators (vscode or make) or is this specific to the ninja
generator? Which version of CMake?

You can open an issue against Skia if you would like, but there isn't
anyone working on this at the moment. If there's a simple patch to
work around this it might be considered.
> --
> You received this message because you are subscribed to the Google Groups "skia-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/42c6d4ea-e1cd-4da6-a089-f939d01a67dfn%40googlegroups.com.

Clark Kent

unread,
Mar 7, 2024, 1:13:51 PM3/7/24
to skia-discuss
this fixes it

skia\gn\skia\BUILD.gn

if (is_clang) {
foreach(dir, _include_dirs) {
cflags += [ "-imsvc", "\"$dir\"" ]
}
} else {
include_dirs = _include_dirs
}

Ben Wagner

unread,
Mar 7, 2024, 3:03:21 PM3/7/24
to skia-d...@googlegroups.com
I understand why that change "works" but we cannot check that into
Skia proper since that doesn't make logical sense and will break other
uses. The real issue is that we're not stringifying each entry in
SetCurrentTargetProperty. Which was supposed to be what
COMPILE_OPTIONS was supposed to fix (by being a proper list).

In theory the fix could be to use COMPILE_OPTIONS and LINK_OPTIONS
like https://skia-review.googlesource.com/c/skia/+/823078, but CMake
is bizarre and "de-duplicates" the list (see
https://gitlab.kitware.com/cmake/cmake/-/issues/15826 and the "fix" at
https://gitlab.kitware.com/cmake/cmake/-/merge_requests/1841). This
breaks use of `-isystem` and `-imsvc` and a host of other arguments by
"combining" them. And we don't know which ones go together (because
why would any build system be so illogical), so we'd need to throw
everything into a "SHELL:" group and escape that (in Unix shell escape
rules?).

I might take another look later, but this isn't likely to get fixed
right now. If you're interested in trying to get
https://skia-review.googlesource.com/c/skia/+/823078 working, feel
free.
> To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/817c76aa-ec7e-4b90-9531-97dd4c2c89d2n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages