Skip to content

Commit db4060f

Browse files
committed
Record and display custom build dependencies (regression fix)
Add record_build_dependency() macro to record/version/cache dependency metadata (FOUND/NOTFOUND, VERSION, NOT_FOUND_EXPLANATION, REQUIRED) for packages discovered outside checked_find_package(), and append them to global lists for reporting. Update print_package_notfound_report() to include these custom-found dependencies in the summary, sort and deduplicate the lists, and only append NOT_FOUND_EXPLANATION when it's defined and non-empty to avoid spurious text. Also adjust list variable usage to operate on the assembled _cfp_* lists for consistent output formatting. Signed-off-by: Vlad (Kuzmin) Erium <libalias@gmail.com>
1 parent 5874180 commit db4060f

File tree

1 file changed

+59
-5
lines changed

1 file changed

+59
-5
lines changed

src/cmake/dependency_utils.cmake

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,44 @@ endfunction ()
8282

8383

8484

85+
# Helper: record the final status of a dependency that is discovered outside
86+
# checked_find_package(), so it still shows up in the dependency summary.
87+
macro (record_build_dependency pkgname)
88+
cmake_parse_arguments(_pkg
89+
"FOUND;NOTFOUND;REQUIRED"
90+
"VERSION;NOT_FOUND_EXPLANATION"
91+
""
92+
${ARGN})
93+
if ((_pkg_FOUND AND _pkg_NOTFOUND)
94+
OR (NOT _pkg_FOUND AND NOT _pkg_NOTFOUND))
95+
message (FATAL_ERROR
96+
"record_build_dependency(${pkgname}) requires exactly one of FOUND or NOTFOUND")
97+
endif ()
98+
set (_pkg_version "")
99+
set (_pkg_not_found_explanation "")
100+
if (DEFINED _pkg_VERSION)
101+
set (_pkg_version "${_pkg_VERSION}")
102+
endif ()
103+
if (DEFINED _pkg_NOT_FOUND_EXPLANATION)
104+
set (_pkg_not_found_explanation "${_pkg_NOT_FOUND_EXPLANATION}")
105+
endif ()
106+
set (${pkgname}_VERSION "${_pkg_version}")
107+
set (${pkgname}_VERSION "${_pkg_version}" CACHE INTERNAL
108+
"Recorded dependency version for ${pkgname}" FORCE)
109+
set (${pkgname}_NOT_FOUND_EXPLANATION "${_pkg_not_found_explanation}")
110+
set (${pkgname}_NOT_FOUND_EXPLANATION "${_pkg_not_found_explanation}"
111+
CACHE INTERNAL "Recorded dependency explanation for ${pkgname}" FORCE)
112+
set (${pkgname}_REQUIRED ${_pkg_REQUIRED})
113+
set (${pkgname}_REQUIRED ${_pkg_REQUIRED} CACHE INTERNAL
114+
"Recorded dependency required-ness for ${pkgname}" FORCE)
115+
if (_pkg_FOUND)
116+
set_property (GLOBAL APPEND PROPERTY OIIO_CFP_CUSTOM_BUILD_DEPS_FOUND ${pkgname})
117+
else ()
118+
set_property (GLOBAL APPEND PROPERTY OIIO_CFP_CUSTOM_BUILD_DEPS_NOTFOUND ${pkgname})
119+
endif ()
120+
endmacro ()
121+
122+
85123
# Utility: if `condition` is true, append `addition` to variable `var`
86124
macro (string_append_if var condition addition)
87125
# message (STATUS "string_append_if ${var} ${condition}='${${condition}}' '${addition}'")
@@ -125,14 +163,27 @@ function (print_package_notfound_report)
125163
message (STATUS " ${_msg}")
126164
endforeach ()
127165
endif ()
166+
if (_cfp_custom_build_deps_found)
167+
message (STATUS "${ColorBoldWhite}The following additional dependencies were found:${ColorReset}")
168+
list (SORT _cfp_custom_build_deps_found CASE INSENSITIVE)
169+
list (REMOVE_DUPLICATES _cfp_custom_build_deps_found)
170+
foreach (_pkg IN LISTS _cfp_custom_build_deps_found)
171+
set (_msg "${_pkg} ${${_pkg}_VERSION} ")
172+
string_append_if (_msg ${_pkg}_REQUIRED " (REQUIRED)")
173+
message (STATUS " ${_msg}")
174+
endforeach ()
175+
endif ()
128176
if (CFP_ALL_BUILD_DEPS_BADVERSION)
129177
message (STATUS "${ColorBoldWhite}The following dependencies were found but were too old:${ColorReset}")
130178
list (SORT CFP_ALL_BUILD_DEPS_BADVERSION CASE INSENSITIVE)
131179
list (REMOVE_DUPLICATES CFP_ALL_BUILD_DEPS_BADVERSION)
132180
foreach (_pkg IN LISTS CFP_ALL_BUILD_DEPS_BADVERSION)
133181
set (_msg "${_pkg}")
134182
string_append_if (_msg ${_pkg}_REQUIRED " (REQUIRED)")
135-
string_append_if (_msg ${_pkg}_NOT_FOUND_EXPLANATION " ${_pkg}_NOT_FOUND_EXPLANATION")
183+
if (DEFINED ${_pkg}_NOT_FOUND_EXPLANATION
184+
AND NOT "${${_pkg}_NOT_FOUND_EXPLANATION}" STREQUAL "")
185+
string (APPEND _msg " ${${_pkg}_NOT_FOUND_EXPLANATION}")
186+
endif ()
136187
if (_pkg IN_LIST CFP_LOCALLY_BUILT_DEPS)
137188
string (APPEND _msg " ${ColorMagenta}(${${_pkg}_VERSION} BUILT LOCALLY)${ColorReset} in ${${_pkg}_build_elapsed_time}s)${ColorReset}")
138189
endif ()
@@ -143,12 +194,15 @@ function (print_package_notfound_report)
143194
${CFP_ALL_BUILD_DEPS_NOTFOUND} ${_cfp_custom_build_deps_notfound})
144195
if (_cfp_all_build_deps_notfound)
145196
message (STATUS "${ColorBoldWhite}The following dependencies were not found:${ColorReset}")
146-
list (SORT CFP_ALL_BUILD_DEPS_NOTFOUND CASE INSENSITIVE)
147-
list (REMOVE_DUPLICATES CFP_ALL_BUILD_DEPS_NOTFOUND)
148-
foreach (_pkg IN LISTS CFP_ALL_BUILD_DEPS_NOTFOUND)
197+
list (SORT _cfp_all_build_deps_notfound CASE INSENSITIVE)
198+
list (REMOVE_DUPLICATES _cfp_all_build_deps_notfound)
199+
foreach (_pkg IN LISTS _cfp_all_build_deps_notfound)
149200
set (_msg "${_pkg} ${_${_pkg}_version_range}")
150201
string_append_if (_msg ${_pkg}_REQUIRED " (REQUIRED)")
151-
string_append_if (_msg ${_pkg}_NOT_FOUND_EXPLANATION " ${_pkg}_NOT_FOUND_EXPLANATION")
202+
if (DEFINED ${_pkg}_NOT_FOUND_EXPLANATION
203+
AND NOT "${${_pkg}_NOT_FOUND_EXPLANATION}" STREQUAL "")
204+
string (APPEND _msg " ${${_pkg}_NOT_FOUND_EXPLANATION}")
205+
endif ()
152206
if (_pkg IN_LIST CFP_LOCALLY_BUILT_DEPS)
153207
string (APPEND _msg " ${ColorMagenta}(${${_pkg}_VERSION} BUILT LOCALLY in ${${_pkg}_build_elapsed_time}s)${ColorReset}")
154208
endif ()

0 commit comments

Comments
 (0)