Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: Add UPDATE_DEPS support #1870

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,15 @@ cmake_minimum_required(VERSION 3.17.2)

project(VULKAN_TOOLS)

add_subdirectory(scripts)

set(API_NAME "Vulkan" CACHE STRING "API name")
add_definitions(-DAPI_NAME="${API_NAME}")

add_definitions(-DVK_ENABLE_BETA_EXTENSIONS)

include(GNUInstallDirs)

if (JSONCPP_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${JSONCPP_INSTALL_DIR})
endif()
if (VULKAN_HEADERS_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${VULKAN_HEADERS_INSTALL_DIR})
endif()
if (GOOGLETEST_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${GOOGLETEST_INSTALL_DIR})
endif()
if (VALIJSON_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${VALIJSON_INSTALL_DIR})
endif()
if (VULKAN_LOADER_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${VULKAN_LOADER_INSTALL_DIR})
endif()
if (VULKAN_VALIDATIONLAYERS_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${VULKAN_VALIDATIONLAYERS_INSTALL_DIR})
endif()

file(TO_CMAKE_PATH "${VULKAN_VALIDATIONLAYERS_INSTALL_DIR}" VULKAN_VALIDATIONLAYERS_INSTALL_DIR)
set(Vulkan-ValidationLayers_INCLUDE_DIR "${VULKAN_VALIDATIONLAYERS_INSTALL_DIR}/include/vulkan")
set(Vulkan-ValidationLayers_LIBRARY_DIR "${VULKAN_VALIDATIONLAYERS_INSTALL_DIR}/lib")
find_library(VkLayer_utils_LIBRARY VkLayer_utils HINTS ${Vulkan-ValidationLayers_LIBRARY_DIR})
Expand Down Expand Up @@ -83,7 +65,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR
CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
CMAKE_SYSTEM_NAME MATCHES "BSD")

option(BUILD_TESTS "Build tests" ON)
option(BUILD_APIDUMP "Build api_dump layer" ON)
option(BUILD_MONITOR "Build monitor layer" ON)
option(BUILD_SCREENSHOT "Build screenshot layer" ON)
Expand All @@ -94,7 +75,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")

option(BUILD_LOADER OFF)
option(BUILD_TESTS OFF)
option(BUILD_APIDUMP "Build api_dump layer" ON)
option(BUILD_MONITOR "Build monitor layer" ON)
option(BUILD_SCREENSHOT "Build screenshot layer" ON)
Expand All @@ -105,6 +85,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")

endif()

option(BUILD_TESTS "Build tests")
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
Expand Down
135 changes: 135 additions & 0 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# ~~~
# Copyright (c) 2023 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.
# ~~~

option(UPDATE_DEPS "Run update_deps.py for user")
if (UPDATE_DEPS)
find_package(Python3 REQUIRED QUIET)

set(update_dep_py "${CMAKE_CURRENT_LIST_DIR}/update_deps.py")
set(known_good_json "${CMAKE_CURRENT_LIST_DIR}/known_good.json")

set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${update_dep_py} ${known_good_json})

list(APPEND update_dep_command "${update_dep_py}")
list(APPEND update_dep_command "--generator")
list(APPEND update_dep_command "${CMAKE_GENERATOR}")

if (CMAKE_GENERATOR_PLATFORM)
list(APPEND update_dep_command "--arch")
list(APPEND update_dep_command "${CMAKE_GENERATOR_PLATFORM}")
endif()

if (NOT CMAKE_BUILD_TYPE)
message(WARNING "CMAKE_BUILD_TYPE not set. Using Debug for dependency build type")
set(_build_type Debug)
else()
set(_build_type ${CMAKE_BUILD_TYPE})
endif()
list(APPEND update_dep_command "--config")
list(APPEND update_dep_command "${_build_type}")

set(UPDATE_DEPS_DIR_SUFFIX "${_build_type}")
if (CMAKE_CROSSCOMPILING)
set(UPDATE_DEPS_DIR_SUFFIX "${CMAKE_SYSTEM_NAME}/${UPDATE_DEPS_DIR_SUFFIX}/${CMAKE_SYSTEM_PROCESSOR}")
else()
math(EXPR bitness "8 * ${CMAKE_SIZEOF_VOID_P}")
set(UPDATE_DEPS_DIR_SUFFIX "${UPDATE_DEPS_DIR_SUFFIX}/${bitness}")
endif()
set(UPDATE_DEPS_DIR "${PROJECT_SOURCE_DIR}/external/${UPDATE_DEPS_DIR_SUFFIX}" CACHE PATH "Location where update_deps.py installs packages")
list(APPEND update_dep_command "--dir" )
list(APPEND update_dep_command "${UPDATE_DEPS_DIR}")

if (NOT BUILD_TESTS)
list(APPEND update_dep_command "--optional=tests")
endif()

if (UPDATE_DEPS_SKIP_EXISTING_INSTALL)
list(APPEND update_dep_command "--skip-existing-install")
endif()

list(APPEND cmake_vars "CMAKE_TOOLCHAIN_FILE")
if (ANDROID)
list(APPEND cmake_vars "ANDROID_PLATFORM" "CMAKE_ANDROID_ARCH_ABI" "CMAKE_ANDROID_STL_TYPE" "CMAKE_ANDROID_RTTI" "CMAKE_ANDROID_EXCEPTIONS" "ANDROID_USE_LEGACY_TOOLCHAIN_FILE")
endif()

set(cmake_var)
foreach(var IN LISTS cmake_vars)
if (DEFINED ${var})
list(APPEND update_dep_command "--cmake_var")
list(APPEND update_dep_command "${var}=${${var}}")
endif()
endforeach()

