From eaef91448707952ca0ca5c84f9d688d02bda21e0 Mon Sep 17 00:00:00 2001 From: Sebastian Parborg Date: Fri, 10 Nov 2023 18:10:41 +0100 Subject: [PATCH] CMake: Allow building with system Vulkan and ShaderC Previously the cmake code would try to run the LIBDIR specific "findX.cmake" files for both vulkan and shaderc. However these would pick up system headers and libraries when LIBDIR were not present. This would lead to compilation errors as the system library configurations were not taken into account or queried. This changes it so that if LIBDIR is not present, the proper pkgconfig files will be used instead. Pull Request: https://projects.blender.org/blender/blender/pulls/114639 --- build_files/cmake/Modules/FindShaderC.cmake | 6 ------ build_files/cmake/Modules/FindVulkan.cmake | 6 ------ build_files/cmake/platform/platform_unix.cmake | 18 ++++++++++++++++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/build_files/cmake/Modules/FindShaderC.cmake b/build_files/cmake/Modules/FindShaderC.cmake index 665b3a99b1e..32784ec3af7 100644 --- a/build_files/cmake/Modules/FindShaderC.cmake +++ b/build_files/cmake/Modules/FindShaderC.cmake @@ -26,12 +26,6 @@ set(_shaderc_SEARCH_DIRS ${SHADERC_ROOT_DIR} ) -# FIXME: These finder modules typically don't use LIBDIR, -# this should be set by `./build_files/cmake/platform/` instead. -if(DEFINED LIBDIR) - set(_shaderc_SEARCH_DIRS ${_shaderc_SEARCH_DIRS} ${LIBDIR}/shaderc) -endif() - find_path(SHADERC_INCLUDE_DIR NAMES shaderc/shaderc.h diff --git a/build_files/cmake/Modules/FindVulkan.cmake b/build_files/cmake/Modules/FindVulkan.cmake index 84c73a0d57c..26ef6d5001a 100644 --- a/build_files/cmake/Modules/FindVulkan.cmake +++ b/build_files/cmake/Modules/FindVulkan.cmake @@ -26,12 +26,6 @@ set(_vulkan_SEARCH_DIRS ${VULKAN_ROOT_DIR} ) -# FIXME: These finder modules typically don't use LIBDIR, -# this should be set by `./build_files/cmake/platform/` instead. -if(DEFINED LIBDIR) - set(_vulkan_SEARCH_DIRS ${_vulkan_SEARCH_DIRS} ${LIBDIR}/vulkan) -endif() - find_path(VULKAN_INCLUDE_DIR NAMES vulkan/vulkan.h diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake index f9daa47c9d1..71e09e228ce 100644 --- a/build_files/cmake/platform/platform_unix.cmake +++ b/build_files/cmake/platform/platform_unix.cmake @@ -116,8 +116,22 @@ find_package_wrapper(Epoxy REQUIRED) find_package(TIFF) if(WITH_VULKAN_BACKEND) - find_package_wrapper(Vulkan REQUIRED) - find_package_wrapper(ShaderC REQUIRED) + if((DEFINED LIBDIR) AND (EXISTS "${LIBDIR}/vulkan") AND (EXISTS "${LIBDIR}/shaderc")) + if(NOT DEFINED VULKAN_ROOT_DIR) + set(VULKAN_ROOT_DIR ${LIBDIR}/vulkan) + endif() + if(NOT DEFINED SHADERC_ROOT_DIR) + set(SHADERC_ROOT_DIR ${LIBDIR}/shaderc) + endif() + + find_package_wrapper(Vulkan REQUIRED) + find_package_wrapper(ShaderC REQUIRED) + else() + # Use system libs + find_package(PkgConfig) + pkg_check_modules(VULKAN REQUIRED vulkan) + pkg_check_modules(SHADERC REQUIRED shaderc) + endif() endif() add_bundled_libraries(vulkan/lib)