Skip to content

Commit

Permalink
FindGLFW3: Use glfw3Config.cmake and mark module as deprecated (#441)
Browse files Browse the repository at this point in the history
* FindGLFW3: Use glfw3Config.cmake and mark module as deprecated

* Update CHANGELOG.md
  • Loading branch information
traversaro authored Feb 13, 2024
1 parent e187cdb commit f8ba554
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 51 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased Patch]

### Deprecated

* FindGLFW3: Use glfw3Config.cmake and mark module as deprecated. Instead of using `find_package(GLFW3)`, please use `find_package(glfw3 NO_MODULE)` and link the `glfw` imported target (https://github.com/robotology/ycm/pull/441).

## [0.16.2] - 2023-12-20

### Added
Expand Down
119 changes: 68 additions & 51 deletions find-modules/FindGLFW3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ FindGLFW3
Find the GLFW3 framework.
This module is deprecated, please use find_package(glfw3 NO_MODULE)
to find glfw3 instead.
IMPORTED Targets
^^^^^^^^^^^^^^^^
This module defines the :prop_tgt:`IMPORTED` target ``GLFW3::GLFW3``,
This module defines the :prop_tgt:`IMPORTED` target ``glfw``,
if GLFW3 has been found.
This module also defines the :prop_tgt:`IMPORTED` target ``GLFW3::GLFW3``,
for backward compatibility with old YCM versions, but support for it will be removed.
Result Variables
^^^^^^^^^^^^^^^^
This module defines the following variables::
This module defines the following deprecated variables::
GLFW3_INCLUDE_DIRS - include directories for GLFW3
GLFW3_LIBRARIES - libraries to link against GLFW3
Expand All @@ -29,61 +35,72 @@ If the library is not found on system paths, the ``GLFW3_ROOT``
environment variable can be used to locate the lbrary.
#]=======================================================================]

include(StandardFindModule)
standard_find_module(GLFW3 glfw3)
message(DEPRECATION "find_package(GLFW3) is deprecated, please use find_package(glfw3 NO_MODULE) and link glfw instead.")

if(NOT GLFW3_FOUND)
find_path(GLFW3_INCLUDE_DIR
DOC "Path to GLFW3 include directory."
NAMES GLFW/glfw3.h
PATH_SUFFIXES include
PATHS /usr/
/usr/local/
${GLFW3_ROOT_DIR}
ENV GLFW3_ROOT)

find_library(GLFW3_GLFW_LIBRARY
DOC "Absolute path to GLFW3 library."
NAMES glfw3
glfw3dll
PATH_SUFFIXES lib
lib-vc2010
find_package(glfw3 NO_MODULE QUIET)

if(glfw3_FOUND)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLFW3
REQUIRED_VARS glfw3_FOUND)
else()
include(StandardFindModule)
standard_find_module(GLFW3 glfw3)

if(NOT GLFW3_FOUND)
find_path(GLFW3_INCLUDE_DIR
DOC "Path to GLFW3 include directory."
NAMES GLFW/glfw3.h
PATH_SUFFIXES include
PATHS /usr/
/usr/local/
${GLFW3_ROOT_DIR}
ENV GLFW3_ROOT)
if(WIN32)
find_library(GLFW3_OPENGL_LIBRARY
NAMES OpenGL32
PATHS "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Lib"
"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.1A\\Lib")
endif()

set(GLFW3_GLFW_glfw3_h "${GLFW3_INCLUDE_DIR}/GLFW/glfw3.h")
if(GLFW3_INCLUDE_DIR AND EXISTS "${GLFW3_GLFW_glfw3_h}")
file(STRINGS "${GLFW3_GLFW_glfw3_h}" GLFW3_GLFW_glfw3_h_CONTENTS
REGEX "^#[\t ]*define[\t ]+GLFW_VERSION_(MAJOR|MINOR|REVISION)[\t ]+[0-9]+$")

foreach(_part MAJOR MINOR REVISION)
string(REGEX REPLACE ".*#[\t ]*define[ \t]+GLFW_VERSION_${_part}[ \t]+([0-9]+).*" "\\1"
GLFW3_VERSION_${_part} "${GLFW3_GLFW_glfw3_h_CONTENTS}")
endforeach(_part)

set(GLFW3_VERSION_STRING "${GLFW3_VERSION_MAJOR}.${GLFW3_VERSION_MINOR}.${GLFW3_VERSION_REVISION}")

endif()

set(GLFW3_INCLUDE_DIRS "${GLFW3_INCLUDE_DIR}")
set(GLFW3_LIBRARIES "${GLFW3_GLFW_LIBRARY}")
if(WIN32)
list(APPEND GLFW3_LIBRARIES "${GLFW3_OPENGL_LIBRARY}")

find_library(GLFW3_GLFW_LIBRARY
DOC "Absolute path to GLFW3 library."
NAMES glfw3
glfw3dll
PATH_SUFFIXES lib
lib-vc2010
PATHS /usr/
/usr/local/
${GLFW3_ROOT_DIR}
ENV GLFW3_ROOT)
if(WIN32)
find_library(GLFW3_OPENGL_LIBRARY
NAMES OpenGL32
PATHS "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Lib"
"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.1A\\Lib")
endif()

set(GLFW3_GLFW_glfw3_h "${GLFW3_INCLUDE_DIR}/GLFW/glfw3.h")
if(GLFW3_INCLUDE_DIR AND EXISTS "${GLFW3_GLFW_glfw3_h}")
file(STRINGS "${GLFW3_GLFW_glfw3_h}" GLFW3_GLFW_glfw3_h_CONTENTS
REGEX "^#[\t ]*define[\t ]+GLFW_VERSION_(MAJOR|MINOR|REVISION)[\t ]+[0-9]+$")

foreach(_part MAJOR MINOR REVISION)
string(REGEX REPLACE ".*#[\t ]*define[ \t]+GLFW_VERSION_${_part}[ \t]+([0-9]+).*" "\\1"
GLFW3_VERSION_${_part} "${GLFW3_GLFW_glfw3_h_CONTENTS}")
endforeach(_part)

set(GLFW3_VERSION_STRING "${GLFW3_VERSION_MAJOR}.${GLFW3_VERSION_MINOR}.${GLFW3_VERSION_REVISION}")

endif()

set(GLFW3_INCLUDE_DIRS "${GLFW3_INCLUDE_DIR}")
set(GLFW3_LIBRARIES "${GLFW3_GLFW_LIBRARY}")
if(WIN32)
list(APPEND GLFW3_LIBRARIES "${GLFW3_OPENGL_LIBRARY}")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLFW3
REQUIRED_VARS GLFW3_LIBRARIES
GLFW3_INCLUDE_DIRS
VERSION_VAR GLFW3_VERSION_STRING)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLFW3
REQUIRED_VARS GLFW3_LIBRARIES
GLFW3_INCLUDE_DIRS
VERSION_VAR GLFW3_VERSION_STRING)
endif()

# Set package properties if FeatureSummary was included
Expand Down

0 comments on commit f8ba554

Please sign in to comment.