| 1 |
# ~~~ |
| 2 |
# Copyright (c) 2023 LunarG, Inc. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
# you may not use this file except in compliance with the License. |
| 6 |
# You may obtain a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
# See the License for the specific language governing permissions and |
| 14 |
# limitations under the License. |
| 15 |
# ~~~ |
| 16 |
|
| 17 |
option(UPDATE_DEPS "Run update_deps.py for user") |
| 18 |
if (UPDATE_DEPS) |
| 19 |
find_package(Python3 REQUIRED QUIET) |
| 20 |
|
| 21 |
set(update_dep_py "${CMAKE_CURRENT_LIST_DIR}/update_deps.py") |
| 22 |
set(known_good_json "${CMAKE_CURRENT_LIST_DIR}/known_good.json") |
| 23 |
|
| 24 |
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${update_dep_py} ${known_good_json}) |
| 25 |
|
| 26 |
list(APPEND update_dep_command "${update_dep_py}") |
| 27 |
list(APPEND update_dep_command "--generator") |
| 28 |
list(APPEND update_dep_command "${CMAKE_GENERATOR}") |
| 29 |
|
| 30 |
if (CMAKE_GENERATOR_PLATFORM) |
| 31 |
list(APPEND update_dep_command "--arch") |
| 32 |
list(APPEND update_dep_command "${CMAKE_GENERATOR_PLATFORM}") |
| 33 |
endif() |
| 34 |
|
| 35 |
if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES ";") |
| 36 |
list(APPEND update_dep_command "--osx-archs") |
| 37 |
string(REPLACE ";" ":" osx_archs "${CMAKE_OSX_ARCHITECTURES}") |
| 38 |
list(APPEND update_dep_command "${osx_archs}") |
| 39 |
|
| 40 |
set(APPLE_UNIVERSAL_BINARY ON) |
| 41 |
endif() |
| 42 |
|
| 43 |
if (NOT CMAKE_BUILD_TYPE) |
| 44 |
message(WARNING "CMAKE_BUILD_TYPE not set. Using Debug for dependency build type") |
| 45 |
set(_build_type Debug) |
| 46 |
else() |
| 47 |
set(_build_type ${CMAKE_BUILD_TYPE}) |
| 48 |
endif() |
| 49 |
list(APPEND update_dep_command "--config") |
| 50 |
list(APPEND update_dep_command "${_build_type}") |
| 51 |
list(APPEND update_dep_command "--api") |
| 52 |
list(APPEND update_dep_command "${API_TYPE}") |
| 53 |
|
| 54 |
set(UPDATE_DEPS_DIR_SUFFIX "${_build_type}") |
| 55 |
if (CMAKE_CROSSCOMPILING) |
| 56 |
if (APPLE_UNIVERSAL_BINARY) |
| 57 |
set(UPDATE_DEPS_DIR_SUFFIX "${CMAKE_SYSTEM_NAME}/${UPDATE_DEPS_DIR_SUFFIX}/universal") |
| 58 |
else() |
| 59 |
set(UPDATE_DEPS_DIR_SUFFIX "${CMAKE_SYSTEM_NAME}/${UPDATE_DEPS_DIR_SUFFIX}/${CMAKE_SYSTEM_PROCESSOR}") |
| 60 |
endif() |
| 61 |
else() |
| 62 |
if (APPLE_UNIVERSAL_BINARY) |
| 63 |
set(UPDATE_DEPS_DIR_SUFFIX "${UPDATE_DEPS_DIR_SUFFIX}/universal") |
| 64 |
else() |
| 65 |
math(EXPR bitness "8 * ${CMAKE_SIZEOF_VOID_P}") |
| 66 |
set(UPDATE_DEPS_DIR_SUFFIX "${UPDATE_DEPS_DIR_SUFFIX}/${bitness}") |
| 67 |
endif() |
| 68 |
endif() |
| 69 |
set(UPDATE_DEPS_DIR "${PROJECT_SOURCE_DIR}/external/${UPDATE_DEPS_DIR_SUFFIX}" CACHE PATH "Location where update_deps.py installs packages") |
| 70 |
list(APPEND update_dep_command "--dir" ) |
| 71 |
list(APPEND update_dep_command "${UPDATE_DEPS_DIR}") |
| 72 |
|
| 73 |
if (NOT BUILD_TESTS) |
| 74 |
list(APPEND update_dep_command "--optional=tests") |
| 75 |
endif() |
| 76 |
|
| 77 |
if (UPDATE_DEPS_SKIP_EXISTING_INSTALL) |
| 78 |
list(APPEND update_dep_command "--skip-existing-install") |
| 79 |
endif() |
| 80 |
|
| 81 |
list(APPEND cmake_vars "CMAKE_TOOLCHAIN_FILE") |
| 82 |
|
| 83 |
# Avoids manually setting CMAKE_SYSTEM_NAME unless it's needed: |
| 84 |
# https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING.html |
| 85 |
if (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "${CMAKE_HOST_SYSTEM_NAME}") |
| 86 |
list(APPEND cmake_vars "CMAKE_SYSTEM_NAME") |
| 87 |
endif() |
| 88 |
if (APPLE) |
| 89 |
list(APPEND cmake_vars "CMAKE_OSX_DEPLOYMENT_TARGET") |
| 90 |
endif() |
| 91 |
if (NOT MSVC_IDE) |
| 92 |
list(APPEND cmake_vars "CMAKE_CXX_COMPILER" "CMAKE_C_COMPILER" "CMAKE_ASM_COMPILER") |
| 93 |
endif() |
| 94 |
if (ANDROID) |
| 95 |
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") |
| 96 |
endif() |
| 97 |
|
| 98 |
set(cmake_var) |
| 99 |
foreach(var IN LISTS cmake_vars) |
| 100 |
if (DEFINED ${var}) |
| 101 |
list(APPEND update_dep_command "--cmake_var") |
| 102 |
list(APPEND update_dep_command "${var}=${${var}}") |
| 103 |
endif() |
| 104 |
endforeach() |
| 105 |
|
| 106 |
if (cmake_var) |
| 107 |
list(APPEND update_dep_command "${cmake_var}") |
| 108 |
endif() |
| 109 |
|
| 110 |
file(TIMESTAMP ${update_dep_py} timestamp_1) |
| 111 |
file(TIMESTAMP ${known_good_json} timestamp_2) |
| 112 |
|
| 113 |
string("MD5" md5_hash "${timestamp_1}-${timestamp_2}-${update_dep_command}") |
| 114 |
|
| 115 |
set(UPDATE_DEPS_HASH "0" CACHE STRING "Default value until we run update_deps.py") |
| 116 |
mark_as_advanced(UPDATE_DEPS_HASH) |
| 117 |
|
| 118 |
if ("${UPDATE_DEPS_HASH}" STREQUAL "0") |
| 119 |
list(APPEND update_dep_command "--clean-build") |
| 120 |
list(APPEND update_dep_command "--clean-install") |
| 121 |
endif() |
| 122 |
|
| 123 |
if ("${md5_hash}" STREQUAL $CACHE{UPDATE_DEPS_HASH}) |
| 124 |
message(DEBUG "update_deps.py: no work to do.") |
| 125 |
else() |
| 126 |
execute_process( |
| 127 |
COMMAND ${Python3_EXECUTABLE} ${update_dep_command} |
| 128 |
RESULT_VARIABLE _update_deps_result |
| 129 |
) |
| 130 |
if (NOT (${_update_deps_result} EQUAL 0)) |
| 131 |
message(FATAL_ERROR "Could not run update_deps.py which is necessary to download dependencies.") |
| 132 |
endif() |
| 133 |
set(UPDATE_DEPS_HASH ${md5_hash} CACHE STRING "Ensure we only run update_deps.py when we need to." FORCE) |
| 134 |
include("${UPDATE_DEPS_DIR}/helper.cmake") |
| 135 |
endif() |
| 136 |
endif() |
| 137 |
if (VULKAN_HEADERS_INSTALL_DIR) |
| 138 |
list(APPEND CMAKE_PREFIX_PATH ${VULKAN_HEADERS_INSTALL_DIR}) |
| 139 |
set(CMAKE_REQUIRE_FIND_PACKAGE_VulkanHeaders TRUE PARENT_SCOPE) |
| 140 |
endif() |
| 141 |
|
| 142 |
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} PARENT_SCOPE) |
| 143 |
|
| 144 |
if (CMAKE_CROSSCOMPILING) |
| 145 |
set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_PREFIX_PATH} PARENT_SCOPE) |
| 146 |
endif() |