1# ~~~ 2# Copyright (c) 2018 Valve Corporation 3# Copyright (c) 2018 LunarG, Inc. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# ~~~ 17 18# Add your optional dependencies in this "external" directory. 19 20# googletest is an optional external dependency for this repo. 21if(BUILD_TESTS) 22 # Attempt to enable googletest if available. 23 24 # Suppress all warnings from external projects (i.e.: in this directory's scope). 25 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 26 set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-w") 27 endif() 28 29 if(TARGET gtest_main) 30 # Already enabled as a target (perhaps by a project enclosing this one) 31 message(STATUS "Vulkan-ValidationLayers/external: " "googletest already configured - using it") 32 elseif(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/googletest") 33 # The googletest directory exists, so enable it as a target. 34 message(STATUS "Vulkan-ValidationLayers/external: " "googletest found - configuring it for tests") 35 set(BUILD_GTEST ON CACHE BOOL "Builds the googletest subproject") 36 set(BUILD_GMOCK OFF CACHE BOOL "Builds the googlemock subproject") 37 set(gtest_force_shared_crt ON CACHE BOOL "Link gtest runtimes dynamically") 38 set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries") 39 # EXCLUDE_FROM_ALL keeps the install target from installing GTEST files. 40 add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/googletest" EXCLUDE_FROM_ALL) 41 else() 42 message(SEND_ERROR "Vulkan-ValidationLayers/external: " "Google Test was not found. " 43 "Provide Google Test in external/googletest or set BUILD_TESTS=OFF") 44 endif() 45endif() 46