blob: 4212512034bf404f291ebc2976aacded4201a049 [file] [log] [blame]
Patrick Williamsb58112e2024-03-07 11:16:36 -06001From 792a46ef27ef879a21c9f01a198eae213ea535e6 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>
12---
13 CMakeLists.txt | 13 ++++++++++---
14 utils/update_build_version.py | 22 +++++++++++++++-------
15 2 files changed, 25 insertions(+), 10 deletions(-)
16
17diff --git a/CMakeLists.txt b/CMakeLists.txt
Patrick Williamsb58112e2024-03-07 11:16:36 -060018index 7bc8f5d..13fc535 100644
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060019--- a/CMakeLists.txt
20+++ b/CMakeLists.txt
Patrick Williamsb58112e2024-03-07 11:16:36 -060021@@ -62,6 +62,7 @@ else()
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060022 endif()
23
24 option(SHADERC_ENABLE_WERROR_COMPILE "Enable passing -Werror to compiler, if available" ON)
25+option(BUILD_EXTERNAL "Build external dependencies in /third_party" ON)
26
Patrick Williams520786c2023-06-25 16:20:36 -050027 set (CMAKE_CXX_STANDARD 17)
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060028
Patrick Williamsb58112e2024-03-07 11:16:36 -060029@@ -123,8 +124,14 @@ endif(MSVC)
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060030
31
32 # Configure subdirectories.
33-# We depend on these for later projects, so they should come first.
34-add_subdirectory(third_party)
35+if(BUILD_EXTERNAL)
36+ # We depend on these for later projects, so they should come first.
37+ add_subdirectory(third_party)
38+else()
39+ find_package(PkgConfig REQUIRED)
40+ pkg_check_modules (PKG_CHECK REQUIRED SPIRV-Tools)
41+ pkg_check_modules (PKG_CHECK REQUIRED glslang)
42+endif()
43
44 add_subdirectory(libshaderc_util)
45 add_subdirectory(libshaderc)
Patrick Williamsb58112e2024-03-07 11:16:36 -060046@@ -136,7 +143,7 @@ endif()
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060047 add_custom_target(build-version
48 ${PYTHON_EXECUTABLE}
49 ${CMAKE_CURRENT_SOURCE_DIR}/utils/update_build_version.py
50- ${shaderc_SOURCE_DIR} ${spirv-tools_SOURCE_DIR} ${glslang_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/build-version.inc
51+ ${CMAKE_CURRENT_BINARY_DIR}/build-version.inc ${shaderc_SOURCE_DIR} ${spirv-tools_SOURCE_DIR} ${glslang_SOURCE_DIR}
52 COMMENT "Update build-version.inc in the Shaderc build directory (if necessary).")
53
54 function(define_pkg_config_file NAME LIBS)
55diff --git a/utils/update_build_version.py b/utils/update_build_version.py
Patrick Williamsb58112e2024-03-07 11:16:36 -060056index 11ee53e..d39e59d 100755
Andrew Geissler9b4d8b02021-02-19 12:26:16 -060057--- a/utils/update_build_version.py
58+++ b/utils/update_build_version.py
59@@ -30,6 +30,7 @@ import re
60 import subprocess
61 import sys
62 import time
63+import itertools
64
65 def mkdir_p(directory):
66 """Make the directory, and all its ancestors as required. Any of the
67@@ -121,25 +122,32 @@ def get_version_string(project, directory):
68 directory, which consists of software version string and git description
69 string."""
70 detailed_version_string_lst = [project]
71- if project != 'glslang':
72- detailed_version_string_lst.append(deduce_software_version(directory))
73- detailed_version_string_lst.append(describe(directory).replace('"', '\\"'))
74+ if isinstance(directory, str) and os.path.isdir(directory):
75+ if project != 'glslang':
76+ detailed_version_string_lst.append(deduce_software_version(directory))
77+ detailed_version_string_lst.append(describe(directory).replace('"', '\\"'))
78+ else:
79+ if project == 'spirv-tools':
80+ project = 'SPIRV-Tools'
81+ pkgconfig = ['pkg-config', '--modversion', project]
82+ version = subprocess.run(pkgconfig, capture_output=True, text=True).stdout.rstrip()
83+ detailed_version_string_lst.append(version)
84 return ' '.join(detailed_version_string_lst)
85
86
87 def main():
88- if len(sys.argv) != 5:
89- print(('usage: {} <shaderc-dir> <spirv-tools-dir> <glslang-dir> <output-file>'.format(
90+ if len(sys.argv) < 3:
91+ print(('usage: {} <output-file> <shaderc-dir> [spirv-tools-dir] [glslang-dir]'.format(
92 sys.argv[0])))
93 sys.exit(1)
94
95 projects = ['shaderc', 'spirv-tools', 'glslang']
96 new_content = ''.join([
97 '"{}\\n"\n'.format(get_version_string(p, d))
98- for (p, d) in zip(projects, sys.argv[1:])
99+ for (p, d) in itertools.zip_longest(projects, sys.argv[2:])
100 ])
101
102- output_file = sys.argv[4]
103+ output_file = sys.argv[1]
104 mkdir_p(os.path.dirname(output_file))
105
106 if os.path.isfile(output_file):