FindGLUT: Imported target for GLUT framework on macOS has incorrect LOCATION property
On macOS 10.14 or 10.15 with Xcode 11 (macOS 10.15 SDK), the target GLUT::GLUT
exported by the FindGLUT
module has a LOCATION
property pointing to a path that does not exist.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.1)
project(myBrokenProject)
find_package(GLUT REQUIRED)
include(CMakePrintHelpers)
cmake_print_properties(TARGETS GLUT::GLUT PROPERTIES INTERFACE_INCLUDE_DIRECTORIES LOCATION)
add_executable(myTarget myTarget.c)
target_link_libraries(myTarget GLUT::GLUT)
% cmake .
-- The C compiler identification is AppleClang 11.0.0.11000033
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
...
-- Found GLUT: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/GLUT.framework
--
Properties for TARGET GLUT::GLUT:
GLUT::GLUT.INTERFACE_INCLUDE_DIRECTORIES = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/GLUT.framework/Headers"
GLUT::GLUT.LOCATION = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/GLUT.framework/GLUT" # <-- BUG: PATH DOES NOT EXIST
...
% make
Scanning dependencies of target myTarget
[ 50%] Building C object CMakeFiles/myTarget.dir/myTarget.c.o
make[2]: *** No rule to make target `/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/GLUT.framework/GLUT', needed by `myTarget'. Stop.
make[1]: *** [CMakeFiles/myTarget.dir/all] Error 2
make: *** [all] Error 2
The "library" and headers are actually in two different locations. The directory that is found only contains headers and debug symbols.
% ls /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/GLUT.framework
GLUT.tbd Headers Modules Versions
% ls /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/GLUT.framework
GLUT.tbd Headers Modules Versions
% ls /System/Library/Frameworks/GLUT.framework
GLUT Resources Versions
The following assumes that a folder named GLUT.framework
always contains a GLUT
"library":
https://gitlab.kitware.com/cmake/cmake/blob/v3.16.2/Modules/FindGLUT.cmake#L150
Workaround is
list(INSERT CMAKE_FRAMEWORK_PATH 0 /System/Library/Frameworks)
but that probably should not be necessary with the most common macOS configuration.
For example:
cmake_minimum_required(VERSION 3.1)
project(myFixedProject)
list(INSERT CMAKE_FRAMEWORK_PATH 0 /System/Library/Frameworks)
find_package(GLUT REQUIRED)
include(CMakePrintHelpers)
cmake_print_properties(TARGETS GLUT::GLUT PROPERTIES INTERFACE_INCLUDE_DIRECTORIES LOCATION)
% cmake .
...
--
Properties for TARGET GLUT::GLUT:
GLUT::GLUT.INTERFACE_INCLUDE_DIRECTORIES = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/GLUT.framework/Headers"
GLUT::GLUT.LOCATION = "/System/Library/Frameworks/GLUT.framework/GLUT" # <-- CORRECT