if (cmake_var)
list(APPEND update_dep_command "${cmake_var}")
endif()

file(TIMESTAMP ${update_dep_py} timestamp_1)
file(TIMESTAMP ${known_good_json} timestamp_2)

string("MD5" md5_hash "${timestamp_1}-${timestamp_2}-${update_dep_command}")

set(UPDATE_DEPS_HASH "0" CACHE STRING "Default value until we run update_deps.py")
mark_as_advanced(UPDATE_DEPS_HASH)

if ("${UPDATE_DEPS_HASH}" STREQUAL "0")
list(APPEND update_dep_command "--clean-build")
list(APPEND update_dep_command "--clean-install")
endif()

if ("${md5_hash}" STREQUAL $CACHE{UPDATE_DEPS_HASH})
message(DEBUG "update_deps.py: no work to do.")
else()
execute_process(
COMMAND ${Python3_EXECUTABLE} ${update_dep_command}
RESULT_VARIABLE _update_deps_result
)
if (NOT (${_update_deps_result} EQUAL 0))
message(FATAL_ERROR "Could not run update_deps.py which is necessary to download dependencies.")
endif()
set(UPDATE_DEPS_HASH ${md5_hash} CACHE STRING "Ensure we only run update_deps.py when we need to." FORCE)
include("${UPDATE_DEPS_DIR}/helper.cmake")
endif()
endif()

if (JSONCPP_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${JSONCPP_INSTALL_DIR})
endif()
if (VULKAN_HEADERS_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${VULKAN_HEADERS_INSTALL_DIR})
endif()
if (GOOGLETEST_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${GOOGLETEST_INSTALL_DIR})
endif()
if (VALIJSON_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${VALIJSON_INSTALL_DIR})
endif()
if (VULKAN_LOADER_INSTALL_DIR)
list(APPEND CMAKE_PREFIX_PATH ${VULKAN_LOADER_INSTALL_DIR})
endif()

# TODO: Remove VVL as a dependency. Use the utility libraries.
if (VULKAN_VALIDATIONLAYERS_INSTALL_DIR)
list(APPEND CMAKE_INCLUDE_PATH ${VULKAN_VALIDATIONLAYERS_INSTALL_DIR}/include/vulkan)
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} PARENT_SCOPE)
list(APPEND CMAKE_PREFIX_PATH ${VULKAN_VALIDATIONLAYERS_INSTALL_DIR})
endif()

if (CMAKE_CROSSCOMPILING)
set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_PREFIX_PATH} PARENT_SCOPE)
else()
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} PARENT_SCOPE)
endif()
12 changes: 3 additions & 9 deletions scripts/github_ci_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,17 @@ def CreateBuildDirectory(dir_path):
#
# Prepare the tools for testing
def BuildVT(args):

print("Log CMake version")
cmake_ver_cmd = 'cmake --version'
RunShellCmd(cmake_ver_cmd)

print("Run update_deps.py for VT Repository")
update_cmd = 'python3 scripts/update_deps.py --dir %s --config %s --arch x64' % (EXTERNAL_DIR_NAME, args.configuration)
RunShellCmd(update_cmd)

CreateBuildDirectory(VT_BUILD_DIR)
print("Run CMake")
cmake_cmd = 'cmake -C ../%s/helper.cmake -DCMAKE_BUILD_TYPE=%s ..' % (EXTERNAL_DIR_NAME, args.configuration.capitalize())
RunShellCmd(cmake_cmd, VT_BUILD_DIR)
cmake_cmd = f'cmake -S . -B {VT_BUILD_DIR} -D UPDATE_DEPS_DIR={EXTERNAL_DIR} -DUPDATE_DEPS=ON -DBUILD_TESTS=ON'
RunShellCmd(cmake_cmd)

print("Build Vulkan Tools")
os.chdir(VT_BUILD_DIR)
build_cmd = 'cmake --build . -- -j%s' % os.cpu_count()
build_cmd = f'cmake --build {VT_BUILD_DIR} --parallel {os.cpu_count()}'
RunShellCmd(build_cmd, VT_BUILD_DIR)

print("Run Vulkan Tools Tests")
Expand Down
12 changes: 4 additions & 8 deletions scripts/github_ci_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,14 @@ def CreateBuildDirectory(dir_path):
def BuildVT(args):
print("Build Configuration: %s %s" % (args.arch, args.configuration))

print("Run update_deps.py for VT Repository")
update_cmd = 'python3 scripts/update_deps.py --dir %s --config %s --arch %s' % (EXTERNAL_DIR_NAME, args.configuration.lower(), args.arch.lower())
RunShellCmd(update_cmd)

CreateBuildDirectory(VT_BUILD_DIR)
print("Run CMake")
cmake_cmd = 'cmake -A %s -C ../%s/helper.cmake ..' % (args.arch, EXTERNAL_DIR_NAME)
RunShellCmd(cmake_cmd, VT_BUILD_DIR)
cmake_cmd = f'cmake -S . -B {VT_BUILD_DIR} -D UPDATE_DEPS_DIR={EXTERNAL_DIR} -DUPDATE_DEPS=ON -DBUILD_TESTS=ON '
cmake_cmd += f' -A {args.arch}'
RunShellCmd(cmake_cmd)

print("Build Vulkan Tools")
os.chdir(VT_BUILD_DIR)
build_cmd = 'cmake --build . --parallel %s' % os.cpu_count()
build_cmd = f'cmake --build {VT_BUILD_DIR} --config {args.configuration} --parallel {os.cpu_count()}'
RunShellCmd(build_cmd, VT_BUILD_DIR)

print("Run Vulkan Tools Tests")
Expand Down