From 4ad57224b515024264340c18b5b03240e100849d Mon Sep 17 00:00:00 2001 From: leha-bot Date: Sun, 9 Oct 2022 19:26:38 +0300 Subject: 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 --- Modules/FindGLUT.cmake | 60 ++++++++++++++++---------------------------------- 1 file changed, 19 insertions(+), 41 deletions(-) diff --git a/Modules/FindGLUT.cmake b/Modules/FindGLUT.cmake index 6934089..902c843 100644 --- a/Modules/FindGLUT.cmake +++ b/Modules/FindGLUT.cmake @@ -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) -- cgit v0.12 From a60a33dcb082c029a28f46346e1a21b95f85e4e5 Mon Sep 17 00:00:00 2001 From: leha-bot Date: Thu, 13 Oct 2022 15:03:33 +0300 Subject: FindGLUT: Drop the now-unnecessary ALLOW_SYSTEM_CFLAGS logic Revert commit 8041ca5df0 (FindGLUT: Fix GLUT_INCLUDE_DIRS with pkg-config and /usr/include, 2022-05-11, v3.24.0-rc1~151^2). As the main code path will always do `find_path()` which respects the `CMAKE_FIND_ROOT_PATH_MODE_INCLUDE` variable and will search in system paths depending on that variable. Issue: #23474, #24028 --- Modules/FindGLUT.cmake | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Modules/FindGLUT.cmake b/Modules/FindGLUT.cmake index 902c843..725a1d0 100644 --- a/Modules/FindGLUT.cmake +++ b/Modules/FindGLUT.cmake @@ -72,21 +72,7 @@ get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) # On WIN32 and when using a multiple config generator, pkg-config # is not used as it cannot distinguish between release and debug libraries if(PKG_CONFIG_FOUND AND NOT (_isMultiConfig AND WIN32)) - # Tell pkg-config not to strip any -I flags to make sure GLUT_INCLUDE_DIRS - # will be defined. - if(DEFINED ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS}) - set(_pkgconfig_allow_system_cflags_old "$ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS}") - else() - unset(_pkgconfig_allow_system_cflags_old) - endif() - set(ENV{PKG_CONFIG_ALLOW_SYSTEM_CFLAGS} 1) 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 PC_GLUT_FOUND) pkg_check_modules(PC_GLUT QUIET freeglut) endif() -- cgit v0.12 From a2fc4b62574dbf44dd2ba2d7e8568857a570c3cd Mon Sep 17 00:00:00 2001 From: leha-bot Date: Thu, 13 Oct 2022 15:08:17 +0300 Subject: FindGLUT: Drop the now-unnecessary exclusion of pkg-config for multiconfig Revert commit e0a62b84b5 (FindGLUT: On Windows and with multiple config generator do not use pkg-config, 2022-09-27, v3.25.0-rc1~69^2). We now call `select_library_configurations()` even after using pkg-config, which will handle the absent libraries on Debug/Release configurations. Issue: #24028 --- Modules/FindGLUT.cmake | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Modules/FindGLUT.cmake b/Modules/FindGLUT.cmake index 725a1d0..e0636b2 100644 --- a/Modules/FindGLUT.cmake +++ b/Modules/FindGLUT.cmake @@ -68,14 +68,9 @@ include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package(PkgConfig QUIET) -get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) -# On WIN32 and when using a multiple config generator, pkg-config -# is not used as it cannot distinguish between release and debug libraries -if(PKG_CONFIG_FOUND AND NOT (_isMultiConfig AND WIN32)) - pkg_check_modules(PC_GLUT QUIET glut) - if(NOT PC_GLUT_FOUND) - pkg_check_modules(PC_GLUT QUIET freeglut) - endif() +pkg_check_modules(PC_GLUT QUIET glut) +if(NOT PC_GLUT_FOUND) + pkg_check_modules(PC_GLUT QUIET freeglut) endif() if(WIN32) -- cgit v0.12