[cmake] Check for deps before adding. When embedding SwitftShader into a third party application, the top level cmake files may already include googletest and SPIRV-Tools. This CL updates the SwiftShader tests to only try to pull in googletest if the `gtest` target is not found and only pull in SPIRV-Tools if the `SPIRV-Tools` target is not found. Change-Id: I3c3ebb528725017dbbb80aa05b01ee2de8d4a2d1 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/26788 Reviewed-by: Ben Clayton <bclayton@google.com> Reviewed-by: Nicolas Capens <nicolascapens@google.com> Tested-by: Dan Sinclair <dsinclair@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt index 45e0f33..9efd51a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -109,13 +109,15 @@ # Initialize submodules ########################################################### -if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest/.git) - message(WARNING " - third_party/googletest submodule missing. - Running 'git submodule update --init' to download it: - ") +if (NOT TARGET gtest) + if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest/.git) + message(WARNING " + third_party/googletest submodule missing. + Running 'git submodule update --init' to download it: + ") - execute_process(COMMAND git submodule update --init) + execute_process(COMMAND git submodule update --init) + endif() endif() ########################################################### @@ -2234,11 +2236,13 @@ endif() if(BUILD_VULKAN) - # This variable is also used by SPIRV-Tools to locate SPIRV-Headers - set(SPIRV-Headers_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/SPIRV-Headers") - list(APPEND VULKAN_INCLUDE_DIR "${SPIRV-Headers_SOURCE_DIR}/include") + if (NOT TARGET SPIRV-Tools) + # This variable is also used by SPIRV-Tools to locate SPIRV-Headers + set(SPIRV-Headers_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/SPIRV-Headers") + list(APPEND VULKAN_INCLUDE_DIR "${SPIRV-Headers_SOURCE_DIR}/include") - add_subdirectory(third_party/SPIRV-Tools) + add_subdirectory(third_party/SPIRV-Tools) + endif() add_library(libvk_swiftshader SHARED ${VULKAN_LIST}) set_target_properties(libvk_swiftshader PROPERTIES