Skip to content

FindGLUT: On Windows and with multiple config generator do not use pkg-config

When compiling a project that used freeglut on Windows with a recent CMake version, I noticed that either Debug or Release builds were failing with errors like:

2022-09-27T09:50:47.3000214Z LINK : fatal error LNK1104: cannot open file 'freeglut.lib' [C:\robotology-superbuild\build\src\ICUB\src\tools\iCubGui\src\iCubGui.vcxproj]

or

2022-09-27T09:50:47.3000214Z LINK : fatal error LNK1104: cannot open file 'freeglutd.lib' [C:\robotology-superbuild\build\src\ICUB\src\tools\iCubGui\src\iCubGui.vcxproj]

After debugging, I realized that the problem was occuring only when pkg-config was installed and when using a multiple config generator (Visual Studio in this case).

What is happening (before this PR) is that due to !6251 (merged) pkg-config is always used to find the library if it is installed. The problem is that if pkg-config is used, the logic to handle properly the Release and Debug version of the library (discussed in #17037 (closed) and implemented in !2398 (merged)) is not run. This PR fixes this by not using pkg-config (even if it is available) when on Windows and using a multiple config generator.

Downstream issue: https://github.com/robotology/robotology-superbuild/issues/1252 .

Merge request reports