CMakeLists.txt 7.82 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

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

7
cmake_minimum_required (VERSION 2.8.12)
Togo Nishigaki's avatar
Togo Nishigaki committed
8

9
10
include(GNUInstallDirs)

Michel Zou's avatar
Michel Zou committed
11
12
if (COMMAND cmake_policy)
  cmake_policy (SET CMP0003 NEW)
13
  cmake_policy (SET CMP0042 NEW)
Michel Zou's avatar
Michel Zou committed
14
endif()
15

Tamas Kenez's avatar
Tamas Kenez committed
16
17
set(CMAKE_DEBUG_POSTFIX d)

Michel Zou's avatar
Michel Zou committed
18
option (BUILD_UTILS "utilities" ON)
19
20
21
22
23
option (GLEW_REGAL "Regal mode" OFF)
option (GLEW_OSMESA "OSMesa mode" OFF)
if (APPLE)
    option (BUILD_FRAMEWORK "Build Framework bundle for OSX" OFF)
endif ()
Togo Nishigaki's avatar
Togo Nishigaki committed
24

25
26
set (GLEW_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../..)

27
28
29
30
31
32
33
34
35
# 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
36
37
38
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
39

40
41
42
43
44
45
46
47
find_package (OpenGL REQUIRED)

# X11 required when builing visualinfo and glewinfo,
# but not for Windows or Apple OSX platforms
if (BUILD_UTILS AND NOT WIN32 AND NOT APPLE)
  find_package (X11)
endif()

Michel Zou's avatar
Michel Zou committed
48
if (WIN32)
Michel Zou's avatar
Michel Zou committed
49
  set (GLEW_LIB_NAME glew32)
Michel Zou's avatar
Michel Zou committed
50
else ()
Michel Zou's avatar
Michel Zou committed
51
52
  set (GLEW_LIB_NAME GLEW)
  set (DLL_PREFIX lib)
Michel Zou's avatar
Michel Zou committed
53
endif ()
54

Michel Zou's avatar
Michel Zou committed
55
set (GLEW_LIBRARIES ${OPENGL_LIBRARIES})
56

57
add_definitions (-DGLEW_NO_GLU)
Togo Nishigaki's avatar
Togo Nishigaki committed
58

59
60
61
62
63
64
65
66
67
68
69
70
#### Regal mode ####

if (GLEW_REGAL)
  if (WIN32)
    set (REGAL_LIB_NAME regal32)
  else ()
    set (REGAL_LIB_NAME Regal)
  endif ()
  add_definitions (-DGLEW_REGAL)
  set (GLEW_LIBRARIES ${REGAL_LIB_NAME})
endif ()

71
72
73
74
75
76
77
78
79
80
#### OSMesa mode ####

if (GLEW_OSMESA)
  if (WIN32)
    set (OSMESA_LIB_NAME osmesa)
  else ()
    set (OSMESA_LIB_NAME OSMesa)
  endif ()
  add_definitions (-DGLEW_OSMESA)
  set (GLEW_LIBRARIES ${OSMESA_LIB_NAME} ${OPENGL_LIBRARIES})
81
  set (X11_LIBRARIES)
82
83
endif ()

84
85
#### GLEW ####

86
include_directories (${GLEW_DIR}/include)
Togo Nishigaki's avatar
Togo Nishigaki committed
87

88
set (GLEW_PUBLIC_HEADERS_FILES ${GLEW_DIR}/include/GL/wglew.h ${GLEW_DIR}/include/GL/glew.h ${GLEW_DIR}/include/GL/glxew.h)
89
90
91
92
93
94
set (GLEW_SRC_FILES ${GLEW_DIR}/src/glew.c)

if (WIN32)
  list (APPEND GLEW_SRC_FILES ${GLEW_DIR}/build/glew.rc)
endif ()

95
add_library (glew SHARED ${GLEW_PUBLIC_HEADERS_FILES} ${GLEW_SRC_FILES})
96
97
98
set_target_properties (glew PROPERTIES COMPILE_DEFINITIONS "GLEW_BUILD" OUTPUT_NAME "${GLEW_LIB_NAME}" PREFIX "${DLL_PREFIX}"
                                       VERSION ${GLEW_VERSION}
                                       SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR})
