CMakeLists.txt 4.53 KB
Newer Older
Michel Zou's avatar
Michel Zou committed
1
2
3
if ( NOT DEFINED CMAKE_BUILD_TYPE )
  set( CMAKE_BUILD_TYPE Release CACHE STRING "Build type" )
endif ()
Togo Nishigaki's avatar
Togo Nishigaki committed
4

Michel Zou's avatar
Michel Zou committed
5
project (glew)
Togo Nishigaki's avatar
Togo Nishigaki committed
6

Michel Zou's avatar
Michel Zou committed
7
cmake_minimum_required (VERSION 2.4)
Togo Nishigaki's avatar
Togo Nishigaki committed
8

Michel Zou's avatar
Michel Zou committed
9
10
11
if (COMMAND cmake_policy)
  cmake_policy (SET CMP0003 NEW)
endif()
12

Tamas Kenez's avatar
Tamas Kenez committed
13
14
set(CMAKE_DEBUG_POSTFIX d)

Michel Zou's avatar
Michel Zou committed
15
option (BUILD_UTILS "utilities" ON)
Togo Nishigaki's avatar
Togo Nishigaki committed
16

17
18
set (GLEW_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../..)

19
20
21
22
23
24
25
26
27
# get version from config/version
file (STRINGS ${GLEW_DIR}/config/version  _VERSION_MAJOR_STRING REGEX "GLEW_MAJOR[ ]*=[ ]*[0-9]+.*")
string (REGEX REPLACE "GLEW_MAJOR[ ]*=[ ]*([0-9]+)" "\\1" CPACK_PACKAGE_VERSION_MAJOR ${_VERSION_MAJOR_STRING})
file (STRINGS ${GLEW_DIR}/config/version  _VERSION_MINOR_STRING REGEX "GLEW_MINOR[ ]*=[ ]*[0-9]+.*")
string (REGEX REPLACE "GLEW_MINOR[ ]*=[ ]*([0-9]+)" "\\1" CPACK_PACKAGE_VERSION_MINOR ${_VERSION_MINOR_STRING})
file (STRINGS ${GLEW_DIR}/config/version  _VERSION_PATCH_STRING REGEX "GLEW_MICRO[ ]*=[ ]*[0-9]+.*")
string (REGEX REPLACE "GLEW_MICRO[ ]*=[ ]*([0-9]+)" "\\1" CPACK_PACKAGE_VERSION_PATCH ${_VERSION_PATCH_STRING})
set (GLEW_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})

Michel Zou's avatar
Michel Zou committed
28
29
30
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
Togo Nishigaki's avatar
Togo Nishigaki committed
31

Michel Zou's avatar
Michel Zou committed
32
if (WIN32)
Michel Zou's avatar
Michel Zou committed
33
  set (GLEW_LIB_NAME glew32)
Michel Zou's avatar
Michel Zou committed
34
else ()
Michel Zou's avatar
Michel Zou committed
35
36
  set (GLEW_LIB_NAME GLEW)
  set (DLL_PREFIX lib)
Michel Zou's avatar
Michel Zou committed
37
endif ()
38

Michel Zou's avatar
Michel Zou committed
39
40
find_package (OpenGL REQUIRED)
set (GLEW_LIBRARIES ${OPENGL_LIBRARIES})
41

42
add_definitions (-DGLEW_NO_GLU)
Togo Nishigaki's avatar
Togo Nishigaki committed
43

44
include_directories (${GLEW_DIR}/include)
Togo Nishigaki's avatar
Togo Nishigaki committed
45

46
add_library (glew SHARED ${GLEW_DIR}/src/glew.c)
47
set_target_properties (glew PROPERTIES COMPILE_DEFINITIONS "GLEW_BUILD" OUTPUT_NAME "${GLEW_LIB_NAME}" PREFIX "${DLL_PREFIX}")
48
add_library (glew_s STATIC ${GLEW_DIR}/src/glew.c)
49
set_target_properties (glew_s PROPERTIES COMPILE_DEFINITIONS "GLEW_STATIC" OUTPUT_NAME "${GLEW_LIB_NAME}" PREFIX lib)
Michel Zou's avatar
Michel Zou committed
50
51
52
target_link_libraries (glew ${GLEW_LIBRARIES})
target_link_libraries (glew_s ${GLEW_LIBRARIES})

