blob: 35855bd8326abfb2dd14cc4eabeb5a6db6352834 [file] [log] [blame]
Patrick Williams520786c2023-06-25 16:20:36 -05001From d3fbd6b9427f29606540528d17fe02930cd78d0c Mon Sep 17 00:00:00 2001
Andrew Geissler9b4d8b02021-02-19 12:26:16 -06002From: Jose Quaresma <quaresma.jose@gmail.com>
3Date: Sat, 13 Feb 2021 00:45:56 +0000
Patrick Williams520786c2023-06-25 16:20:36 -05004Subject: [PATCH] cmake: disable building external dependencies
Andrew Geissler9b4d8b02021-02-19 12:26:16 -06005
6- add cmake option to disable the build of the third_party dependencies
7- change the update_build_version.py to use pkg-config when third_party dependencies not found
8
9Upstream-Status: Inappropriate [OE-core specific]
10
11Signed-off-by: Jose Quaresma <quaresma.jose@gmail.com>
Patrick Williams520786c2023-06-25 16:20:36 -050012
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060013---
14 CMakeLists.txt | 13 ++++++++++---
15 utils/update_build_version.py | 22 +++++++++++++++-------
16 2 files changed, 25 insertions(+), 10 deletions(-)
17
18diff --git a/CMakeLists.txt b/CMakeLists.txt
Patrick Williams520786c2023-06-25 16:20:36 -050019index 633c244..75b01da 100644
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060020--- a/CMakeLists.txt
21+++ b/CMakeLists.txt
Patrick Williams520786c2023-06-25 16:20:36 -050022@@ -67,6 +67,7 @@ else()
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060023 endif()
24
25 option(SHADERC_ENABLE_WERROR_COMPILE "Enable passing -Werror to compiler, if available" ON)
26+option(BUILD_EXTERNAL "Build external dependencies in /third_party" ON)
27
Patrick Williams520786c2023-06-25 16:20:36 -050028 set (CMAKE_CXX_STANDARD 17)
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060029
Patrick Williams520786c2023-06-25 16:20:36 -050030@@ -129,8 +130,14 @@ endif(MSVC)
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060031
32
33 # Configure subdirectories.
34-# We depend on these for later projects, so they should come first.
35-add_subdirectory(third_party)
36+if(BUILD_EXTERNAL)
37+ # We depend on these for later projects, so they should come first.
38+ add_subdirectory(third_party)
39+else()
40+ find_package(PkgConfig REQUIRED)
41+ pkg_check_modules (PKG_CHECK REQUIRED SPIRV-Tools)
42+ pkg_check_modules (PKG_CHECK REQUIRED glslang)
43+endif()
44
45 add_subdirectory(libshaderc_util)
46 add_subdirectory(libshaderc)
Patrick Williams520786c2023-06-25 16:20:36 -050047@@ -142,7 +149,7 @@ endif()
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060048 add_custom_target(build-version
49 ${PYTHON_EXECUTABLE}
50 ${CMAKE_CURRENT_SOURCE_DIR}/utils/update_build_version.py
51- ${shaderc_SOURCE_DIR} ${spirv-tools_SOURCE_DIR} ${glslang_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/build-version.inc
52+ ${CMAKE_CURRENT_BINARY_DIR}/build-version.inc ${shaderc_SOURCE_DIR} ${spirv-tools_SOURCE_DIR} ${glslang_SOURCE_DIR}
53 COMMENT "Update build-version.inc in the Shaderc build directory (if necessary).")
54
55 function(define_pkg_config_file NAME LIBS)
56diff --git a/utils/update_build_version.py b/utils/update_build_version.py
57index 5785390..f72b762 100755
58--- a/utils/update_build_version.py
59+++ b/utils/update_build_version.py
60@@ -30,6 +30,7 @@ import re
61 import subprocess
62 import sys
63 import time
64+import itertools
65
66 def mkdir_p(directory):
67 """Make the directory, and all its ancestors as required. Any of the
68@@ -121,25 +122,32 @@ def get_version_string(project, directory):
69 directory, which consists of software version string and git description
70 string."""
71 detailed_version_string_lst = [project]
72- if project != 'glslang':
73- detailed_version_string_lst.append(deduce_software_version(directory))
74- detailed_version_string_lst.append(describe(directory).replace('"', '\\"'))
75+ if isinstance(directory, str) and os.path.isdir(directory):
76+ if project != 'glslang':
77+ detailed_version_string_lst.append(deduce_software_version(directory))
78+ detailed_version_string_lst.append(describe(directory).replace('"', '\\"'))
79+ else:
80+ if project == 'spirv-tools':
81+ project = 'SPIRV-Tools'
82+ pkgconfig = ['pkg-config', '--modversion', project]
83+ version = subprocess.run(pkgconfig, capture_output=True, text=True).stdout.rstrip()
84+ detailed_version_string_lst.append(version)
85 return ' '.join(detailed_version_string_lst)
86
87
88 def main():
89- if len(sys.argv) != 5:
90- print(('usage: {} <shaderc-dir> <spirv-tools-dir> <glslang-dir> <output-file>'.format(
91+ if len(sys.argv) < 3:
92+ print(('usage: {} <output-file> <shaderc-dir> [spirv-tools-dir] [glslang-dir]'.format(
93 sys.argv[0])))
94 sys.exit(1)
95
96 projects = ['shaderc', 'spirv-tools', 'glslang']
97 new_content = ''.join([
98 '"{}\\n"\n'.format(get_version_string(p, d))
99- for (p, d) in zip(projects, sys.argv[1:])
100+ for (p, d) in itertools.zip_longest(projects, sys.argv[2:])
101 ])
102
103- output_file = sys.argv[4]
104+ output_file = sys.argv[1]
105 mkdir_p(os.path.dirname(output_file))
106
107 if os.path.isfile(output_file):