99
add_library (glew_s STATIC ${GLEW_PUBLIC_HEADERS_FILES} ${GLEW_SRC_FILES})
100
set_target_properties (glew_s PROPERTIES COMPILE_DEFINITIONS "GLEW_STATIC" OUTPUT_NAME "${GLEW_LIB_NAME}" PREFIX lib)
101

102
if (MSVC)
103
  # add options from visual studio project
104
105
  target_compile_definitions (glew PRIVATE "GLEW_BUILD;VC_EXTRALEAN")
  target_compile_definitions (glew_s PRIVATE "GLEW_STATIC;VC_EXTRALEAN")
Wes Tarro's avatar
Wes Tarro committed
106
  target_link_libraries (glew LINK_PRIVATE -BASE:0x62AA0000)
107
108
109
  # kill security checks which are dependent on stdlib
  target_compile_options (glew PRIVATE -GS-)
  target_compile_options (glew_s PRIVATE -GS-)
110
  # remove stdlib dependency
Wes Tarro's avatar
Wes Tarro committed
111
  target_link_libraries (glew LINK_PRIVATE -nodefaultlib -noentry)
Tan Li Boon's avatar
Tan Li Boon committed
112
  string(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
113
114
115
elseif (WIN32 AND ((CMAKE_C_COMPILER_ID MATCHES "GNU") OR (CMAKE_C_COMPILER_ID MATCHES "Clang")))
  # remove stdlib dependency on windows with GCC and Clang (for similar reasons
  # as to MSVC - to allow it to be used with any Windows compiler)
116
117
  target_compile_options (glew PRIVATE -fno-builtin -fno-stack-protector)
  target_compile_options (glew_s PRIVATE -fno-builtin -fno-stack-protector)
Wes Tarro's avatar
Wes Tarro committed
118
  target_link_libraries (glew LINK_PRIVATE -nostdlib)
119
endif ()
120
121
122
123
124
125
126
127
128
129
130
131
132
133

if (BUILD_FRAMEWORK)
  set_target_properties(glew PROPERTIES
    FRAMEWORK TRUE
    FRAMEWORK_VERSION ${GLEW_VERSION}
    MACOSX_FRAMEWORK_IDENTIFIER net.sourceforge.glew
    MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${GLEW_VERSION}
    MACOSX_FRAMEWORK_BUNDLE_VERSION ${GLEW_VERSION}
    XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
    PUBLIC_HEADER "${GLEW_PUBLIC_HEADERS_FILES}"
    OUTPUT_NAME GLEW
  )
endif()

Wes Tarro's avatar
Wes Tarro committed
134
target_link_libraries (glew LINK_PUBLIC ${GLEW_LIBRARIES})
Michel Zou's avatar
Michel Zou committed
135
136
target_link_libraries (glew_s ${GLEW_LIBRARIES})

Tamas Kenez's avatar
Tamas Kenez committed
137
138
139
140
if(CMAKE_VERSION VERSION_LESS 2.8.12)
  set(MAYBE_EXPORT "")
else()
  target_compile_definitions(glew_s INTERFACE "GLEW_STATIC")
141
  foreach(t glew glew_s)
Tamas Kenez's avatar
Tamas Kenez committed
142
143
144
145
146
147
148
    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)
149
  list(APPEND targets_to_install glew)
Tamas Kenez's avatar
Tamas Kenez committed
150
151
152
endif()

if(NOT DEFINED BUILD_SHARED_LIBS OR NOT BUILD_SHARED_LIBS)
153
  list(APPEND targets_to_install glew_s)
Tamas Kenez's avatar
Tamas Kenez committed
154
155
156
157
endif()

install ( TARGETS ${targets_to_install}
          ${MAYBE_EXPORT}
158
159
160
          RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
          ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
161
          FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
Michel Zou's avatar
Michel Zou committed
162
163
)

Michel Zou's avatar
Michel Zou committed
164
if (BUILD_UTILS)
165
166
167
168
169
  set (GLEWINFO_SRC_FILES ${GLEW_DIR}/src/glewinfo.c)
  if (WIN32)
    list (APPEND GLEWINFO_SRC_FILES ${GLEW_DIR}/build/glewinfo.rc)
  endif ()
  add_executable (glewinfo ${GLEWINFO_SRC_FILES})
170
171
172
173
  target_link_libraries (glewinfo glew)
  if (NOT WIN32)
    target_link_libraries(glewinfo ${X11_LIBRARIES})
  endif ()
Michel Zou's avatar
Michel Zou committed
174

175
176
177
178
179
  set (VISUALINFO_SRC_FILES ${GLEW_DIR}/src/visualinfo.c)
  if (WIN32)
    list (APPEND VISUALINFO_SRC_FILES ${GLEW_DIR}/build/visualinfo.rc)
  endif ()
  add_executable (visualinfo ${VISUALINFO_SRC_FILES})
180
181
182
183
  target_link_libraries (visualinfo glew)
  if (NOT WIN32)
    target_link_libraries(visualinfo ${X11_LIBRARIES})
  endif ()
Michel Zou's avatar
Michel Zou committed
184
185

  install ( TARGETS glewinfo visualinfo
186
            DESTINATION ${CMAKE_INSTALL_BINDIR})
Michel Zou's avatar
Michel Zou committed
187
188
endif ()

Michel Zou's avatar
Michel Zou committed
189
set (prefix ${CMAKE_INSTALL_PREFIX})
190
191
192
set (exec_prefix ${CMAKE_INSTALL_PREFIX})
set (libdir ${CMAKE_INSTALL_FULL_LIBDIR})
set (includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
Michel Zou's avatar
Michel Zou committed
193
194
195
196
set (version ${GLEW_VERSION})
set (libname ${GLEW_LIB_NAME})
set (cflags)
set (requireslib glu)
197
198
199
200
201
202

#  Mac OSX has no glu.pc unless optional X11/GLX is installed
if (APPLE)
  set (requireslib)
endif ()

203
configure_file (${GLEW_DIR}/glew.pc.in ${GLEW_DIR}/glew.pc @ONLY)
Michel Zou's avatar
Michel Zou committed
204

Claudio's avatar
Claudio committed
205
install(FILES ${GLEW_DIR}/glew.pc
206
        DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
Michel Zou's avatar
Michel Zou committed
207
)
Tamas Kenez's avatar
Tamas Kenez committed
208

209
if(WIN32 AND MSVC AND (NOT MSVC_VERSION LESS 1600) AND (NOT CMAKE_VERSION VERSION_LESS "3.1"))
210
211
212
213
214
215
216
    install(
        FILES $<TARGET_PDB_FILE:glew>
        DESTINATION ${CMAKE_INSTALL_LIBDIR}
        CONFIGURATIONS Debug RelWithDebInfo
    )
endif()

217
install (FILES
Tamas Kenez's avatar
Tamas Kenez committed
218
219
220
    ${GLEW_DIR}/include/GL/wglew.h
    ${GLEW_DIR}/include/GL/glew.h
    ${GLEW_DIR}/include/GL/glxew.h
221
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GL)
Tamas Kenez's avatar
Tamas Kenez committed
222
223

if(MAYBE_EXPORT)
224
  install(EXPORT glew-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/glew
Tamas Kenez's avatar
Tamas Kenez committed
225
226
227
228
    NAMESPACE GLEW::)
  install(FILES
      ${CMAKE_CURRENT_SOURCE_DIR}/glew-config.cmake
      ${CMAKE_CURRENT_SOURCE_DIR}/CopyImportedTargetProperties.cmake
229
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/glew)
Tamas Kenez's avatar
Tamas Kenez committed
230
endif()
231
232
233
234
235
236
237
238
239
240
241

if(NOT TARGET uninstall)
  configure_file(
      ${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in
      ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
      IMMEDIATE @ONLY)

  add_custom_target(uninstall
      COMMAND ${CMAKE_COMMAND} -P
      ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()