Skip to content

Commit b070ce1

Browse files
committed
Merge bitcoin/bitcoin#31360: depends: Avoid using helper variables in toolchain file
7343a18 depends: Avoid using helper variables in toolchain file (Hennadii Stepanov) Pull request description: Using helper variables has two issues: 1. They contaminate the global namespace of the main build script. 2. They can be used as `set(var)`, effectively [exposing](https://cmake.org/cmake/help/latest/command/set.html) a cache variable `var`, which makes the toolchain file susceptible to the build environment. The [`depends/Makefile`](https://github.com/bitcoin/bitcoin/blob/master/depends/Makefile) can generate values with "not-set" semantics as empty strings or strings containing only spaces. For example:https://github.com/bitcoin/bitcoin/blob/2638fdb4f934be96b7c798dbac38ea5ab8a6374a/depends/Makefile#L157 Therefore, [`MATCHES`](https://cmake.org/cmake/help/latest/command/if.html#matches) must be used rather than [`STREQUAL`](https://cmake.org/cmake/help/latest/command/if.html#strequal). ACKs for top commit: purpleKarrot: ACK 7343a18 Tree-SHA512: f2235321ac13daee8e82fa1ae9d02b95097a696265ad3a31fbda9cbc3c387c1dc7d01951154f99828468e50b73ed2889a6fa2720007f519dd11fe25ee5303d23
2 parents 5b87521 + 7343a18 commit b070ce1

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

depends/toolchain.cmake.in

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,37 +115,35 @@ endif()
115115

116116

117117
# Set configuration options for the main build system.
118-
set(qt_packages @qt_packages@)
119-
if("${qt_packages}" STREQUAL "")
118+
# The depends/Makefile can generate values with "not-set"
119+
# semantics as empty strings or strings containing only spaces.
120+
# Therefore, MATCHES must be used rather than STREQUAL.
121+
if("@qt_packages@" MATCHES "^[ ]*$")
120122
set(BUILD_GUI OFF CACHE BOOL "")
121123
else()
122124
set(BUILD_GUI ON CACHE BOOL "")
123125
set(Qt6_ROOT "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "")
124126
endif()
125127

126-
set(qrencode_packages @qrencode_packages@)
127-
if("${qrencode_packages}" STREQUAL "")
128+
if("@qrencode_packages@" MATCHES "^[ ]*$")
128129
set(WITH_QRENCODE OFF CACHE BOOL "")
129130
else()
130131
set(WITH_QRENCODE ON CACHE BOOL "")
131132
endif()
132133

133-
set(zmq_packages @zmq_packages@)
134-
if("${zmq_packages}" STREQUAL "")
134+
if("@zmq_packages@" MATCHES "^[ ]*$")
135135
set(WITH_ZMQ OFF CACHE BOOL "")
136136
else()
137137
set(WITH_ZMQ ON CACHE BOOL "")
138138
endif()
139139

140-
set(wallet_packages @wallet_packages@)
141-
if("${wallet_packages}" STREQUAL "")
140+
if("@wallet_packages@" MATCHES "^[ ]*$")
142141
set(ENABLE_WALLET OFF CACHE BOOL "")
143142
else()
144143
set(ENABLE_WALLET ON CACHE BOOL "")
145144
endif()
146145

147-
set(usdt_packages @usdt_packages@)
148-
if("${usdt_packages}" STREQUAL "")
146+
if("@usdt_packages@" MATCHES "^[ ]*$")
149147
set(WITH_USDT OFF CACHE BOOL "")
150148
else()
151149
set(WITH_USDT ON CACHE BOOL "")

0 commit comments

Comments
 (0)