53
add_library(glewmx SHARED ${GLEW_DIR}/src/glew.c )
54
set_target_properties (glewmx PROPERTIES COMPILE_DEFINITIONS "GLEW_BUILD;GLEW_MX" OUTPUT_NAME "${GLEW_LIB_NAME}mx" PREFIX "${DLL_PREFIX}")
55
add_library(glewmx_s STATIC ${GLEW_DIR}/src/glew.c )
56
set_target_properties (glewmx_s PROPERTIES COMPILE_DEFINITIONS "GLEW_STATIC;GLEW_MX" OUTPUT_NAME "${GLEW_LIB_NAME}mx" PREFIX lib)
Michel Zou's avatar
Michel Zou committed
57
58
59
target_link_libraries (glewmx ${GLEW_LIBRARIES})
target_link_libraries (glewmx_s ${GLEW_LIBRARIES})

Tamas Kenez's avatar
Tamas Kenez committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
if(CMAKE_VERSION VERSION_LESS 2.8.12)
  set(MAYBE_EXPORT "")
else()
  target_compile_definitions(glew_s INTERFACE "GLEW_STATIC")
  target_compile_definitions(glewmx INTERFACE "GLEW_MX")
  target_compile_definitions(glewmx_s INTERFACE "GLEW_STATIC;GLEW_MX")
  foreach(t glew glew_s glewmx glewmx_s)
    target_include_directories(${t} PUBLIC $<INSTALL_INTERFACE:include>)
  endforeach()
  set(MAYBE_EXPORT EXPORT glew-targets)
endif()

set(targets_to_install "")
if(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)
  list(APPEND targets_to_install glew glewmx)
endif()

if(NOT DEFINED BUILD_SHARED_LIBS OR NOT BUILD_SHARED_LIBS)
  list(APPEND targets_to_install glew_s glewmx_s)
endif()

install ( TARGETS ${targets_to_install}
          ${MAYBE_EXPORT}
Michel Zou's avatar
Michel Zou committed
83
84
85
86
87
          RUNTIME DESTINATION bin
          LIBRARY DESTINATION lib${LIB_SUFFIX}
          ARCHIVE DESTINATION lib${LIB_SUFFIX}
)

Michel Zou's avatar
Michel Zou committed
88
if (BUILD_UTILS)
89
  add_executable (glewinfo ${GLEW_DIR}/src/glewinfo.c)
Michel Zou's avatar
Michel Zou committed
90
91
  target_link_libraries (glewinfo glew)

92
  add_executable (visualinfo ${GLEW_DIR}/src/visualinfo.c)
Michel Zou's avatar
Michel Zou committed
93
94
95
96
97
98
  target_link_libraries (visualinfo glew)

  install ( TARGETS glewinfo visualinfo
            DESTINATION bin)
endif ()

Michel Zou's avatar
Michel Zou committed
99
100
101
102
103
104
105
106
107
set (prefix ${CMAKE_INSTALL_PREFIX})
set (exec_prefix \${prefix})
set (libdir \${prefix}/lib)
set (includedir \${prefix}/include)
set (includedir \${prefix}/include)
set (version ${GLEW_VERSION})
set (libname ${GLEW_LIB_NAME})
set (cflags)
set (requireslib glu)
108
configure_file (${GLEW_DIR}/glew.pc.in ${GLEW_DIR}/glew.pc @ONLY)
Michel Zou's avatar
Michel Zou committed
109
110
set (cflags "-DGLEW_MX")
set (libname ${GLEW_LIB_NAME}mx)
111
configure_file (${GLEW_DIR}/glew.pc.in ${GLEW_DIR}/glewmx.pc @ONLY)
Michel Zou's avatar
Michel Zou committed
112

113
install(FILES ${GLEW_DIR}/glew.pc ${GLEW_DIR}/glewmx.pc
Michel Zou's avatar
Michel Zou committed
114
115
        DESTINATION lib/pkgconfig
)
Tamas Kenez's avatar
Tamas Kenez committed
116

117
install (FILES
Tamas Kenez's avatar
Tamas Kenez committed
118
119
120
    ${GLEW_DIR}/include/GL/wglew.h
    ${GLEW_DIR}/include/GL/glew.h
    ${GLEW_DIR}/include/GL/glxew.h
121
    DESTINATION include/GL)
Tamas Kenez's avatar
Tamas Kenez committed
122
123
124
125
126
127
128
129
130

if(MAYBE_EXPORT)
  install(EXPORT glew-targets DESTINATION lib/cmake/glew
    NAMESPACE GLEW::)
  install(FILES
      ${CMAKE_CURRENT_SOURCE_DIR}/glew-config.cmake
      ${CMAKE_CURRENT_SOURCE_DIR}/CopyImportedTargetProperties.cmake
    DESTINATION lib/cmake/glew)
endif()