forked from rpavlik/cmake-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindGLM.cmake
120 lines (105 loc) · 3.51 KB
/
FindGLM.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# - Find GLM
# Find the GLM header-only library
#
# GLM::GLM - Interface target created if GLM was found.
#
# GLM_FOUND - True if GLM was found.
#
# Original Author:
# 2019, 2021 Ryan Pavlik <[email protected]> <[email protected]>
#
# Copyright 2019, 2021, Collabora, Ltd.
#
# SPDX-License-Identifier: BSL-1.0
set(GLM_ROOT_DIR
"${GLM_ROOT_DIR}"
CACHE PATH "Directory to search for GLM")
option(GLM_ATTEMPT_CMAKE_MODULE
"Should we attempt to use GLM's own CMake module for configuration?" ON)
mark_as_advanced(GLM_ATTEMPT_CMAKE_MODULE)
if(GLM_ATTEMPT_CMAKE_MODULE AND NOT glm_FOUND)
# Look for a CMake config file
find_package(glm QUIET NO_MODULE)
endif()
# Ask pkg-config for hints
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
set(_old_prefix_path "${CMAKE_PREFIX_PATH}")
# So pkg-config uses GLM_ROOT_DIR too.
if(GLM_ROOT_DIR)
list(APPEND CMAKE_PREFIX_PATH ${GLM_ROOT_DIR})
endif()
if(GLM_FIND_VERSION)
set(_GLM_FIND_VERSION_EXT ">=${GLM_FIND_VERSION}")
else()
unset(_GLM_FIND_VERSION_EXT)
endif()
pkg_check_modules(PC_GLM QUIET glm${_GLM_FIND_VERSION_EXT})
# Restore
set(CMAKE_PREFIX_PATH "${_old_prefix_path}")
# Use pkg-config's version if we have it.
if(PC_GLM_FOUND
AND PC_GLM_VERSION
AND GLM_FIND_VERSION
AND NOT GLM_VERSION)
set(GLM_VERSION ${PC_GLM_VERSION})
endif()
endif()
find_path(
GLM_INCLUDE_DIR
NAMES glm/glm.hpp
PATHS "${GLM_ROOT_DIR}"
PATH_SUFFIXES include
HINTS ${PC_GLM_INCLUDE_DIRS} ${GLM_INCLUDE_DIRS})
if(GLM_INCLUDE_DIR AND NOT GLM_VERSION)
# Parse the header to get the version, if we can
file(STRINGS "${GLM_INCLUDE_DIR}/glm/detail/setup.hpp" _glm_header_contents
REGEX "GLM_VERSION_(MAJOR|MINOR|PATCH|REVISION)")
foreach(_line IN LISTS _glm_header_contents)
if("${_line}" MATCHES
"GLM_VERSION_(MAJOR|MINOR|PATCH|REVISION)[^0-9]+([0-9]+)")
set(VERSION_COMPONENT "${CMAKE_MATCH_1}")
set(GLM_VERSION_${VERSION_COMPONENT} "${CMAKE_MATCH_2}")
endif()
endforeach()
if(DEFINED GLM_VERSION_MAJOR)
set(GLM_VERSION "${GLM_VERSION_MAJOR}")
if(DEFINED GLM_VERSION_MINOR)
string(APPEND GLM_VERSION . ${GLM_VERSION_MINOR})
if(DEFINED GLM_VERSION_PATCH)
string(APPEND GLM_VERSION . ${GLM_VERSION_PATCH})
if(DEFINED GLM_VERSION_REVISION)
string(APPEND GLM_VERSION . ${GLM_VERSION_REVISION})
endif()
endif()
endif()
endif()
endif()
if(GLM_VERSION)
set(_version_arg VERSION_VAR GLM_VERSION)
else()
unset(_version_arg)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLM REQUIRED_VARS GLM_INCLUDE_DIR
${_version_arg})
if(GLM_FOUND AND NOT TARGET GLM::GLM)
if(TARGET glm::glm)
add_library(GLM::GLM ALIAS glm::glm)
else()
add_library(GLM::GLM INTERFACE)
set_target_properties(GLM::GLM PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${GLM_INCLUDE_DIR}")
endif()
endif()
if(GLM_FOUND)
mark_as_advanced(GLM_ROOT_DIR)
endif()
mark_as_advanced(GLM_INCLUDE_DIR)
include(FeatureSummary)
set_package_properties(
GLM PROPERTIES
URL "https://github.com/g-truc/glm"
DESCRIPTION
"A header-only C++ mathematics library for graphics software based on the OpenGL Shading Language (GLSL) specifications."
)