FindGLFW3.cmake
5.15 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#.rst:
# FindGLFW3
# ------------
#
# Locate glfw3 library
#
# This module defines
#
# ::
#
# GLFW3_LIBRARIES, the library to link against
# GLFW3_FOUND, if false, do not try to link to FREETYPE
# GLFW3_INCLUDE_DIRS, where to find headers.
# This is the concatenation of the paths:
# GLFW3_INCLUDE_DIR
#
#=============================================================================
# Copyright 2014-2014 Martell Malone
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
# glfw has special requirements for linking (from docs: http://www.glfw.org/docs/latest/build.html)
# MINGW or MSVC + static "glfw3" -> link: opengl32, gdi32 (plus glu32 if use GLU)
# MINGW or MSVC + dynamic "glfw3dll" (but this not true ;) -> -DGLFW_DLL link: no
# UNIX + static -> pkg-config --static --libs
# UNIX + dynamic -> pkg-config --libs
# So... if we find dynamic version, no problems, but if we find static, we need to determine deps
# but cmake can't simply say to us what kind of library it found. So we try to find static version
# first, and then if nothing found, we repeat search for dynamic
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
message(STATUS "PkgConfig found")
else()
message(STATUS "PkgConfig not found, if you have only static glfw library, you build can fail")
endif()
if(PKG_CONFIG_FOUND)
# Save some global stuff that we change, to revert after work has been done
set(_saved_PKG_CONFIG_PATH "$ENV{PKG_CONFIG_PATH}")
set(_saved_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}")
# add /usr/local/lib/pkgconfig to pkg-config search path (some linuxes do not do that, but glfw installs to taht prefix by default)
file(TO_CMAKE_PATH "$ENV{PKG_CONFIG_PATH}" PKG_CONFIG_PATH)
list(APPEND PKG_CONFIG_PATH "/usr/local/lib/pkgconfig")
file(TO_NATIVE_PATH "${PKG_CONFIG_PATH}" new_pkg_config_path)
set(ENV{PKG_CONFIG_PATH} "${new_pkg_config_path}")
# now try to find glfw with pkg-config
pkg_check_modules(PC_GLFW3 glfw3)
if(PC_GLFW3_FOUND)
# try to find static library
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
find_library(GLFW3_STATIC_LIBRARY NAMES glfw3 libglfw3 PATHS ${PC_GLFW3_LIBRARY_DIRS} NO_DEFAULT_PATH)
find_library(GLFW3_STATIC_LIBRARY NAMES glfw3 libglfw3 PATHS ${PC_GLFW3_LIBRARY_DIRS})
# also we include glfw3.h header, not GLFW/glfw3.h :(
find_path(GLFW3_INCLUDE_DIRS glfw3.h PATH_SUFFIXES GLFW PATHS ${PC_GLFW3_INCLUDE_DIRS} NO_DEFAULT_PATH)
find_path(GLFW3_INCLUDE_DIRS glfw3.h PATH_SUFFIXES GLFW PATHS ${PC_GLFW3_INCLUDE_DIRS})
if(GLFW3_STATIC_LIBRARY)
# glfw3 is static
set(GLFW3_LIBRARIES ${PC_GLFW3_STATIC_LIBRARIES})
set(GLFW3_LIBRARY_DIRS ${PC_GLFW3_STATIC_LIBRARY_DIRS})
# We also need to add any other LDFLAGS, but with additional fixup for Apple frameworks :(
if(APPLE)
unset(_is_framework)
foreach(_arg ${PC_GLFW3_STATIC_LDFLAGS_OTHER})
if(_is_framework)
set(var FRAMEWORK_${_arg}_LIBRARY)
find_library(${var} ${_arg})
if(${var})
list(APPEND GLFW3_LIBRARIES ${${var}})
endif()
unset(var)
unset(_is_framework)
else()
if(_arg STREQUAL "-framework")
set(_is_framework 1)
else()
list(APPEND GLFW3_LIBRARIES ${_arg})
endif()
endif()
endforeach()
else(APPLE)
list(APPEND GLFW3_LIBRARIES ${PC_GLFW3_STATIC_LDFLAGS_OTHER})
endif(APPLE)
else()
# glfw3 is dynamic
set(GLFW3_DEFINITIONS -DGLFW_DLL)
set(GLFW3_LIBRARIES ${PC_GLFW3_LIBRARIES})
set(GLFW3_LIBRARY_DIRS ${PC_GLFW3_LIBRARY_DIRS})
endif()
set(GLFW3_FOUND 1)
endif()
# Restore global stuff
set(CMAKE_FIND_LIBRARY_SUFFIXES "${_saved_CMAKE_FIND_LIBRARY_SUFFIXES}")
set(ENV{PKG_CONFIG_PATH} "${_saved_PKG_CONFIG_PATH}")
endif(PKG_CONFIG_FOUND)
# fallback if pkg-config method not work
if(NOT GLFW3_FOUND)
find_path(GLFW3_INCLUDE_DIR glfw3.h
HINTS
ENV GLFW3_DIR
PATH_SUFFIXES include/GLFW include
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
find_library(GLFW3_LIBRARY
NAMES glfw3 libglfw3 glfw
HINTS
ENV GLFW3_DIR
PATH_SUFFIXES lib
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw
/opt/local
/opt/csw
/opt
)
set(GLFW3_INCLUDE_DIRS "${GLFW3_INCLUDE_DIR}")
set(GLFW3_LIBRARIES "${GLFW3_LIBRARY}")
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(GLFW3 DEFAULT_MSG GLFW3_LIBRARIES GLFW3_INCLUDE_DIR)
endif()
mark_as_advanced(GLFW3_INCLUDE_DIR GLFW3_LIBRARIES GLFW3_LIBRARY)