summaryrefslogtreecommitdiff
path: root/Modules/FindGLUT.cmake
diff options
context:
space:
mode:
authorChristopher Degawa <ccom@randomderp.com>2021-06-11 15:38:44 -0500
committerChristopher Degawa <ccom@randomderp.com>2021-07-02 13:33:18 -0500
commitf90d15458a9a98180fcc95158f2ab5d2b1ad3152 (patch)
tree3e266619825398dd8c8e66a43ce048701b5ca211 /Modules/FindGLUT.cmake
parentf3f040118736eb793a2615247ed7e0ed5d5bd939 (diff)
downloadcmake-f90d15458a9a98180fcc95158f2ab5d2b1ad3152.tar.gz
FindGLUT: Use pkg-config to find flags if available
FindGLUT fails to properly link a static libglut as it does not list the dependencies needed. Signed-off-by: Christopher Degawa <ccom@randomderp.com>
Diffstat (limited to 'Modules/FindGLUT.cmake')
-rw-r--r--Modules/FindGLUT.cmake36
1 files changed, 35 insertions, 1 deletions
diff --git a/Modules/FindGLUT.cmake b/Modules/FindGLUT.cmake
index 53ff727ed2..dd0975d395 100644
--- a/Modules/FindGLUT.cmake
+++ b/Modules/FindGLUT.cmake
@@ -41,6 +41,41 @@ Also defined, but not for general use are:
#]=======================================================================]
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_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)
+if(PKG_CONFIG_FOUND)
+ pkg_check_modules(GLUT glut)
+ if(GLUT_FOUND)
+ _add_glut_target_simple()
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_FOUND)
+ return()
+ endif()
+endif()
if(WIN32)
find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
@@ -126,7 +161,6 @@ else()
endif()
mark_as_advanced(GLUT_glut_LIBRARY)
-include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR)
if (GLUT_FOUND)