From e3264d1de34922ce8a42bf7141a58dda6c70b4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Wed, 22 Nov 2017 11:48:12 +0100 Subject: [PATCH] CMake: Add option to use system GLEW 2.0+ The option is enabled by default, but the system version will only be used if found and newer than 2.0.0 (to ensure that https://sourceforge.net/p/glew/patches/40/ is fixed). When missing, we silently fallback to the vendored source code, so there is no change for e.g. Windows compilation. --- CMakeLists.txt | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64b1798f9..eacd1baed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ option(SERVER_ONLY "Create a server only (i.e. no graphics or sound)" OFF) option(USE_FRIBIDI "Support for right-to-left languages" ON) option(CHECK_ASSETS "Check if assets are installed in ../stk-assets" ON) option(USE_SYSTEM_ANGELSCRIPT "Use system angelscript instead of built-in angelscript. If you enable this option, make sure to use a compatible version." OFF) +option(USE_SYSTEM_GLEW "Use system GLEW instead of the built-in version, when available." ON) option(ENABLE_WAYLAND_DEVICE "Enable Wayland device for linux build" OFF) CMAKE_DEPENDENT_OPTION(BUILD_RECORDER "Build opengl recorder" ON @@ -109,11 +110,24 @@ include_directories("${PROJECT_SOURCE_DIR}/lib/bullet/src") add_subdirectory("${PROJECT_SOURCE_DIR}/lib/enet") include_directories("${PROJECT_SOURCE_DIR}/lib/enet/include") -# Build glew library +# Find system GLEW library or build it if missing if(NOT USE_GLES2 AND NOT SERVER_ONLY) add_definitions(-DGLEW_NO_GLU) - add_subdirectory("${PROJECT_SOURCE_DIR}/lib/glew") - include_directories("${PROJECT_SOURCE_DIR}/lib/glew/include") + if(USE_SYSTEM_GLEW) + find_package(PkgConfig) + if(PKGCONFIG_FOUND) + pkg_check_modules(GLEW glew>=2.0) + endif() + endif() + + if(GLEW_FOUND) + include_directories(${GLEW_INCLUDE_DIRS}) + else() + # Fallback to built-in version silently + add_subdirectory("${PROJECT_SOURCE_DIR}/lib/glew") + include_directories("${PROJECT_SOURCE_DIR}/lib/glew/include") + set(GLEW_LIBRARIES "glew") + endif() endif() if(MSVC OR APPLE) @@ -420,7 +434,7 @@ target_link_libraries(supertuxkart if(NOT SERVER_ONLY) if(NOT USE_GLES2) - target_link_libraries(supertuxkart ${OPENGL_gl_LIBRARY} glew graphics_utils) + target_link_libraries(supertuxkart ${OPENGL_gl_LIBRARY} ${GLEW_LIBRARIES} graphics_utils) else() target_link_libraries(supertuxkart GLESv2) endif()