Search code examples
windowscmakemingwmsys2pkg-config

How can I convert *nix style paths into Windows style paths in CMake?


I'm developing a C program based on GLib and OpenBLAS. I hope it'd run on both Windows and linux platforms, so I chose CMake to configure the project. Here's my CMakeLists.txt:

# ...
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLib REQUIRED glib-2.0)
message(STATUS "GLib Found:")
message(STATUS "  GLib include directories:   ${GLib_INCLUDE_DIRS}")
message(STATUS "  GLib library directories:   ${GLib_LIBRARY_DIRS}")
message(STATUS "  GLib libraries:             ${GLib_LIBRARIES}")
pkg_check_modules(BLAS REQUIRED openblas)
message(STATUS "OpenBLAS Found:")
message(STATUS "  BLAS include directories:   ${BLAS_INCLUDE_DIRS}")
message(STATUS "  BLAS library directories:   ${BLAS_LIBRARY_DIRS}")
message(STATUS "  BLAS libraries:             ${BLAS_LIBRARIES}")
#...

Running on MSYS2/MinGW64, cmake gives:

-- GLib Found:
--   GLib include directories:   X:/path/to/msys64/mingw64/include/glib-2.0;X:/path/to/msys64/mingw64/lib/glib-2.0/include;X:/path/to/msys64/mingw64/include
--   GLib library directories:   X:/path/to/msys64/mingw64/lib
--   GLib libraries:             glib-2.0;intl
-- OpenBLAS Found:
--   BLAS include directories:   /mingw64/include/OpenBLAS
--   BLAS library directories:   
--   BLAS libraries:             openblas

It seems that pkg-config uses *nix path on openblas which leads to include failures.

Add X:/path/to/msys64 as a prefix should work. However msys could be installed in various places and I don't know how to find the msys path in cmake.

Thanks for any help in advance.

P.S. FindBLAS gives the same output.


Solution

  • If you install Openblas and Glib in msys2, then you can compare the pkg-config files openblas.pc and glib-2.0.pc. Now you would figure out the differences between them. In other words, please add the prefix=/mingw64 to the openblas.pc.