FindOpenGL3.cmake 1.42 KB
Newer Older
Bastian Krayer's avatar
Bastian Krayer committed
1
2
3
4
5
6
7
8
9
#
# Try to find OpenGL and include path.
# Once done this will define
#
# OpenGL3_FOUND
# OpenGL3_INCLUDE_PATH
# OpenGL3_LIBRARY
# 

Bastian Krayer's avatar
Bastian Krayer committed
10
11
12
IF(DEFINED ENV{OpenGL_ROOT})
	file(TO_CMAKE_PATH $ENV{OpenGL_ROOT} OpenGL_ROOT_ENV)
ENDIF()
Bastian Krayer's avatar
Bastian Krayer committed
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

IF (WIN32)
  FIND_PATH( OpenGL3_INCLUDE_PATH 
    NAMES GL/glcorearb.h
    PATHS ${OpenGL_ROOT_ENV}/include/
  )
  SET(OpenGL3_LIBRARY OpenGL32)

ELSEIF (APPLE)
 FIND_PATH(OpenGL3_INCLUDE_PATH OpenGL/gl3.h 
   OpenGL_ROOT_ENV/OpenGL/)
 SET(OpenGL3_LIBRARY "-framework Cocoa -framework OpenGL -framework IOKit" CACHE STRING "OpenGL lib for OSX")
 
ELSE()

SET(OpenGL3_LIBRARY "GL" CACHE STRING "OpenGL lib for Linux")
    FIND_PATH(OpenGL3_INCLUDE_PATH GL/gl.h
      /usr/share/doc/NVIDIA_GLX-1.0/include
      /usr/openwin/share/include
      /opt/graphics/OpenGL/include /usr/X11R6/include
    )
ENDIF ()

SET(OpenGL3_FOUND "NO")
IF (OpenGL3_INCLUDE_PATH)
	SET(OpenGL3_LIBRARIES ${OpenGL3_LIBRARY})
	SET(OpenGL3_FOUND "YES")
	IF (WIN32)
		LIST(APPEND
			OpenGL3_LIBRARIES
			opengl32
		)
	ENDIF()
	
    message("EXTERNAL LIBRARY 'OpenGL3' FOUND")
ELSE()
    message("ERROR: EXTERNAL LIBRARY 'OpenGL3' NOT FOUND")
ENDIF (OpenGL3_INCLUDE_PATH)

if(OpenGL3_FOUND AND NOT TARGET OpenGL3::opengl3)
    add_library(OpenGL3::opengl3 INTERFACE IMPORTED)
    set_target_properties(OpenGL3::opengl3 PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${OpenGL3_INCLUDE_PATH}"
		INTERFACE_LINK_LIBRARIES "${OpenGL3_LIBRARIES}" 
    )
endif()