Commit 0da645d4 authored by Kohányi Róbert's avatar Kohányi Róbert Committed by Brad King

FindGLUT: Find debug/release variants on Windows

* Separate find_library calls to find Release and Debug libs.
* Using select_library_configurations to properly populate required
  variables (similar to FindZLIB).
* Setting Release and Debug specific properties
  (IMPORTED_CONFIGURATIONS_<CONFIG> and IMPORTED_LOCATION_<CONFIG>).
* Falling back to setting just IMPORTED_LOCATION if
  GLUT_glut_LIBRARY_RELEASE or GLUT_glut_LIBRARY_DEBUG are not defined.

This enables proper linking on Windows.

Fixes: #17037
parent 6097d8dd
......@@ -34,20 +34,30 @@
# GLUT_Xmu_LIBRARY = the full path to the Xmu library.
# GLUT_Xi_LIBRARY = the full path to the Xi Library.
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
if (WIN32)
find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h
PATHS ${GLUT_ROOT_PATH}/include )
find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut
find_library( GLUT_glut_LIBRARY_RELEASE NAMES glut glut32 freeglut
PATHS
${OPENGL_LIBRARY_DIR}
${GLUT_ROOT_PATH}/Release
)
find_library( GLUT_glut_LIBRARY_DEBUG NAMES freeglutd
PATHS
${OPENGL_LIBRARY_DIR}
${GLUT_ROOT_PATH}/Debug
)
mark_as_advanced(GLUT_glut_LIBRARY_RELEASE GLUT_glut_LIBRARY_DEBUG)
select_library_configurations(GLUT_glut)
else ()
if (APPLE)
find_path(GLUT_INCLUDE_DIR glut.h ${OPENGL_LIBRARY_DIR})
find_library(GLUT_glut_LIBRARY GLUT 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)
if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa)
add_library(GLUT::Cocoa UNKNOWN IMPORTED)
......@@ -72,10 +82,12 @@ else ()
find_library( GLUT_Xi_LIBRARY Xi
/usr/openwin/lib
)
mark_as_advanced(GLUT_Xi_LIBRARY)
find_library( GLUT_Xmu_LIBRARY Xmu
/usr/openwin/lib
)
mark_as_advanced(GLUT_Xmu_LIBRARY)
if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi)
add_library(GLUT::Xi UNKNOWN IMPORTED)
......@@ -104,6 +116,7 @@ else ()
/usr/openwin/lib
${_GLUT_glut_LIB_DIR}
)
mark_as_advanced(GLUT_glut_LIBRARY)
unset(_GLUT_INC_DIR)
unset(_GLUT_glut_LIB_DIR)
......@@ -135,8 +148,24 @@ if (GLUT_FOUND)
set_target_properties(GLUT::GLUT PROPERTIES
IMPORTED_LOCATION "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}")
else()
set_target_properties(GLUT::GLUT PROPERTIES
IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
if(GLUT_glut_LIBRARY_RELEASE)
set_property(TARGET GLUT::GLUT APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(GLUT::GLUT PROPERTIES
IMPORTED_LOCATION_RELEASE "${GLUT_glut_LIBRARY_RELEASE}")
endif()
if(GLUT_glut_LIBRARY_DEBUG)
set_property(TARGET GLUT::GLUT APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(GLUT::GLUT PROPERTIES
IMPORTED_LOCATION_DEBUG "${GLUT_glut_LIBRARY_DEBUG}")
endif()
if(NOT GLUT_glut_LIBRARY_RELEASE AND NOT GLUT_glut_LIBRARY_DEBUG)
set_property(TARGET GLUT::GLUT APPEND PROPERTY
IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
endif()
endif()
if(TARGET GLUT::Xmu)
......@@ -160,9 +189,4 @@ if (GLUT_FOUND)
set (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
endif()
mark_as_advanced(
GLUT_INCLUDE_DIR
GLUT_glut_LIBRARY
GLUT_Xmu_LIBRARY
GLUT_Xi_LIBRARY
)
mark_as_advanced(GLUT_INCLUDE_DIR)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment