2020-12-29 10:52:07 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8.12)
|
2021-02-08 14:33:27 +00:00
|
|
|
|
|
|
|
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/config/version _VERSION_MAJOR_STRING REGEX "GLEW_MAJOR[ ]*=[ ]*[0-9]+.*")
|
|
|
|
string(REGEX REPLACE "GLEW_MAJOR[ ]*=[ ]*([0-9]+)" "\\1" MAJOR_VERSION ${_VERSION_MAJOR_STRING})
|
|
|
|
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/config/version _VERSION_MINOR_STRING REGEX "GLEW_MINOR[ ]*=[ ]*[0-9]+.*")
|
|
|
|
string(REGEX REPLACE "GLEW_MINOR[ ]*=[ ]*([0-9]+)" "\\1" MINOR_VERSION ${_VERSION_MINOR_STRING})
|
|
|
|
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/config/version _VERSION_PATCH_STRING REGEX "GLEW_MICRO[ ]*=[ ]*[0-9]+.*")
|
|
|
|
string(REGEX REPLACE "GLEW_MICRO[ ]*=[ ]*([0-9]+)" "\\1" PATCH_VERSION ${_VERSION_PATCH_STRING})
|
|
|
|
set(GLEW_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION})
|
|
|
|
|
|
|
|
if(NOT CMAKE_VERSION VERSION_LESS 3.0)
|
|
|
|
cmake_policy(SET CMP0048 NEW)
|
|
|
|
project("glew" VERSION ${GLEW_VERSION} LANGUAGES C)
|
|
|
|
else()
|
|
|
|
project("glew" C)
|
|
|
|
set(CPACK_PACKAGE_VERSION_MAJOR ${MAJOR_VERSION})
|
|
|
|
set(CPACK_PACKAGE_VERSION_MINOR ${MAJOR_VERSION})
|
|
|
|
set(CPACK_PACKAGE_VERSION_PATCH ${MAJOR_VERSION})
|
|
|
|
endif()
|
2019-10-09 11:40:25 +00:00
|
|
|
|
|
|
|
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
2020-12-29 12:05:28 +00:00
|
|
|
set(INCLUDE_DIR "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>$<INSTALL_INTERFACE:include>")
|
2019-10-09 11:40:25 +00:00
|
|
|
set(RC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
|
|
|
|
|
2020-12-29 10:56:22 +00:00
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
2019-10-09 11:40:25 +00:00
|
|
|
|
2019-10-09 11:40:50 +00:00
|
|
|
include("GeneratePkgConfig.cmake")
|
|
|
|
|
2023-02-08 22:43:00 +00:00
|
|
|
if (POLICY CMP0077)
|
|
|
|
cmake_policy(SET CMP0077 NEW)
|
|
|
|
endif()
|
|
|
|
|
2019-10-09 11:40:25 +00:00
|
|
|
option(glew-cmake_BUILD_SHARED "Build the shared glew library" ON)
|
|
|
|
option(glew-cmake_BUILD_STATIC "Build the static glew library" ON)
|
|
|
|
option(USE_GLU "Use GLU" OFF)
|
2021-08-22 12:24:41 +00:00
|
|
|
option(GLEW_OSMESA "Off-screen Mesa mode" OFF)
|
2020-12-29 13:56:02 +00:00
|
|
|
option(PKG_CONFIG_REPRESENTATIVE_TARGET "Generate pc file for specified target as glew. libglew_static|libglew_shared" OFF)
|
2019-10-09 11:40:25 +00:00
|
|
|
option(ONLY_LIBS "Do not build executables" OFF)
|
|
|
|
|
|
|
|
set(LIBGLEW_SRCS ${SRC_DIR}/glew.c)
|
|
|
|
|
|
|
|
set(DEFINITIONS)
|
|
|
|
if(WIN32)
|
|
|
|
list(APPEND DEFINITIONS -DWIN32_MEAN_AND_LEAN -DVC_EXTRALEAN -D_CRT_SECURE_NO_WARNINGS)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(MSVC)
|
|
|
|
list(APPEND LIBGLEW_SRCS ${RC_DIR}/glew.rc)
|
|
|
|
endif()
|
|
|
|
|
2020-12-29 13:56:02 +00:00
|
|
|
# Use namespaced libraries when supported
|
2021-02-08 14:33:27 +00:00
|
|
|
if(NOT CMAKE_VERSION VERSION_LESS 3.14)
|
2020-12-29 13:56:02 +00:00
|
|
|
set(USE_NAMESPACED_LIB YES)
|
|
|
|
else()
|
|
|
|
set(USE_NAMESPACED_LIB NO)
|
|
|
|
endif()
|
|
|
|
|
2021-11-14 06:48:44 +00:00
|
|
|
if(POLICY CMP0028)
|
|
|
|
cmake_policy(SET CMP0028 NEW)
|
|
|
|
endif()
|
|
|
|
|
2021-02-25 16:51:03 +00:00
|
|
|
if(POLICY CMP0042)
|
|
|
|
cmake_policy(SET CMP0042 NEW)
|
|
|
|
endif()
|
|
|
|
|
2020-12-29 10:51:14 +00:00
|
|
|
if(POLICY CMP0072)
|
2020-12-29 13:56:02 +00:00
|
|
|
set(OpenGL_GL_PREFERENCE GLVND)
|
2023-02-16 14:32:22 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT (WIN32 OR APPLE))
|
|
|
|
message("Try to find OpenGL with GLVND")
|
|
|
|
find_package(OpenGL REQUIRED
|
|
|
|
COMPONENTS OpenGL GLX)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(OPENGL_FOUND AND OpenGL_GLX_FOUND AND TARGET OpenGL::OpenGL)
|
|
|
|
set(USE_GLVND YES)
|
2021-11-14 06:48:44 +00:00
|
|
|
else()
|
2023-02-16 14:32:22 +00:00
|
|
|
message("GLVND not supported. Try find OpenGL legacy")
|
|
|
|
find_package(OpenGL REQUIRED)
|
2021-11-14 06:48:44 +00:00
|
|
|
set(USE_GLVND NO)
|
2020-12-29 10:51:14 +00:00
|
|
|
endif()
|
|
|
|
|
2020-12-29 13:56:02 +00:00
|
|
|
set(pc_requires)
|
|
|
|
|
2019-10-09 11:40:25 +00:00
|
|
|
if(NOT USE_GLU)
|
|
|
|
list(APPEND DEFINITIONS -DGLEW_NO_GLU)
|
|
|
|
else()
|
|
|
|
if(NOT OPENGL_GLU_FOUND)
|
|
|
|
message(FATAL_ERROR "GLU is not found. but GLU option is enabled")
|
|
|
|
endif()
|
|
|
|
|
2020-12-29 13:56:02 +00:00
|
|
|
list(APPEND pc_requires glu)
|
|
|
|
|
|
|
|
if(USE_NAMESPACED_LIB)
|
|
|
|
list(APPEND LIBRARIES OpenGL::GLU)
|
|
|
|
else()
|
2021-02-08 14:06:11 +00:00
|
|
|
list(APPEND LIBRARIES ${OPENGL_glu_LIBRARY})
|
2020-12-29 13:56:02 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(APPEND pc_requires gl)
|
2021-08-22 12:24:41 +00:00
|
|
|
if(USE_NAMESPACED_LIB)
|
2021-11-14 06:48:44 +00:00
|
|
|
if(USE_GLVND)
|
|
|
|
list(APPEND LIBRARIES OpenGL::OpenGL)
|
|
|
|
else()
|
|
|
|
list(APPEND LIBRARIES OpenGL::GL)
|
|
|
|
endif()
|
2019-10-09 11:40:25 +00:00
|
|
|
else()
|
2021-11-14 06:48:44 +00:00
|
|
|
if(USE_GLVND)
|
|
|
|
list(APPEND LIBRARIES ${OPENGL_opengl_LIBRARY})
|
|
|
|
else()
|
|
|
|
list(APPEND LIBRARIES ${OPENGL_gl_LIBRARY})
|
|
|
|
endif()
|
2020-12-29 13:56:02 +00:00
|
|
|
endif()
|
|
|
|
|
2021-08-22 12:24:41 +00:00
|
|
|
# OS Specific dependencies
|
2020-12-29 13:56:02 +00:00
|
|
|
if(APPLE)
|
2021-08-22 12:24:41 +00:00
|
|
|
find_library(AGL_LIBRARY AGL REQUIRED)
|
2020-12-29 13:56:02 +00:00
|
|
|
list(APPEND LIBRARIES ${AGL_LIBRARY})
|
|
|
|
elseif(NOT WIN32)
|
2021-08-22 12:24:41 +00:00
|
|
|
if(GLEW_OSMESA)
|
|
|
|
find_library(OSMESA_LIBRARY OSMesa REQUIRED)
|
|
|
|
list(APPEND LIBRARIES ${OSMESA_LIBRARY})
|
|
|
|
list(APPEND DEFINITIONS -DGLEW_OSMESA)
|
|
|
|
list(APPEND pc_requires osmesa)
|
2020-12-29 13:56:02 +00:00
|
|
|
else()
|
2021-11-14 06:48:44 +00:00
|
|
|
if(USE_GLVND)
|
|
|
|
if(NOT OpenGL_GLX_FOUND)
|
|
|
|
message(FATAL_ERROR "GLX is not found. Try with PREFER_GLVND=NO")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(USE_NAMESPACED_LIB)
|
|
|
|
list(APPEND LIBRARIES OpenGL::GLX)
|
|
|
|
else()
|
|
|
|
list(APPEND LIBRARIES ${OPENGL_glx_LIBRARY})
|
|
|
|
endif()
|
2021-08-22 12:24:41 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
find_package(X11 REQUIRED)
|
|
|
|
|
|
|
|
list(APPEND pc_requires x11 xext)
|
|
|
|
if(USE_NAMESPACED_LIB)
|
|
|
|
list(APPEND LIBRARIES X11::X11 X11::Xext)
|
|
|
|
else()
|
|
|
|
list(APPEND LIBRARIES ${X11_X11_LIB} ${X11_Xext_LIB})
|
|
|
|
endif()
|
2020-12-29 13:56:02 +00:00
|
|
|
endif()
|
2019-10-09 11:40:25 +00:00
|
|
|
endif()
|
|
|
|
|
2020-12-29 11:48:07 +00:00
|
|
|
set(GLEW_TARGETS)
|
|
|
|
|
2021-02-08 14:34:17 +00:00
|
|
|
if(NOT CMAKE_INSTALL_LIBDIR)
|
|
|
|
set(INSTALL_LIBDIR lib)
|
|
|
|
else()
|
|
|
|
set(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
endif()
|
|
|
|
|
2023-02-19 04:09:15 +00:00
|
|
|
execute_process(
|
2023-02-27 12:00:25 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/test_fs_support_case_sensitivity
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/test_fs_support_CASE_sensitivity)
|
2023-02-19 04:09:15 +00:00
|
|
|
file(GLOB TEST_FILE_LIST ${CMAKE_BINARY_DIR}/test_fs_support_*_sensitivity)
|
|
|
|
list(LENGTH TEST_FILE_LIST TEST_FILE_COUNT)
|
|
|
|
if(TEST_FILE_COUNT EQUAL 2)
|
|
|
|
set(SUPPORT_CASE_SENSITIVE_FS YES)
|
|
|
|
else()
|
|
|
|
set(SUPPORT_CASE_SENSITIVE_FS NO)
|
|
|
|
endif()
|
|
|
|
|
2021-02-08 14:34:17 +00:00
|
|
|
function(set_representative_target TARGET)
|
|
|
|
set_target_properties(${TARGET} PROPERTIES
|
|
|
|
OUTPUT_NAME "glew"
|
|
|
|
DEBUG_POSTFIX d)
|
|
|
|
|
|
|
|
# Windows & macOS use case-insensetive FS. do not create symbolic link
|
2023-02-19 04:09:15 +00:00
|
|
|
if(SUPPORT_CASE_SENSITIVE_FS)
|
2021-02-08 14:34:17 +00:00
|
|
|
get_target_property(TARGET_TYPE ${TARGET} TYPE)
|
|
|
|
if(TARGET_TYPE STREQUAL STATIC_LIBRARY)
|
|
|
|
set(EXT ".a")
|
|
|
|
get_target_property(OUT_DIR ${TARGET} ARCHIVE_OUTPUT_DIRECTORY)
|
|
|
|
else()
|
|
|
|
set(EXT ".so")
|
|
|
|
get_target_property(OUT_DIR ${TARGET} LIBRARY_OUTPUT_DIRECTORY)
|
|
|
|
endif()
|
|
|
|
if(NOT ${CMAKE_VERSION} VERSION_LESS 3.0)
|
|
|
|
add_custom_command(TARGET ${TARGET} POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink libglew${EXT} libGLEW${EXT}
|
|
|
|
WORKING_DIRECTORY ${OUT_DIR}
|
|
|
|
BYPRODUCTS ${OUT_DIR}/libGLEW${EXT}
|
|
|
|
COMMENT "create libGLEW symbolic link")
|
|
|
|
else()
|
|
|
|
add_custom_command(TARGET ${TARGET} POST_BUILD
|
|
|
|
COMMAND bash ARGS -c "( test ! -e ${OUT_DIR}/libGLEW${EXT} && cd ${OUT_DIR} && ${CMAKE_COMMAND} -E create_symlink libglew${EXT} libGLEW${EXT} ) || true"
|
|
|
|
COMMENT "create libGLEW symbolic link"
|
|
|
|
VERBATIM)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT ${CMAKE_VERSION} VERSION_LESS 3.14)
|
|
|
|
install(FILES ${OUT_DIR}/libGLEW${EXT} TYPE LIB)
|
|
|
|
else()
|
|
|
|
install(FILES ${OUT_DIR}/libGLEW${EXT} DESTINATION ${INSTALL_LIBDIR})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2019-10-09 11:40:25 +00:00
|
|
|
if(glew-cmake_BUILD_STATIC)
|
2020-05-12 05:33:32 +00:00
|
|
|
add_library(libglew_static STATIC ${LIBGLEW_SRCS})
|
2019-10-09 11:40:25 +00:00
|
|
|
|
2021-02-08 14:34:17 +00:00
|
|
|
set_representative_target(libglew_static)
|
2019-10-09 11:40:25 +00:00
|
|
|
|
2021-02-04 13:10:43 +00:00
|
|
|
target_compile_definitions(libglew_static PUBLIC GLEW_STATIC)
|
2020-12-29 11:48:07 +00:00
|
|
|
list(APPEND GLEW_TARGETS libglew_static)
|
2019-10-09 11:40:25 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(glew-cmake_BUILD_SHARED)
|
2020-05-12 05:33:32 +00:00
|
|
|
add_library(libglew_shared SHARED ${LIBGLEW_SRCS})
|
|
|
|
|
2020-12-29 11:18:49 +00:00
|
|
|
if(glew-cmake_BUILD_STATIC)
|
|
|
|
set_target_properties(libglew_shared PROPERTIES
|
|
|
|
OUTPUT_NAME "glew-shared"
|
|
|
|
DEBUG_POSTFIX d)
|
|
|
|
else()
|
2021-02-08 14:34:17 +00:00
|
|
|
set_representative_target(libglew_shared)
|
2020-12-29 11:18:49 +00:00
|
|
|
endif()
|
2020-05-12 05:33:32 +00:00
|
|
|
|
2020-12-29 13:56:02 +00:00
|
|
|
target_compile_definitions(libglew_shared PRIVATE GLEW_BUILD)
|
2021-03-05 12:55:15 +00:00
|
|
|
if(MINGW)
|
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
|
|
|
|
target_link_options(libglew_shared PRIVATE -nostdlib)
|
|
|
|
else()
|
|
|
|
target_link_libraries(libglew_shared PRIVATE -nostdlib)
|
|
|
|
endif()
|
|
|
|
endif()
|
2020-12-29 11:48:07 +00:00
|
|
|
list(APPEND GLEW_TARGETS libglew_shared)
|
2019-10-09 11:40:25 +00:00
|
|
|
endif()
|
|
|
|
|
2020-12-29 13:56:02 +00:00
|
|
|
foreach(GLEW_TARGET ${GLEW_TARGETS})
|
|
|
|
target_compile_definitions(${GLEW_TARGET} PUBLIC ${DEFINITIONS})
|
|
|
|
target_include_directories(${GLEW_TARGET} PUBLIC ${INCLUDE_DIR})
|
2021-03-05 12:55:15 +00:00
|
|
|
target_link_libraries(${GLEW_TARGET} PUBLIC ${LIBRARIES})
|
2020-12-29 13:56:02 +00:00
|
|
|
set_target_properties(${GLEW_TARGET} PROPERTIES VERSION ${GLEW_VERSION})
|
|
|
|
endforeach()
|
|
|
|
|
2019-10-09 11:40:50 +00:00
|
|
|
if(PKG_CONFIG_REPRESENTATIVE_TARGET)
|
|
|
|
GeneratePkgConfigFile(${PKG_CONFIG_REPRESENTATIVE_TARGET} "The OpenGL Extension Wrangler library"
|
|
|
|
NAME "glew"
|
2021-02-08 14:34:17 +00:00
|
|
|
LIBRARY_DIR ${INSTALL_LIBDIR}
|
2020-12-29 13:56:02 +00:00
|
|
|
REQUIRES ${pc_requires})
|
2019-10-09 11:40:50 +00:00
|
|
|
endif()
|
|
|
|
|
2021-02-08 14:34:17 +00:00
|
|
|
install(TARGETS ${GLEW_TARGETS} EXPORT glew-cmake
|
|
|
|
ARCHIVE DESTINATION ${INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${INSTALL_LIBDIR})
|
|
|
|
install(EXPORT glew-cmake DESTINATION ${INSTALL_LIBDIR}/cmake/glew FILE glewConfig.cmake)
|
2020-12-29 11:48:07 +00:00
|
|
|
|
2019-10-09 11:40:25 +00:00
|
|
|
file(GLOB PUBLIC_HEADERS "include/GL/*.h")
|
|
|
|
install(FILES ${PUBLIC_HEADERS} DESTINATION include/GL/)
|
|
|
|
|
|
|
|
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR} AND NOT ONLY_LIBS)
|
|
|
|
set(GLEWINFO_SRCS ${SRC_DIR}/glewinfo.c)
|
|
|
|
set(VISUALINFO_SRCS ${SRC_DIR}/visualinfo.c)
|
|
|
|
if(MSVS)
|
|
|
|
list(APPEND GLEWINFO_SRCS ${RC_DIR}/glewinfo.rc)
|
|
|
|
list(APPEND VISUALINFO_SRCS ${RC_DIR}/visualinfo.rc)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_executable(glewinfo ${GLEWINFO_SRCS})
|
|
|
|
add_executable(visualinfo ${VISUALINFO_SRCS})
|
|
|
|
|
|
|
|
if(glew-cmake_BUILD_STATIC)
|
|
|
|
target_link_libraries(glewinfo libglew_static)
|
|
|
|
target_link_libraries(visualinfo libglew_static)
|
|
|
|
else()
|
|
|
|
target_link_libraries(glewinfo libglew_shared)
|
|
|
|
target_link_libraries(visualinfo libglew_shared)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
install(TARGETS glewinfo visualinfo DESTINATION bin)
|
|
|
|
endif()
|