From 7c3706763a14a548e5f8f0071b4211f8bab03556 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 5 Aug 2016 00:23:16 +0200 Subject: [PATCH] Cleanup Cleanup of 8bdb105897d262c477dc12f8934419de7e6947d9. Add build macro to configuration header and documentation. Add corresponding CMake option. Add change log entry and credit. Add loader static library to link dependencies and add detection to FindVulkan.cmake. --- CMake/modules/FindVulkan.cmake | 5 ++++- CMakeLists.txt | 20 ++++++++++++++++++++ README.md | 3 +++ docs/compile.dox | 7 +++++++ src/glfw_config.h.in | 2 ++ src/internal.h | 8 ++++---- src/vulkan.c | 1 - tests/CMakeLists.txt | 4 +++- 8 files changed, 43 insertions(+), 7 deletions(-) diff --git a/CMake/modules/FindVulkan.cmake b/CMake/modules/FindVulkan.cmake index 75cc25c7..d3a664a8 100644 --- a/CMake/modules/FindVulkan.cmake +++ b/CMake/modules/FindVulkan.cmake @@ -12,6 +12,9 @@ if (WIN32) find_library(VULKAN_LIBRARY NAMES vulkan-1 HINTS "$ENV{VULKAN_SDK}/Bin" "$ENV{VK_SDK_PATH}/Bin") + find_library(VULKAN_STATIC_LIBRARY NAMES vkstatic.1 HINTS + "$ENV{VULKAN_SDK}/Bin" + "$ENV{VK_SDK_PATH}/Bin") else() find_library(VULKAN_LIBRARY NAMES vulkan-1 HINTS "$ENV{VULKAN_SDK}/Bin32" @@ -27,5 +30,5 @@ endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Vulkan DEFAULT_MSG VULKAN_LIBRARY VULKAN_INCLUDE_DIR) -mark_as_advanced(VULKAN_INCLUDE_DIR VULKAN_LIBRARY) +mark_as_advanced(VULKAN_INCLUDE_DIR VULKAN_LIBRARY VULKAN_STATIC_LIBRARY) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0af226a..b1476bd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ON) option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON) option(GLFW_BUILD_DOCS "Build the GLFW documentation" ON) option(GLFW_INSTALL "Generate installation target" ON) +option(GLFW_VULKAN_STATIC "Use the Vulkan loader statically linked into application" OFF) option(GLFW_DOCUMENT_INTERNALS "Include internals in documentation" OFF) if (WIN32) @@ -57,6 +58,10 @@ else() set(GLFW_LIB_NAME glfw3) endif() +if (GLFW_VULKAN_STATIC) + set(_GLFW_VULKAN_STATIC 1) +endif() + list(APPEND CMAKE_MODULE_PATH "${GLFW_SOURCE_DIR}/CMake/modules") find_package(Threads REQUIRED) @@ -148,6 +153,21 @@ else() message(FATAL_ERROR "No supported platform was detected") endif() +#-------------------------------------------------------------------- +# Add Vulkan static library if requested +#-------------------------------------------------------------------- +if (GLFW_VULKAN_STATIC) + if (VULKAN_FOUND AND VULKAN_STATIC_LIBRARY) + list(APPEND glfw_LIBRARIES ${VULKAN_STATIC_LIBRARY}) + else() + if (BUILD_SHARED_LIBS OR GLFW_BUILD_EXAMPLES OR GLFW_BUILD_TESTS) + message(FATAL_ERROR "Vulkan loader static library not found") + else() + message(WARNING "Vulkan loader static library not found") + endif() + endif() +endif() + #-------------------------------------------------------------------- # Find and add Unix math and time libraries #-------------------------------------------------------------------- diff --git a/README.md b/README.md index 964e0219..f61d1dc4 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,8 @@ information on what to include when reporting a bug. ## Changelog - Added on-demand loading of Vulkan and context creation API libraries + - Added `_GLFW_VULKAN_STATIC` build macro to make the library use the Vulkan + loader linked statically into the application - Bugfix: Single compilation unit builds failed due to naming conflicts (#783) - Bugfix: The range checks for `glfwSetCursorPos` used the wrong minimum (#773) - [Win32] Bugfix: `glfwSetClipboardString` created an unnecessary intermediate @@ -208,6 +210,7 @@ skills. - Emmanuel Gil Peyrot - Cyril Pichard - Pieroman + - Philip Rideout - Jorge Rodriguez - Ed Ropple - Aleksey Rybalkin diff --git a/docs/compile.dox b/docs/compile.dox index adadf779..e1b157ca 100644 --- a/docs/compile.dox +++ b/docs/compile.dox @@ -197,6 +197,9 @@ built along with the library. `GLFW_BUILD_DOCS` determines whether the GLFW documentation is built along with the library. +`GLFW_VULKAN_STATIC` determines whether to use the Vulkan loader linked +statically into the application. + @subsubsection compile_options_osx OS X specific CMake options @@ -251,6 +254,10 @@ ramps and clipboard. The options are: If you are building GLFW as a shared library / dynamic library / DLL then you must also define `_GLFW_BUILD_DLL`. Otherwise, you must not define it. +If you are linking the Vulkan loader statically into your application then you +must also define `_GLFW_VULKAN_STATIC`. Otherwise, GLFW will attempt to use the +external version. + For the EGL context creation API, the following options are available: - `_GLFW_USE_EGLPLATFORM_H` to use `EGL/eglplatform.h` for native handle diff --git a/src/glfw_config.h.in b/src/glfw_config.h.in index 7acbc87a..cf253d36 100644 --- a/src/glfw_config.h.in +++ b/src/glfw_config.h.in @@ -47,6 +47,8 @@ // Define this to 1 if building as a shared library / dynamic library / DLL #cmakedefine _GLFW_BUILD_DLL +// Define this to 1 to use Vulkan loader linked statically into application +#cmakedefine _GLFW_VULKAN_STATIC // Define this to 1 to force use of high-performance GPU on hybrid systems #cmakedefine _GLFW_USE_HYBRID_HPG diff --git a/src/internal.h b/src/internal.h index b35af6a4..8fc685b7 100644 --- a/src/internal.h +++ b/src/internal.h @@ -450,10 +450,10 @@ struct _GLFWlibrary void* handle; char** extensions; uint32_t extensionCount; - #if !defined(_GLFW_VULKAN_STATIC) - PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties; - PFN_vkGetInstanceProcAddr GetInstanceProcAddr; - #endif +#if !defined(_GLFW_VULKAN_STATIC) + PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties; + PFN_vkGetInstanceProcAddr GetInstanceProcAddr; +#endif GLFWbool KHR_surface; GLFWbool KHR_win32_surface; GLFWbool KHR_xlib_surface; diff --git a/src/vulkan.c b/src/vulkan.c index b851402b..fa8e8e99 100644 --- a/src/vulkan.c +++ b/src/vulkan.c @@ -80,7 +80,6 @@ GLFWbool _glfwInitVulkan(void) _glfwTerminateVulkan(); return GLFW_FALSE; } - #endif // _GLFW_VULKAN_STATIC err = vkEnumerateInstanceExtensionProperties(NULL, &count, NULL); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9339ee59..205ec377 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -48,7 +48,9 @@ set(CONSOLE_BINARIES clipboard events msaa gamma glfwinfo if (VULKAN_FOUND) add_executable(vulkan WIN32 vulkan.c ${ICON}) target_include_directories(vulkan PRIVATE "${VULKAN_INCLUDE_DIR}") - target_link_libraries(vulkan "${VULKAN_LIBRARY}") + if (NOT GLFW_VULKAN_STATIC) + target_link_libraries(vulkan "${VULKAN_LIBRARY}") + endif() list(APPEND WINDOWS_BINARIES vulkan) endif()