Skip to content

Variables CMAKE_PREFIX_PATH, CMAKE_FRAMEWORK_PATH, CMAKE_APPBUNDLE_PATH do not work in Cygwin

Cygwin version of pkg-config (C:/Cygwin64/bin/pkgconf.exe) recognizes only Cygwin paths in PKG_CONFIG_PATH, but not Windows paths. For example on my Windows 10 64bit pkgconf.exe version 1.6.3 finds packages with PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig, but does not find them with PKG_CONFIG_PATH=C:/Cygwin64/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig, although both paths are valid in the Cygwin console.

The function _pkg_set_path_internal() from Modules/FindPkgConfig.cmake parses CMAKE_PREFIX_PATH, CMAKE_FRAMEWORK_PATH, CMAKE_APPBUNDLE_PATH and sets PKG_CONFIG_PATH conditionally depending on EXISTS result:

# Check if directories exist and eventually append them to the
# pkgconfig path list
foreach(_prefix_dir ${_extra_paths})
  foreach(_lib_dir ${_lib_dirs})
    if(EXISTS "${_prefix_dir}/${_lib_dir}") # !!
      list(APPEND _pkgconfig_path "${_prefix_dir}/${_lib_dir}")
      list(REMOVE_DUPLICATES _pkgconfig_path)
    endif()
  endforeach()
endforeach()

The problem is the EXISTS macro recognizes only Windows paths. If I use a Cygwin path in CMAKE_PREFIX_PATH, CMAKE_FRAMEWORK_PATH, CMAKE_APPBUNDLE_PATH then EXISTS fails and PKG_CONFIG_PATH is not appended. If I use a Windows path then EXISTS succeeds, but stores a Windows path into PKG_CONFIG_PATH which is not accepted by pkgconf.exe as I said earlier.

Workaround: directly use environment variable PKG_CONFIG_PATH, not use CMAKE_PREFIX_PATH, CMAKE_FRAMEWORK_PATH, CMAKE_APPBUNDLE_PATH.

Proposed solution: teach EXISTS macro to consider a path as a Cygwin path if it starts with / on Windows.

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