FindGLFW3.cmake 5.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# FindGLFW
# Mostly adapted from glfw's CMakeLists.txt

find_package(OpenGL)
find_package(Threads)

if (WIN32)
	set(_GLFW_WIN32 1)
	set(_GLFW_WGL 1)
elseif (APPLE)
	set(_GLFW_COCOA 1)
	set(_GLFW_NSGL 1)
elseif (UNIX)
	set(_GLFW_X11 1)
	set(_GLFW_GLX 1)
else()
17
    message(WARNING "No supported platform was detected")
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
endif()

#--------------------------------------------------------------------
# Use Win32 for window creation
#--------------------------------------------------------------------
if (_GLFW_WIN32)
	list(APPEND GLFW3_LIBRARIES winmm)

	# HACK: When building on MinGW, WINVER and UNICODE need to be defined before
	# the inclusion of stddef.h (by glfw3.h), which is itself included before
	# win32_platform.h.  We define them here until a saner solution can be found
	# NOTE: MinGW-w64 and Visual C++ do /not/ need this hack.
	# add_definitions(-DUNICODE)
	# add_definitions(-DWINVER=0x0501)
endif()

#--------------------------------------------------------------------
# Use WGL for context creation
#--------------------------------------------------------------------
if (_GLFW_WGL)
	list(APPEND GLFW3_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR})
	list(APPEND GLFW3_LIBRARIES ${OPENGL_gl_LIBRARY})
endif()

#--------------------------------------------------------------------
# Use X11 for window creation
#--------------------------------------------------------------------
if (_GLFW_X11)

47
    find_package(X11 REQUIRED)
48 49 50 51 52 53 54 55 56 57

	# Set up library and include paths
	list(APPEND GLFW3_INCLUDE_DIRS ${X11_X11_INCLUDE_PATH})
	list(APPEND GLFW3_LIBRARIES ${X11_X11_LIB} ${CMAKE_THREAD_LIBS_INIT})
	if (UNIX AND NOT APPLE)
		list(APPEND GLFW3_LIBRARIES ${RT_LIBRARY})
	endif()

	# Check for XRandR (modern resolution switching and gamma control)
	if (NOT X11_Xrandr_FOUND)
58
        message(WARNING "The RandR library and headers were not found")
59 60 61 62 63 64
	endif()

	list(APPEND GLFW3_INCLUDE_DIRS ${X11_Xrandr_INCLUDE_PATH})
	list(APPEND GLFW3_LIBRARIES ${X11_Xrandr_LIB})

	# Check for XInput (high-resolution cursor motion)
65 66
    if (NOT X11_Xinput_FOUND)
        message(WARNING "The XInput library and headers were not found")
67 68 69 70 71 72 73 74 75 76 77 78 79
	endif()

	list(APPEND GLFW3_INCLUDE_DIRS ${X11_Xinput_INCLUDE_PATH})

	if (X11_Xinput_LIB)
		list(APPEND GLFW3_LIBRARIES ${X11_Xinput_LIB})
	else()
		# Backwards compatibility (bug in CMake 2.8.7)
		list(APPEND GLFW3_LIBRARIES Xi)
	endif()

	# Check for Xf86VidMode (fallback gamma control)
	if (NOT X11_xf86vmode_FOUND)
80
        message(WARNING "The Xf86VidMode library and headers were not found")
81 82 83 84 85 86 87 88 89 90 91 92 93
	endif()

	list(APPEND GLFW3_INCLUDE_DIRS ${X11_xf86vmode_INCLUDE_PATH})

	if (X11_Xxf86vm_LIB)
		list(APPEND GLFW3_LIBRARIES ${X11_Xxf86vm_LIB})
	else()
		# Backwards compatibility (see CMake bug 0006976)
		list(APPEND GLFW3_LIBRARIES Xxf86vm)
	endif()

	# Check for Xkb (X keyboard extension)
	if (NOT X11_Xkb_FOUND)
94
        message(WARNING "The X keyboard extension headers were not found")
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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
	endif() 

	list(APPEND glfw_INCLUDE_DIR ${X11_Xkb_INCLUDE_PATH})

	find_library(RT_LIBRARY rt)
	mark_as_advanced(RT_LIBRARY)
	if (RT_LIBRARY)
		list(APPEND GLFW3_LIBRARIES ${RT_LIBRARY})
	endif()

	find_library(MATH_LIBRARY m)
	mark_as_advanced(MATH_LIBRARY)
	if (MATH_LIBRARY)
		list(APPEND GLFW3_LIBRARIES ${MATH_LIBRARY})
	endif()

endif()

#--------------------------------------------------------------------
# Use GLX for context creation
#--------------------------------------------------------------------
if (_GLFW_GLX)
	list(APPEND GLFW3_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR})
	list(APPEND GLFW3_LIBRARIES ${OPENGL_gl_LIBRARY})
	
	            list(APPEND glfw_LIBRARIES ${CMAKE_DL_LIBS})

endif()

#--------------------------------------------------------------------
# Use EGL for context creation
#--------------------------------------------------------------------
#if (_GLFW_EGL)
#
#    list(APPEND GLFW3_INCLUDE_DIRS ${EGL_INCLUDE_DIR})
#    list(APPEND GLFW3_LIBRARIES ${EGL_LIBRARY})
#
#    if (UNIX)
#        set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} egl")
#    endif()
#
#    if (_GLFW_USE_OPENGL)
#        list(APPEND GLFW3_LIBRARIES ${OPENGL_gl_LIBRARY})
#        list(APPEND GLFW3_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR})
#        set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} gl")
#    elseif (_GLFW_USE_GLESV1)
#        list(APPEND GLFW3_LIBRARIES ${GLESv1_LIBRARY})
#        list(APPEND GLFW3_INCLUDE_DIRS ${GLESv1_INCLUDE_DIR})
#        set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} glesv1_cm")
#    elseif (_GLFW_USE_GLESV2)
#        list(APPEND GLFW3_LIBRARIES ${GLESv2_LIBRARY})
#        list(APPEND GLFW3_INCLUDE_DIRS ${GLESv2_INCLUDE_DIR})
#        set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} glesv2")
#    endif()
#
#endif()

#--------------------------------------------------------------------
# Use Cocoa for window creation and NSOpenGL for context creation
#--------------------------------------------------------------------
if (_GLFW_COCOA AND _GLFW_NSGL)
        
    # Set up library and include paths
    find_library(COCOA_FRAMEWORK Cocoa)
    find_library(IOKIT_FRAMEWORK IOKit)
    find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation)
    find_library(CORE_VIDEO_FRAMEWORK CoreVideo)
    list(APPEND GLFW3_LIBRARIES ${COCOA_FRAMEWORK}
                               ${OPENGL_gl_LIBRARY}
                               ${IOKIT_FRAMEWORK}
                               ${CORE_FOUNDATION_FRAMEWORK}
                               ${CORE_VIDEO_FRAMEWORK})

    set(GLFW3_PKG_DEPS "")
    set(GLFW3_PKG_LIBS "-framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation -framework CoreVideo")
endif()


find_path(GLFW3_INCLUDE_DIR GLFW/glfw3.h)
find_library(GLFW3_LIBRARY glfw3)

set(GLFW3_INCLUDE_DIRS "${GLFW3_INCLUDE_DIR};${GLFW3_INCLUDE_DIRS}")
set(GLFW3_LIBRARIES "${GLFW3_LIBRARY};${GLFW3_LIBRARIES}")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLFW3 DEFAULT_MSG
	GLFW3_INCLUDE_DIR GLFW3_LIBRARY GLFW3_INCLUDE_DIRS GLFW3_LIBRARIES)