FindGLUT: Use pkg-config's results as HINTS for normal search

Since commit f90d15458a (FindGLUT: Use pkg-config to find flags if
available, 2021-06-11, v3.22.0-rc1~469^2), pkg-config results are used
directly.  However, this is not compatible with other features of
CMake's find logic such as `CMAKE_FIND_ROOT_PATH` and per-config
results.  Switch to a convention already used by pkg-config support in
other find modules, in which the pkg-config results are only used as
hints for the main search logic.

Fixes: #24028
This commit is contained in:
leha-bot
2022-10-09 19:26:38 +03:00
committed by Brad King
parent ffad2c44d7
commit 4ad57224b5

View File

@@ -67,33 +67,6 @@ The following variables may also be provided, for backwards compatibility:
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
function(_add_glut_target_simple)
if(TARGET GLUT::GLUT)
return()
endif()
add_library(GLUT::GLUT INTERFACE IMPORTED)
if(GLUT_INCLUDE_DIRS)
target_include_directories(GLUT::GLUT SYSTEM
INTERFACE "${GLUT_INCLUDE_DIRS}")
endif()
if(GLUT_LIBRARIES)
target_link_libraries(GLUT::GLUT INTERFACE ${GLUT_LIBRARIES})
endif()
if(GLUT_LIBRARY_DIRS)
target_link_directories(GLUT::GLUT INTERFACE ${GLUT_LIBRARY_DIRS})
endif()
if(GLUT_LDFLAGS)
target_link_options(GLUT::GLUT INTERFACE ${GLUT_LDFLAGS})
endif()
if(GLUT_CFLAGS)
separate_arguments(GLUT_CFLAGS_SPLIT UNIX_COMMAND "${GLUT_CFLAGS}")
target_compile_options(GLUT::GLUT INTERFACE ${GLUT_CFLAGS_SPLIT})
endif()
set_property(TARGET GLUT::GLUT APPEND PROPERTY
IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
endfunction()
find_package(PkgConfig QUIET)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
# On WIN32 and when using a multiple config generator, pkg-config
@@ -107,46 +80,45 @@ if(PKG_CONFIG_FOUND AND NOT (_isMultiConfig AND WIN32))
unset(_pkgconfig_allow_system_cflags_old)
endif()
set(ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS} 1)
pkg_check_modules(GLUT QUIET glut)
pkg_check_modules(PC_GLUT QUIET glut)
if(DEFINED _pkgconfig_allow_system_cflags_old)
set(ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS} "${_pkgconfig_allow_system_cflags_old}")
unset(_pkgconfig_allow_system_cflags_old)
else()
unset(ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS})
endif()
if(NOT GLUT_FOUND)
pkg_check_modules(GLUT QUIET freeglut)
endif()
if(GLUT_FOUND)
# GLUT_INCLUDE_DIRS is now the official result variable, but
# older versions of CMake only provided GLUT_INCLUDE_DIR.
set(GLUT_INCLUDE_DIR "${GLUT_INCLUDE_DIRS}")
_add_glut_target_simple()
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_FOUND)
return()
if(NOT PC_GLUT_FOUND)
pkg_check_modules(PC_GLUT QUIET freeglut)
endif()
endif()
if(WIN32)
find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
PATHS ${GLUT_ROOT_PATH}/include )
PATHS ${GLUT_ROOT_PATH}/include
HINTS ${PC_GLUT_INCLUDE_DIRS})
mark_as_advanced(GLUT_INCLUDE_DIR)
find_library( GLUT_glut_LIBRARY_RELEASE NAMES freeglut glut glut32
PATHS
${OPENGL_LIBRARY_DIR}
${GLUT_ROOT_PATH}/Release
HINTS
${PC_GLUT_LIBRARY_DIRS}
)
# N.B. As the pkg-config cannot distinguish between release and debug libraries,
# assume that their hint was the both Debug and Release library.
find_library( GLUT_glut_LIBRARY_DEBUG NAMES freeglutd
PATHS
${OPENGL_LIBRARY_DIR}
${GLUT_ROOT_PATH}/Debug
HINTS
${PC_GLUT_LIBRARY_DIRS}
)
mark_as_advanced(GLUT_glut_LIBRARY_RELEASE GLUT_glut_LIBRARY_DEBUG)
select_library_configurations(GLUT_glut)
elseif(APPLE)
find_path(GLUT_INCLUDE_DIR glut.h ${OPENGL_LIBRARY_DIR})
find_path(GLUT_INCLUDE_DIR glut.h PATHS ${OPENGL_LIBRARY_DIR} HINTS ${PC_GLUT_INCLUDE_DIRS})
mark_as_advanced(GLUT_INCLUDE_DIR)
find_library(GLUT_glut_LIBRARY GLUT DOC "GLUT library for OSX")
find_library(GLUT_glut_LIBRARY GLUT HINTS ${PC_GLUT_LIBRARY_DIRS} DOC "GLUT library for OSX")
find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX")
mark_as_advanced(GLUT_glut_LIBRARY GLUT_cocoa_LIBRARY)
@@ -195,18 +167,24 @@ else()
endif ()
find_path( GLUT_INCLUDE_DIR GL/glut.h
PATHS
/usr/include/GL
/usr/openwin/share/include
/usr/openwin/include
/opt/graphics/OpenGL/include
/opt/graphics/OpenGL/contrib/libglut
${_GLUT_INC_DIR}
HINTS
${PC_GLUT_INCLUDE_DIRS}
)
mark_as_advanced(GLUT_INCLUDE_DIR)
find_library( GLUT_glut_LIBRARY glut
PATHS
/usr/openwin/lib
${_GLUT_glut_LIB_DIR}
HINTS
${PC_GLUT_LIBRARY_DIRS}
)
mark_as_advanced(GLUT_glut_LIBRARY)