build: Move test dependencies to known_good.json

This makes the requisite changes to make the dependencies needed for testing automatically
downloaded by cmake when the UPDATE_DEPS option is given.
This commit is contained in:
Charles Giessen 2021-09-23 15:15:08 -06:00 committed by Charles Giessen
parent 5f67bbd6d8
commit 69fc7ecb20
5 changed files with 155 additions and 176 deletions

View File

@ -73,23 +73,16 @@ contains the Vulkan API definition files (registry) that are required to build
the loader. You must also take note of the headers install directory and pass
it on the CMake command line for building this repository, as described below.
#### Google Test
#### Test Dependencies
The loader tests depend on the [Google Test](https://github.com/google/googletest)
framework and do not build unless this framework is downloaded into the
repository's `external` directory.
The loader tests depend on the [Google Test](https://github.com/google/googletest) library and
on Windows platforms depends on the [Microsoft Detours](https://github.com/microsoft/Detours) library.
To obtain the framework, change your current directory to the top of your
Vulkan-Loader repository and run:
git clone https://github.com/google/googletest.git external/googletest
cd external/googletest
git checkout tags/release-1.10.0
before configuring your build with CMake.
If you do not need the loader tests, there is no need to download this
framework.
To build the tests, pass the `DUPDATE_DEPS=ON` and `-DBUILD_TESTS=ON` options when generating the project:
```bash
cmake ... -DUPDATE_DEPS=ON -DBUILD_TESTS=ON ...
```
This will ensure googletest and detours is downloaded and the appropriate version is used.
### Build and Install Directories

View File

@ -49,6 +49,11 @@ if (UPDATE_DEPS)
set(_build_type ${CMAKE_BUILD_TYPE})
endif()
set(_build_tests_arg "")
if (NOT BUILD_TESTS)
set(_build_tests_arg "--optional=tests")
endif()
message("********************************************************************************")
message("* NOTE: Adding target vl_update_deps to run as needed for updating *")
message("* dependencies. *")
@ -84,11 +89,7 @@ endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(PythonInterp 3 QUIET)
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest)
option(BUILD_TESTS "Build Tests" ON)
else()
option(BUILD_TESTS "Build Tests" OFF)
endif()
option(BUILD_TESTS "Build Tests" OFF)
if(BUILD_TESTS)
enable_testing()
@ -331,7 +332,104 @@ if(BUILD_LOADER)
add_subdirectory(loader)
endif()
add_subdirectory(external)
if(BUILD_TESTS)
add_subdirectory(tests)
# Set gtest build configuration
# Attempt to enable if it is available.
if(TARGET gtest)
# Already enabled as a target (perhaps by a project enclosing this one)
message(STATUS "Vulkan-Loader/external: " "googletest already configured - using it")
elseif(IS_DIRECTORY "${GOOGLETEST_INSTALL_DIR}/googletest")
set(BUILD_GTEST ON CACHE BOOL "Builds the googletest subproject")
set(BUILD_GMOCK OFF CACHE BOOL "Builds the googlemock subproject")
set(gtest_force_shared_crt ON CACHE BOOL "Link gtest runtimes dynamically")
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
# The googletest directory exists, so enable it as a target.
message(STATUS "Vulkan-Loader/external: " "googletest found - configuring it for tests")
add_subdirectory("${GOOGLETEST_INSTALL_DIR}/googletest")
else()
message(SEND_ERROR "Could not find googletest directory. Be sure to run update_deps.py with the --tests option to download the appropriate version of googletest")
set(BUILD_TESTS OFF)
endif()
if (WIN32)
if(TARGET detours)
# Already enabled as a target (perhaps by a project enclosing this one)
message(STATUS "Vulkan-Loader/external: " "detours already configured - using it")
else()
if(IS_DIRECTORY ${DETOURS_INSTALL_DIR})
# The detours directory exists, so enable it as a target.
message(STATUS "Vulkan-Loader/external: " "detours found - configuring it for tests")
else()
message(SEND_ERROR "Could not find detours directory. Be sure to run update_deps.py with the --tests option to download the appropriate version of detours")
set(BUILD_TESTS OFF)
endif()
add_library(detours STATIC
${DETOURS_INSTALL_DIR}/src/creatwth.cpp
${DETOURS_INSTALL_DIR}/src/detours.cpp
${DETOURS_INSTALL_DIR}/src/detours.h
${DETOURS_INSTALL_DIR}/src/detver.h
${DETOURS_INSTALL_DIR}/src/disasm.cpp
${DETOURS_INSTALL_DIR}/src/disolarm.cpp
${DETOURS_INSTALL_DIR}/src/disolarm64.cpp
${DETOURS_INSTALL_DIR}/src/disolia64.cpp
${DETOURS_INSTALL_DIR}/src/disolx64.cpp
${DETOURS_INSTALL_DIR}/src/disolx86.cpp
${DETOURS_INSTALL_DIR}/src/image.cpp
${DETOURS_INSTALL_DIR}/src/modules.cpp
)
target_include_directories(detours PUBLIC ${DETOURS_INSTALL_DIR}/src)
macro(GET_WIN32_WINNT version)
if(WIN32 AND CMAKE_SYSTEM_VERSION)
set(ver ${CMAKE_SYSTEM_VERSION})
string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
# Check for Windows 10, b/c we'll need to convert to hex 'A'.
if("${verMajor}" MATCHES "10")
set(verMajor "A")
string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
endif("${verMajor}" MATCHES "10")
# Remove all remaining '.' characters.
string(REPLACE "." "" ver ${ver})
# Prepend each digit with a zero.
string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
set(${version} "0x${ver}")
endif()
endmacro()
set(DETOURS_MAJOR_VERSION "4")
set(DETOURS_MINOR_VERSION "0")
set(DETOURS_PATCH_VERSION "1")
set(DETOURS_VERSION "${DETOURS_MAJOR_VERSION}.${DETOURS_MINOR_VERSION}.${DETOURS_PATCH_VERSION}")
target_include_directories(detours PUBLIC ${DETOURS_INSTALL_DIR}/src)
if(MSVC_VERSION GREATER_EQUAL 1700)
target_compile_definitions(detours PUBLIC DETOURS_CL_17_OR_NEWER)
endif(MSVC_VERSION GREATER_EQUAL 1700)
GET_WIN32_WINNT(ver)
if(ver EQUAL 0x0700)
target_compile_definitions(detours PUBLIC _USING_V110_SDK71_ DETOURS_WIN_7)
endif(ver EQUAL 0x0700)
target_compile_definitions(detours PUBLIC "_WIN32_WINNT=${ver}")
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
target_compile_definitions(detours PUBLIC "DETOURS_TARGET_PROCESSOR=X64" DETOURS_X64 DETOURS_64BIT _AMD64_)
else("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
target_compile_definitions(detours PUBLIC "DETOURS_TARGET_PROCESSOR=X86" DETOURS_X86 _X86_)
endif("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
target_compile_definitions(detours PUBLIC "DETOURS_VERSION=0x4c0c1" WIN32_LEAN_AND_MEAN)
if(MSVC)
target_compile_definitions(detours PUBLIC "_CRT_SECURE_NO_WARNINGS=1")
set_target_properties(detours PROPERTIES COMPILE_FLAGS /EHsc)
endif()
endif()
endif()
if (BUILD_TESTS)
add_subdirectory(tests ${CMAKE_BINARY_DIR}/tests)
endif()
endif()

View File

@ -1,114 +0,0 @@
# ~~~
# Copyright (c) 2018 Valve Corporation
# Copyright (c) 2018 LunarG, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ~~~
# Add your optional dependencies in this "external" directory.
# googletest is an optional external dependency for this repo.
if(BUILD_TESTS)
# Set gtest build configuration
set(BUILD_GTEST ON CACHE BOOL "Builds the googletest subproject")
set(BUILD_GMOCK OFF CACHE BOOL "Builds the googlemock subproject")
set(gtest_force_shared_crt ON CACHE BOOL "Link gtest runtimes dynamically")
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
# Attempt to enable if it is available.
if(TARGET gtest)
# Already enabled as a target (perhaps by a project enclosing this one)
message(STATUS "Vulkan-Loader/external: " "googletest already configured - using it")
elseif(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/googletest")
# The googletest directory exists, so enable it as a target.
message(STATUS "Vulkan-Loader/external: " "googletest found - configuring it for tests")
# EXCLUDE_FROM_ALL keeps the install target from installing GTEST files.
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/googletest" EXCLUDE_FROM_ALL)
else()
message(FATAL_ERROR "Vulkan-Loader/external: Google Test was not found. Please download it and place it in this folder")
endif()
if (WIN32)
if(TARGET detours)
# Already enabled as a target (perhaps by a project enclosing this one)
message(STATUS "Vulkan-Loader/external: " "detours already configured - using it")
else()
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/detours")
# The detours directory exists, so enable it as a target.
message(STATUS "Vulkan-Loader/external: " "detours found - configuring it for tests")
else()
message(FATAL_ERROR "Vulkan-Loader/external: Microsoft Detours was not found. Please download it and place it in this folder")
endif()
add_library(detours STATIC
${CMAKE_CURRENT_SOURCE_DIR}/detours/src/creatwth.cpp
${CMAKE_CURRENT_SOURCE_DIR}/detours/src/detours.cpp
${CMAKE_CURRENT_SOURCE_DIR}/detours/src/detours.h
${CMAKE_CURRENT_SOURCE_DIR}/detours/src/detver.h
${CMAKE_CURRENT_SOURCE_DIR}/detours/src/disasm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/detours/src/disolarm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/detours/src/disolarm64.cpp
${CMAKE_CURRENT_SOURCE_DIR}/detours/src/disolia64.cpp
${CMAKE_CURRENT_SOURCE_DIR}/detours/src/disolx64.cpp
${CMAKE_CURRENT_SOURCE_DIR}/detours/src/disolx86.cpp
${CMAKE_CURRENT_SOURCE_DIR}/detours/src/image.cpp
${CMAKE_CURRENT_SOURCE_DIR}/detours/src/modules.cpp
)
target_include_directories(detours PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/detours/src)
macro(GET_WIN32_WINNT version)
if(WIN32 AND CMAKE_SYSTEM_VERSION)
set(ver ${CMAKE_SYSTEM_VERSION})
string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
# Check for Windows 10, b/c we'll need to convert to hex 'A'.
if("${verMajor}" MATCHES "10")
set(verMajor "A")
string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
endif("${verMajor}" MATCHES "10")
# Remove all remaining '.' characters.
string(REPLACE "." "" ver ${ver})
# Prepend each digit with a zero.
string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
set(${version} "0x${ver}")
endif()
endmacro()
set(DETOURS_MAJOR_VERSION "4")
set(DETOURS_MINOR_VERSION "0")
set(DETOURS_PATCH_VERSION "1")
set(DETOURS_VERSION "${DETOURS_MAJOR_VERSION}.${DETOURS_MINOR_VERSION}.${DETOURS_PATCH_VERSION}")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/detours/src")
if(MSVC_VERSION GREATER_EQUAL 1700)
target_compile_definitions(detours PUBLIC DETOURS_CL_17_OR_NEWER)
endif(MSVC_VERSION GREATER_EQUAL 1700)
GET_WIN32_WINNT(ver)
if(ver EQUAL 0x0700)
target_compile_definitions(detours PUBLIC _USING_V110_SDK71_ DETOURS_WIN_7)
endif(ver EQUAL 0x0700)
target_compile_definitions(detours PUBLIC "_WIN32_WINNT=${ver}")
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
target_compile_definitions(detours PUBLIC "DETOURS_TARGET_PROCESSOR=X64" DETOURS_X64 DETOURS_64BIT _AMD64_)
else("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
target_compile_definitions(detours PUBLIC "DETOURS_TARGET_PROCESSOR=X86" DETOURS_X86 _X86_)
endif("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
target_compile_definitions(detours PUBLIC "DETOURS_VERSION=0x4c0c1" WIN32_LEAN_AND_MEAN)
if(MSVC)
target_compile_definitions(detours PUBLIC "_CRT_SECURE_NO_WARNINGS=1")
set_target_properties(detours PROPERTIES COMPILE_FLAGS /EHsc)
endif()
endif()
endif()
endif()

27
external/README.md vendored
View File

@ -1,27 +0,0 @@
# External dependencies
This directory provides a location where external projects can be cloned that are used by the loader.
Tests require GoogleTest on all platforms and Detours on Windows only.
The dependencies for testing need to be manually downloaded into this folder. CMake configuring will fail if they are not present
If the repositories are already in the `external` folder, then CMake won't download them.
To download googletest
```
git clone https://github.com/google/googletest.git
```
To download Detours (only necessary for Windows)
```
git clone https://github.com/microsoft/Detours.git
```
If you don't have a local install of the Vulkan Headers they can be placed in
the externals folder with:
```
git clone https://github.com/KhronosGroup/Vulkan-Headers.git
```

View File

@ -1,15 +1,44 @@
{
"repos" : [
{
"name" : "Vulkan-Headers",
"url" : "https://github.com/KhronosGroup/Vulkan-Headers.git",
"sub_dir" : "Vulkan-Headers",
"build_dir" : "Vulkan-Headers/build",
"install_dir" : "Vulkan-Headers/build/install",
"commit" : "v1.2.194"
"repos": [
{
"name": "Vulkan-Headers",
"url": "https://github.com/KhronosGroup/Vulkan-Headers.git",
"sub_dir": "Vulkan-Headers",
"build_dir": "Vulkan-Headers/build",
"install_dir": "Vulkan-Headers/build/install",
"commit": "v1.2.194"
},
{
"name": "googletest",
"url": "https://github.com/google/googletest.git",
"sub_dir": "googletest",
"build_dir": "googletest",
"install_dir": "googletest",
"build_step": "skip",
"commit": "release-1.10.0",
"optional": [
"tests"
]
},
{
"name": "detours",
"url": "https://github.com/microsoft/Detours.git",
"sub_dir": "detours",
"build_dir": "detours",
"install_dir": "detours",
"build_step": "skip",
"commit": "v4.0.1",
"optional": [
"tests"
],
"build_platforms": [
"windows"
]
}
],
"install_names": {
"Vulkan-Headers": "VULKAN_HEADERS_INSTALL_DIR",
"googletest": "GOOGLETEST_INSTALL_DIR",
"detours": "DETOURS_INSTALL_DIR"
}
],
"install_names" : {
"Vulkan-Headers" : "VULKAN_HEADERS_INSTALL_DIR"
}
}
}