|
| 1 | +#.rst: |
| 2 | +# FindGLFW |
| 3 | +# ------------ |
| 4 | +# |
| 5 | +# Locate glfw3 library |
| 6 | +# |
| 7 | +# This module defines |
| 8 | +# |
| 9 | +# :: |
| 10 | +# |
| 11 | +# GLFW_LIBRARIES, the library to link against |
| 12 | +# GLFW_FOUND, if false, do not try to link to FREETYPE |
| 13 | +# GLFW_INCLUDE_DIRS, where to find headers. |
| 14 | +# This is the concatenation of the paths: |
| 15 | +# GLFW_INCLUDE_DIR |
| 16 | +# |
| 17 | +#============================================================================= |
| 18 | +# Copyright 2014-2014 Martell Malone |
| 19 | +# |
| 20 | +# Distributed under the OSI-approved BSD License (the "License"); |
| 21 | +# see accompanying file Copyright.txt for details. |
| 22 | +# |
| 23 | +# This software is distributed WITHOUT ANY WARRANTY; without even the |
| 24 | +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 25 | +# See the License for more information. |
| 26 | +#============================================================================= |
| 27 | +# (To distribute this file outside of CMake, substitute the full |
| 28 | +# License text for the above reference.) |
| 29 | + |
| 30 | +# glfw has special requirements for linking (from docs: http://www.glfw.org/docs/latest/build.html) |
| 31 | +# MINGW or MSVC + static "glfw3" -> link: opengl32, gdi32 (plus glu32 if use GLU) |
| 32 | +# MINGW or MSVC + dynamic "glfw3dll" (but this not true ;) -> -DGLFW_DLL link: no |
| 33 | +# UNIX + static -> pkg-config --static --libs |
| 34 | +# UNIX + dynamic -> pkg-config --libs |
| 35 | +# So... if we find dynamic version, no problems, but if we find static, we need to determine deps |
| 36 | +# but cmake can't simply say to us what kind of library it found. So we try to find static version |
| 37 | +# first, and then if nothing found, we repeat search for dynamic |
| 38 | + |
| 39 | +find_package(PkgConfig) |
| 40 | +if(PKG_CONFIG_FOUND) |
| 41 | + message(STATUS "PkgConfig found") |
| 42 | +else() |
| 43 | + message(STATUS "PkgConfig not found, if you have only static glfw library, you build can fail") |
| 44 | +endif() |
| 45 | + |
| 46 | +if(PKG_CONFIG_FOUND) |
| 47 | + # Save some global stuff that we change, to revert after work has been done |
| 48 | + set(_saved_PKG_CONFIG_PATH "$ENV{PKG_CONFIG_PATH}") |
| 49 | + set(_saved_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}") |
| 50 | + |
| 51 | + # add /usr/local/lib/pkgconfig to pkg-config search path (some linuxes do not do that, but glfw installs to taht prefix by default) |
| 52 | + file(TO_CMAKE_PATH "$ENV{PKG_CONFIG_PATH}" PKG_CONFIG_PATH) |
| 53 | + list(APPEND PKG_CONFIG_PATH "/usr/local/lib/pkgconfig") |
| 54 | + file(TO_NATIVE_PATH "${PKG_CONFIG_PATH}" new_pkg_config_path) |
| 55 | + set(ENV{PKG_CONFIG_PATH} "${new_pkg_config_path}") |
| 56 | + |
| 57 | + # now try to find glfw with pkg-config |
| 58 | + pkg_check_modules(PC_GLFW3 glfw3) |
| 59 | + if(PC_GLFW3_FOUND) |
| 60 | + |
| 61 | + # try to find static library |
| 62 | + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX}) |
| 63 | + find_library(GLFW3_STATIC_LIBRARY NAMES glfw3 libglfw3 PATHS ${PC_GLFW3_LIBRARY_DIRS} NO_DEFAULT_PATH) |
| 64 | + find_library(GLFW3_STATIC_LIBRARY NAMES glfw3 libglfw3 PATHS ${PC_GLFW3_LIBRARY_DIRS}) |
| 65 | + # also we include glfw3.h header, not GLFW/glfw3.h :( |
| 66 | + find_path(GLFW3_INCLUDE_DIRS glfw3.h GLFW/glfw PATH_SUFFIXES GLFW PATHS ${PC_GLFW3_INCLUDE_DIRS} NO_DEFAULT_PATH) |
| 67 | + find_path(GLFW3_INCLUDE_DIRS glfw3.h PATH_SUFFIXES GLFW PATHS ${PC_GLFW3_INCLUDE_DIRS}) |
| 68 | +MESSAGE("${GLFW3_STATIC_LIBRARY}") |
| 69 | +MESSAGE(${GLFW3_STATIC_LIBRARY}) |
| 70 | + if(GLFW3_STATIC_LIBRARY) |
| 71 | + # glfw3 is static |
| 72 | + set(GLFW_LIBRARIES ${PC_GLFW3_STATIC_LIBRARIES}) |
| 73 | + set(GLFW_LIBRARY_DIRS ${PC_GLFW3_STATIC_LIBRARY_DIRS}) |
| 74 | + |
| 75 | + # We also need to add any other LDFLAGS, but with additional fixup for Apple frameworks :( |
| 76 | + if(APPLE) |
| 77 | + unset(_is_framework) |
| 78 | + foreach(_arg ${PC_GLFW3_STATIC_LDFLAGS_OTHER}) |
| 79 | + if(_is_framework) |
| 80 | + set(var FRAMEWORK_${_arg}_LIBRARY) |
| 81 | + find_library(${var} ${_arg}) |
| 82 | + if(${var}) |
| 83 | + list(APPEND GLFW_LIBRARIES ${${var}}) |
| 84 | + endif() |
| 85 | + unset(var) |
| 86 | + unset(_is_framework) |
| 87 | + else() |
| 88 | + if(_arg STREQUAL "-framework") |
| 89 | + set(_is_framework 1) |
| 90 | + else() |
| 91 | + list(APPEND GLFW_LIBRARIES ${_arg}) |
| 92 | + endif() |
| 93 | + endif() |
| 94 | + endforeach() |
| 95 | + else(APPLE) |
| 96 | + list(APPEND GLFW_LIBRARIES ${PC_GLFW3_STATIC_LDFLAGS_OTHER}) |
| 97 | + endif(APPLE) |
| 98 | + |
| 99 | + else() |
| 100 | + # glfw3 is dynamic |
| 101 | + set(GLFW_DEFINITIONS -DGLFW_DLL) |
| 102 | + set(GLFW_LIBRARIES ${PC_GLFW3_LIBRARIES}) |
| 103 | + set(GLFW_LIBRARY_DIRS ${PC_GLFW3_LIBRARY_DIRS}) |
| 104 | + |
| 105 | + endif() |
| 106 | + set(GLFW3_FOUND 1) |
| 107 | + |
| 108 | + endif() |
| 109 | + |
| 110 | + # Restore global stuff |
| 111 | + set(CMAKE_FIND_LIBRARY_SUFFIXES "${_saved_CMAKE_FIND_LIBRARY_SUFFIXES}") |
| 112 | + set(ENV{PKG_CONFIG_PATH} "${_saved_PKG_CONFIG_PATH}") |
| 113 | +endif(PKG_CONFIG_FOUND) |
| 114 | + |
| 115 | +# fallback if pkg-config method not work |
| 116 | +if(NOT GLFW3_FOUND) |
| 117 | + |
| 118 | + find_path(GLFW3_INCLUDE_DIR GLFW/glfw3.h |
| 119 | + $ENV{GLFW_ROOT} |
| 120 | + HINTS |
| 121 | + ENV GLFW3_DIR |
| 122 | + PATH_SUFFIXES include/GLFW include |
| 123 | + PATHS |
| 124 | + /opt/glfw3/current/include/ |
| 125 | + /usr/include/ |
| 126 | + /usr/local/include/ |
| 127 | + ~/Library/Frameworks |
| 128 | + /Library/Frameworks |
| 129 | + /usr/local |
| 130 | + /usr |
| 131 | + /sw # Fink |
| 132 | + /opt/local # DarwinPorts |
| 133 | + /opt/csw # Blastwave |
| 134 | + /opt |
| 135 | + /opt/glfw3/current/include/ |
| 136 | + # By default headers are under GLFW subfolder |
| 137 | + /usr/include/GLFW |
| 138 | + /usr/local/include/GLFW |
| 139 | + ${GLOBAL_EXT_DIR}/glfw/include |
| 140 | + ${GLFW_ROOT_DIR}/include/ # added by ptr |
| 141 | +) |
| 142 | + find_library(GLFW3_LIBRARY |
| 143 | + NAMES glfw3 libglfw3 glfw glfw3dll |
| 144 | + HINTS |
| 145 | + ENV GLFW3_DIR |
| 146 | + PATH_SUFFIXES lib |
| 147 | + PATHS |
| 148 | + ~/Library/Frameworks |
| 149 | + /Library/Frameworks |
| 150 | + /usr/local |
| 151 | + /usr |
| 152 | + /sw |
| 153 | + /opt/local |
| 154 | + /opt/csw |
| 155 | + /opt |
| 156 | + /opt/glfw3/current/lib |
| 157 | + ) |
| 158 | + |
| 159 | +IF(MSVC) |
| 160 | + # VisualStudio needs a debug version |
| 161 | + |
| 162 | + find_library(GLFW3_LIBRARY_DEBUG |
| 163 | + NAMES glfw3d libglfw3d glfwd glfw3dlld |
| 164 | + HINTS |
| 165 | + ENV GLFW3_DIR |
| 166 | + PATH_SUFFIXES lib |
| 167 | + PATHS |
| 168 | + ~/Library/Frameworks |
| 169 | + /Library/Frameworks |
| 170 | + /usr/local |
| 171 | + /usr |
| 172 | + /sw |
| 173 | + /opt/local |
| 174 | + /opt/csw |
| 175 | + /opt |
| 176 | + /opt/glfw3/current/lib |
| 177 | + ) |
| 178 | + |
| 179 | + IF(GLFW3_LIBRARY_DEBUG AND GLFW3_LIBRARY) |
| 180 | + SET(GLFW3_LIBRARIES optimized ${GLFW3_LIBRARY} debug ${GLFW3_LIBRARY_DEBUG} ) |
| 181 | + SET(GLFW_LIBRARIES optimized ${GLFW3_LIBRARY} debug ${GLFW3_LIBRARY_DEBUG} ) |
| 182 | + ENDIF(GLFW3_LIBRARY_DEBUG AND GLFW3_LIBRARY) |
| 183 | + |
| 184 | + FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLFW3 DEFAULT_MSG GLFW3_LIBRARY GLFW3_LIBRARY_DEBUG GLFW3_INCLUDE_DIR) |
| 185 | + |
| 186 | + MARK_AS_ADVANCED(GLFW3_LIBRARY GLFW3_LIBRARY_DEBUG GLFW3_INCLUDE_DIR) |
| 187 | + |
| 188 | +ELSE(MSVC) |
| 189 | + |
| 190 | + set(GLFW_LIBRARIES "${GLFW3_LIBRARY}") |
| 191 | + set(GLFW3_LIBRARIES "${GLFW3_LIBRARY}") |
| 192 | + |
| 193 | + include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) |
| 194 | + find_package_handle_standard_args(GLFW3 DEFAULT_MSG GLFW3_LIBRARIES GLFW3_INCLUDE_DIRS) |
| 195 | + |
| 196 | +ENDIF(MSVC) |
| 197 | + |
| 198 | + set(GLFW_INCLUDE_DIRS "${GLFW3_INCLUDE_DIR}") |
| 199 | + |
| 200 | +endif() |
| 201 | + |
| 202 | +mark_as_advanced(GLFW_INCLUDE_DIR GLFW_LIBRARIES GLFW_LIBRARY) |
0 commit comments