Skip to content

Problem in FindPkgConfig.cmake when finding GTK3 on Windows

cmake version 3.19.2 on Windows 10

In my CMakeLists.txt I have the following lines

find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)

I specify the path to my GTK3 build using CMAKE_PREFIX_PATH:

cmake .. -G "Visual Studio 16 2019" -A x64 -DCMAKE_PREFIX_PATH="C:/gtk-build/gtk/x64/release"

This results in the following error:

-- Checking for module 'gtk+-3.0'

CMake Error at C:/Program Files/CMake/share/cmake-3.19/Modules/FindPkgConfig.cmake:83 (set):

Syntax error in cmake code at

C:/Program Files/CMake/share/cmake-3.19/Modules/FindPkgConfig.cmake:83

when parsing string

C:\gtk-build\gtk\x64\release

Invalid character escape '\g'.

Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.19/Modules/FindPkgConfig.cmake:110 (_pkgconfig_set)

C:/Program Files/CMake/share/cmake-3.19/Modules/FindPkgConfig.cmake:836 (_pkgconfig_invoke)

C:/Program Files/CMake/share/cmake-3.19/Modules/FindPkgConfig.cmake:572 (pkg_get_variable)

C:/Program Files/CMake/share/cmake-3.19/Modules/FindPkgConfig.cmake:741 (_pkg_check_modules_internal)

script/cmake/FindGTK3.cmake:33 (pkg_check_modules)

CMakeLists.txt:17 (include)

Please note that I use forward slashes in CMAKE_PREFIX_PATH, but the error text includes reverse slashes

I managed to track the error to line 375 in FindPkgConfig.cmake:

file(TO_NATIVE_PATH "${_pkgconfig_path}" _pkgconfig_path)

Locally I worked around the problem by removing the line, but I am not sure if it's a good general solution. Personally, I don't understand the need to convert the path to native, but maybe there is a use for this.

I suggest to either remove the conversion, or escape backward slashes

Edited by Vlad
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information