FindGLUT issues spurious failure message on macOS (maybe Win32?)
cmake: 3.22.3 macos: 12.2.1
tl;dr
FindGLUT.cmake
reports check failures up to the user causing confusion.
Details
FindGLUT.cmake
uses pkg_check_modules()
before moving on to OS specific checks. On macOS with pkg-config
installed, this results in a spurious failure message. This message is confusing to users who are not intimately familiar with their system's CMake, which then gets reported to their upstream.
Given
# CMakeLists.txt
cmake_minimum_required(VERSION 3.1)
project(f)
find_package(GLUT REQUIRED)
include(CMakePrintHelpers)
cmake_print_variables(GLUT_FOUND GLUT_LIBRARIES GLUT_INCLUDE_DIR)
cmake_print_properties(TARGETS GLUT::GLUT PROPERTIES INTERFACE_INCLUDE_DIRECTORIES LOCATION)
If we run cmake
without pkg-config
installed:
$ brew uninstall --ignore-dependencies pkg-config
$ rm -rf CMakeCache.txt CMakeFiles/ ; cmake .
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found GLUT: /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/GLUT.framework
-- GLUT_FOUND="TRUE" ; GLUT_LIBRARIES="/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/GLUT.framework;/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Cocoa.framework" ; GLUT_INCLUDE_DIR="/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/GLUT.framework/Headers"
--
Properties for TARGET GLUT::GLUT:
GLUT::GLUT.INTERFACE_INCLUDE_DIRECTORIES = "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/GLUT.framework/Headers"
GLUT::GLUT.LOCATION = "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/GLUT.framework/GLUT.tbd"
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/nega/glut_test
$
If we do the same with pkg-config
installed:
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /opt/homebrew/bin/pkg-config (found version "0.29.2")
-- Checking for module 'glut'
-- No package 'glut' found
-- Found GLUT: /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/GLUT.framework
-- GLUT_FOUND="TRUE" ; GLUT_LIBRARIES="/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/GLUT.framework;/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Cocoa.framework" ; GLUT_INCLUDE_DIR="/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/GLUT.framework/Headers"
--
Properties for TARGET GLUT::GLUT:
GLUT::GLUT.INTERFACE_INCLUDE_DIRECTORIES = "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/GLUT.framework/Headers"
GLUT::GLUT.LOCATION = "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/GLUT.framework/GLUT.tbd"
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/nega/glut_test
$
Without context, the output
-- Checking for module 'glut'
-- No package 'glut' found
causes user confusion, and upstream reporting. This issue is being driven by the fact that I gave a user incorrect advice to "install freeglut, re-cmake, and report back" instead of taking the 15 seconds that it would have taken me to recognize/remember that this is an error bubbling up from "under the hood". The best way to handle this might be to QUIET
the call to pkg_check_modules()
à la:
--- cmake/Modules/FindGLUT.cmake.old 2022-03-11 08:21:58.000000000 -0500
+++ cmake/Modules/FindGLUT.cmake 2022-03-11 08:22:22.000000000 -0500
@@ -70,9 +70,9 @@
IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
endfunction()
-find_package(PkgConfig)
+find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
- pkg_check_modules(GLUT glut)
+ pkg_check_modules(GLUT glut QUIET)
if(GLUT_FOUND)
# In the non-pkg-config code path we only provide GLUT_INCLUDE_DIR.
set(GLUT_INCLUDE_DIR "${GLUT_INCLUDE_DIRS}")
Notice that this diff also quiets find_package(PkgConfig)
whose output I believe is also not germane, and runs counter to the convention in the other included Find*.cmake
modules (along with FindBLAS
, FindLAPACK
, and FindGSL
.)