diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/CMakeLists.txt | 120 | ||||
| -rwxr-xr-x | scripts/update_deps.py | 55 |
2 files changed, 142 insertions, 33 deletions
diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt new file mode 100644 index 00000000..5b979d43 --- /dev/null +++ b/scripts/CMakeLists.txt @@ -0,0 +1,120 @@ +# ~~~ +# 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) + set(_target_arch ${CMAKE_GENERATOR_PLATFORM}) + else() + if (MSVC_IDE) + message(WARNING "CMAKE_GENERATOR_PLATFORM not set. Using x64 as target architecture.") + endif() + set(_target_arch x64) + endif() + list(APPEND update_dep_command "--arch") + list(APPEND update_dep_command "${_target_arch}") + + 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 (ANDROID) + set(UPDATE_DEPS_DIR_SUFFIX "android/${UPDATE_DEPS_DIR_SUFFIX}") + 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 ("${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} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + 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 (VULKAN_HEADERS_INSTALL_DIR) + list(APPEND CMAKE_PREFIX_PATH ${VULKAN_HEADERS_INSTALL_DIR}) +endif() +if (VULKAN_LOADER_INSTALL_DIR) + list(APPEND CMAKE_PREFIX_PATH ${VULKAN_LOADER_INSTALL_DIR}) +endif() +if (MOLTENVK_REPO_ROOT) + list(APPEND CMAKE_PREFIX_PATH ${MOLTENVK_REPO_ROOT}) +endif() + +if (CMAKE_CROSSCOMPILING) + set(CMAKE_FIND_ROOT_PATH ${CMAKE_PREFIX_PATH} PARENT_SCOPE) +else() + set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} PARENT_SCOPE) +endif() diff --git a/scripts/update_deps.py b/scripts/update_deps.py index ff09871b..7664a55f 100755 --- a/scripts/update_deps.py +++ b/scripts/update_deps.py @@ -1,8 +1,8 @@ #!/usr/bin/env python # Copyright 2017 The Glslang Authors. All rights reserved. -# Copyright (c) 2018 Valve Corporation -# Copyright (c) 2018-2021 LunarG, Inc. +# Copyright (c) 2018-2023 Valve Corporation +# Copyright (c) 2018-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. @@ -206,11 +206,6 @@ A list of options to pass to CMake during the generation phase. A list of environment variables where one must be set to "true" (case-insensitive) in order for this repo to be fetched and built. This list can be used to specify repos that should be built only in CI. -Typically, this list might contain "TRAVIS" and/or "APPVEYOR" because -each of these CI systems sets an environment variable with its own -name to "true". Note that this could also be (ab)used to control -the processing of the repo with any environment variable. The default -is an empty list, which means that the repo is always processed. - build_step (optional) @@ -443,6 +438,11 @@ class GoodRepo(object): '-DCMAKE_INSTALL_PREFIX=' + self.install_dir ] + # Allow users to pass in arbitrary cache variables + for cmake_var in self._args.cmake_var: + pieces = cmake_var.split('=', 1) + cmake_cmd.append('-D{}={}'.format(pieces[0], pieces[1])) + # For each repo this repo depends on, generate a CMake variable # definitions for "...INSTALL_DIR" that points to that dependent # repo's install dir. @@ -457,10 +457,8 @@ class GoodRepo(object): for option in self.cmake_options: cmake_cmd.append(escape(option.format(**self.__dict__))) - # Set build config for single-configuration generators - if platform.system() == 'Linux' or platform.system() == 'Darwin': - cmake_cmd.append('-DCMAKE_BUILD_TYPE={config}'.format( - config=CONFIG_MAP[self._args.config])) + # Set build config for single-configuration generators (this is a no-op on multi-config generators) + cmake_cmd.append(f'-D CMAKE_BUILD_TYPE={CONFIG_MAP[self._args.config]}') # Use the CMake -A option to select the platform architecture # without needing a Visual Studio generator. @@ -487,29 +485,14 @@ class GoodRepo(object): def CMakeBuild(self): """Build CMake command for the build phase and execute it""" - cmake_cmd = ['cmake', '--build', self.build_dir, '--target', 'install'] + cmake_cmd = ['cmake', '--build', self.build_dir, '--target', 'install', '--config', CONFIG_MAP[self._args.config]] if self._args.do_clean: cmake_cmd.append('--clean-first') - if platform.system() == 'Windows': - cmake_cmd.append('--config') - cmake_cmd.append(CONFIG_MAP[self._args.config]) - - # Speed up the build. - if platform.system() == 'Linux' or platform.system() == 'Darwin': - cmake_cmd.append('--') - num_make_jobs = multiprocessing.cpu_count() - env_make_jobs = os.environ.get('MAKE_JOBS', None) - if env_make_jobs is not None: - try: - num_make_jobs = min(num_make_jobs, int(env_make_jobs)) - except ValueError: - print('warning: environment variable MAKE_JOBS has non-numeric value "{}". ' - 'Using {} (CPU count) instead.'.format(env_make_jobs, num_make_jobs)) - cmake_cmd.append('-j{}'.format(num_make_jobs)) - if platform.system() == 'Windows' and self._args.generator != "Ninja": - cmake_cmd.append('--') - cmake_cmd.append('/maxcpucount') + # Ninja is parallel by default + if self._args.generator != "Ninja": + cmake_cmd.append('--parallel') + cmake_cmd.append(format(multiprocessing.cpu_count())) if VERBOSE: print("CMake command: " + " ".join(cmake_cmd)) @@ -662,7 +645,7 @@ def main(): dest='arch', choices=['32', '64', 'x86', 'x64', 'win32', 'win64'], type=str.lower, - help="Set build files architecture (Windows)", + help="Set build files architecture (Visual Studio Generator Only)", default='64') parser.add_argument( '--config', @@ -682,6 +665,13 @@ def main(): type=lambda a: set(a.lower().split(',')), help="Comma-separated list of 'optional' resources that may be skipped. Only 'tests' is currently supported as 'optional'", default=set()) + parser.add_argument( + '--cmake_var', + dest='cmake_var', + action='append', + metavar='VAR[=VALUE]', + help="Add CMake command line option -D'VAR'='VALUE' to the CMake generation command line; may be used multiple times", + default=[]) args = parser.parse_args() save_cwd = os.getcwd() @@ -759,4 +749,3 @@ def main(): if __name__ == '__main__': main() - |
