mirror of
https://github.com/Perlmint/glew-cmake.git
synced 2025-03-20 15:56:16 +00:00
Merge pull request #42 from Perlmint/fix-for-old-cmake
Fix errors in cmake
This commit is contained in:
commit
f1c0b06b1b
81
.github/workflows/cmake.yml
vendored
81
.github/workflows/cmake.yml
vendored
@ -79,4 +79,83 @@ jobs:
|
||||
cp $GITHUB_WORKSPACE/glew-cmake/sub-directory-test.cmake CMakeLists.txt
|
||||
cmake .
|
||||
cmake --build .
|
||||
|
||||
|
||||
build_2_8:
|
||||
# The CMake configure and build commands are platform agnostic and should work equally
|
||||
# well on Windows or Mac. You can convert this to a matrix build if you need
|
||||
# cross-platform coverage.
|
||||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
|
||||
runs-on: ubuntu-latest
|
||||
container: ubuntu:14.04
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install dependencies
|
||||
run: apt update && apt install -y cmake gcc libgl1-mesa-dev libx11-dev libxext-dev
|
||||
|
||||
- name: Configure CMake
|
||||
shell: bash
|
||||
run: cmake . -DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
||||
|
||||
- name: Build test
|
||||
shell: bash
|
||||
run: cmake --build .
|
||||
|
||||
- name: Check alias
|
||||
shell: bash
|
||||
run: test -e lib/libGLEW.a
|
||||
|
||||
build_3_10:
|
||||
# The CMake configure and build commands are platform agnostic and should work equally
|
||||
# well on Windows or Mac. You can convert this to a matrix build if you need
|
||||
# cross-platform coverage.
|
||||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
|
||||
runs-on: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install dependencies
|
||||
run: apt update && apt install -y cmake gcc libgl1-mesa-dev libx11-dev libxext-dev
|
||||
|
||||
- name: Configure CMake
|
||||
shell: bash
|
||||
run: cmake . -DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
||||
|
||||
- name: Build test
|
||||
shell: bash
|
||||
run: cmake --build .
|
||||
|
||||
- name: Check alias
|
||||
shell: bash
|
||||
run: test -e lib/libGLEW.a
|
||||
|
||||
build_mac:
|
||||
runs-on: macos-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Configure CMake
|
||||
shell: bash
|
||||
run: cmake . -DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
||||
|
||||
- name: Build test
|
||||
shell: bash
|
||||
run: cmake --build .
|
||||
|
||||
build_windows:
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Configure CMake
|
||||
shell: bash
|
||||
run: cmake . -DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
||||
|
||||
- name: Build test
|
||||
shell: bash
|
||||
run: cmake --build .
|
||||
|
131
CMakeLists.txt
131
CMakeLists.txt
@ -1,5 +1,22 @@
|
||||
cmake_minimum_required(VERSION 2.8.12)
|
||||
project("glew")
|
||||
|
||||
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()
|
||||
|
||||
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
set(INCLUDE_DIR "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>$<INSTALL_INTERFACE:include>")
|
||||
@ -17,14 +34,6 @@ option(USE_GLU "Use GLU" OFF)
|
||||
option(PKG_CONFIG_REPRESENTATIVE_TARGET "Generate pc file for specified target as glew. libglew_static|libglew_shared" OFF)
|
||||
option(ONLY_LIBS "Do not build executables" OFF)
|
||||
|
||||
file(STRINGS ${CMAKE_CURRENT_SOURCE_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 ${CMAKE_CURRENT_SOURCE_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 ${CMAKE_CURRENT_SOURCE_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})
|
||||
|
||||
set(LIBGLEW_SRCS ${SRC_DIR}/glew.c)
|
||||
|
||||
set(DEFINITIONS)
|
||||
@ -37,7 +46,7 @@ if(MSVC)
|
||||
endif()
|
||||
|
||||
# Use namespaced libraries when supported
|
||||
if(${CMAKE_VERSION} VERSION_GREATER 3.14)
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.14)
|
||||
set(USE_NAMESPACED_LIB YES)
|
||||
else()
|
||||
set(USE_NAMESPACED_LIB NO)
|
||||
@ -63,15 +72,31 @@ else()
|
||||
if(USE_NAMESPACED_LIB)
|
||||
list(APPEND LIBRARIES OpenGL::GLU)
|
||||
else()
|
||||
list(APPEND LIBRARIES OPENGL_glu_LIBRARY)
|
||||
list(APPEND LIBRARIES ${OPENGL_glu_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
list(APPEND pc_requires gl)
|
||||
if(USE_NAMESPACED_LIB)
|
||||
list(APPEND LIBRARIES OpenGL::GL)
|
||||
if(POLICY CMP0072)
|
||||
# GLVND
|
||||
if(USE_NAMESPACED_LIB)
|
||||
list(APPEND LIBRARIES OpenGL::GL)
|
||||
if(NOT (WIN32 OR APPLE))
|
||||
list(APPEND LIBRARIES OpenGL::GLX)
|
||||
endif()
|
||||
else()
|
||||
list(APPEND LIBRARIES ${OPENGL_opengl_LIBRARY})
|
||||
if(NOT (WIN32 OR APPLE))
|
||||
list(APPEND LIBRARIES ${OPENGL_glx_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
list(APPEND LIBRARIES OPENGL_opengl_LIBRARY)
|
||||
# Non GLVND
|
||||
if(USE_NAMESPACED_LIB)
|
||||
list(APPEND LIBRARIES OpenGL::OpenGL)
|
||||
else()
|
||||
list(APPEND LIBRARIES ${OPENGL_gl_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
@ -84,29 +109,61 @@ elseif(NOT WIN32)
|
||||
if(USE_NAMESPACED_LIB)
|
||||
list(APPEND LIBRARIES X11::X11 X11::Xext)
|
||||
else()
|
||||
list(APPEND LIBRARIES X11_X11_LIB X11_Xext_LIB)
|
||||
list(APPEND LIBRARIES ${X11_X11_LIB} ${X11_Xext_LIB})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(GLEW_TARGETS)
|
||||
|
||||
if(NOT CMAKE_INSTALL_LIBDIR)
|
||||
set(INSTALL_LIBDIR lib)
|
||||
else()
|
||||
set(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
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
|
||||
if(NOT (WIN32 OR APPLE))
|
||||
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()
|
||||
|
||||
if(glew-cmake_BUILD_STATIC)
|
||||
add_library(libglew_static STATIC ${LIBGLEW_SRCS})
|
||||
|
||||
set_target_properties(libglew_static PROPERTIES
|
||||
OUTPUT_NAME "glew"
|
||||
DEBUG_POSTFIX d)
|
||||
set_representative_target(libglew_static)
|
||||
|
||||
target_compile_definitions(libglew_static PUBLIC GLEW_STATIC)
|
||||
list(APPEND GLEW_TARGETS libglew_static)
|
||||
if(NOT WIN32)
|
||||
add_custom_command(TARGET libglew_static POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink libglew.a libGLEW.a
|
||||
WORKING_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
|
||||
BYPRODUCTS ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libGLEW.a
|
||||
COMMENT "create libGLEW symbolic link")
|
||||
install(FILES ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libGLEW.a TYPE LIB)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(glew-cmake_BUILD_SHARED)
|
||||
@ -117,17 +174,7 @@ if(glew-cmake_BUILD_SHARED)
|
||||
OUTPUT_NAME "glew-shared"
|
||||
DEBUG_POSTFIX d)
|
||||
else()
|
||||
set_target_properties(libglew_shared PROPERTIES
|
||||
OUTPUT_NAME "glew"
|
||||
DEBUG_POSTFIX d)
|
||||
if(NOT WIN32)
|
||||
add_custom_command(TARGET libglew_shared POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink libglew.so libGLEW.so
|
||||
WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
|
||||
BYPRODUCTS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libGLEW.so
|
||||
COMMENT "create libGLEW symbolic link")
|
||||
install(FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libGLEW.so TYPE LIB)
|
||||
endif()
|
||||
set_representative_target(libglew_shared)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(libglew_shared PRIVATE GLEW_BUILD)
|
||||
@ -144,14 +191,14 @@ endforeach()
|
||||
if(PKG_CONFIG_REPRESENTATIVE_TARGET)
|
||||
GeneratePkgConfigFile(${PKG_CONFIG_REPRESENTATIVE_TARGET} "The OpenGL Extension Wrangler library"
|
||||
NAME "glew"
|
||||
LIBRARY_DIR lib
|
||||
LIBRARY_DIR ${INSTALL_LIBDIR}
|
||||
REQUIRES ${pc_requires})
|
||||
endif()
|
||||
|
||||
install(TARGETS ${GLEW_TARGETS}
|
||||
EXPORT glew-cmake
|
||||
ARCHIVE DESTINATION lib)
|
||||
install(EXPORT glew-cmake DESTINATION lib/cmake/glew FILE glewConfig.cmake)
|
||||
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)
|
||||
|
||||
file(GLOB PUBLIC_HEADERS "include/GL/*.h")
|
||||
install(FILES ${PUBLIC_HEADERS} DESTINATION include/GL/)
|
||||
|
Loading…
Reference in New Issue
Block a user