OSDN Git Service

[cmake] Check for deps before adding.
authorDan Sinclair <dsinclair@google.com>
Mon, 11 Mar 2019 14:48:19 +0000 (10:48 -0400)
committerDan Sinclair <dsinclair@google.com>
Wed, 13 Mar 2019 18:00:31 +0000 (18:00 +0000)
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>
CMakeLists.txt

index 45e0f33..9efd51a 100644 (file)
@@ -109,13 +109,15 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
 # 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:
-    ")
-
-    execute_process(COMMAND git submodule update --init)
+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)
+    endif()
 endif()
 
 ###########################################################
@@ -2234,11 +2236,13 @@ if(BUILD_GLES_CM)
 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