Skip to content

Commit 9c3ca8c

Browse files
build: auto-resolve staged outputs from TARGET_LIBS imported locations
Replace USE_FLAG_FILE with proper output tracking for TARGET_LIBS: the staging macro now resolves IMPORTED_LOCATION at configure time to derive output filenames, so Ninja detects deleted staged files and re-runs the staging command automatically. Falls back to flag file if location cannot be resolved. Also convert dav1d, ffmpeg, and ocio from LIB_DIR copy-directory staging to TARGET_LIBS for the same incremental-build benefit.
1 parent 24b160e commit 9c3ca8c

File tree

9 files changed

+92
-28
lines changed

9 files changed

+92
-28
lines changed

cmake/dependencies/boost.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,5 @@ ELSE()
186186
ENDFOREACH()
187187

188188
# Found path: actual filenames may differ (e.g. -mt suffix), use TARGET_LIBS to resolve at build time
189-
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} TARGET_LIBS ${_boost_deps_list_targets} USE_FLAG_FILE)
189+
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} TARGET_LIBS ${_boost_deps_list_targets})
190190
ENDIF()

cmake/dependencies/dav1d.cmake

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ ELSE()
9494
ENDIF()
9595

9696
# --- Staging ---
97-
IF(RV_TARGET_WINDOWS)
98-
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} BIN_DIR ${_bin_dir} USE_FLAG_FILE)
99-
ELSE()
100-
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} USE_FLAG_FILE)
101-
ENDIF()
97+
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} TARGET_LIBS dav1d::dav1d)
10298

10399
# --- FFmpeg customization adding dav1d codec support ---
104100
SET_PROPERTY(

cmake/dependencies/ffmpeg.cmake

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,15 @@ ADD_CUSTOM_TARGET(
410410
COMMAND ${CMAKE_COMMAND} -E remove_directory ${RV_DEPS_BASE_DIR}/cmake/dependencies/${_target}-prefix
411411
)
412412

413-
# Note: On Windows, FFmpeg stores both import libs and DLLs in the install bin directory, so we copy _lib_dir (which is install/bin on Windows) to both stage
414-
# dirs.
415-
IF(RV_TARGET_WINDOWS)
416-
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} EXTRA_LIB_DIRS ${RV_STAGE_BIN_DIR} USE_FLAG_FILE)
417-
ELSE()
418-
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} USE_FLAG_FILE)
419-
ENDIF()
413+
SET(_ffmpeg_targets)
414+
FOREACH(
415+
_ffmpeg_lib
416+
${_ffmpeg_libs}
417+
)
418+
LIST(APPEND _ffmpeg_targets ffmpeg::${_ffmpeg_lib})
419+
ENDFOREACH()
420+
421+
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} TARGET_LIBS ${_ffmpeg_targets})
420422

421423
SET(RV_DEPS_FFMPEG_VERSION
422424
${_version}

cmake/dependencies/glew.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ ELSE()
4848
ENDIF()
4949

5050
# Found path: use TARGET_LIBS to resolve actual library path at build time
51-
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} TARGET_LIBS GLEW::GLEW USE_FLAG_FILE)
51+
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} TARGET_LIBS GLEW::GLEW)
5252
ENDIF()

cmake/dependencies/ocio.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,6 @@ IF(RV_TARGET_WINDOWS)
319319
ENDIF()
320320
ENDIF()
321321

322-
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} BIN_DIR ${_bin_dir} USE_FLAG_FILE)
323-
324322
RV_ADD_IMPORTED_LIBRARY(
325323
NAME
326324
OpenColorIO::OpenColorIO
@@ -336,3 +334,5 @@ RV_ADD_IMPORTED_LIBRARY(
336334
${_target}
337335
ADD_TO_DEPS_LIST
338336
)
337+
338+
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} TARGET_LIBS OpenColorIO::OpenColorIO)

cmake/dependencies/openexr.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,5 @@ ELSE()
169169
LIST(APPEND _openexr_stage_targets OpenEXR::OpenEXRCore)
170170
ENDIF()
171171

172-
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} TARGET_LIBS ${_openexr_stage_targets} USE_FLAG_FILE)
172+
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} TARGET_LIBS ${_openexr_stage_targets})
173173
ENDIF()

cmake/dependencies/openssl.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ ELSE()
182182
TARGET_LIBS
183183
OpenSSL::Crypto
184184
OpenSSL::SSL
185-
USE_FLAG_FILE
186185
)
187186
ENDIF()
188187

cmake/dependencies/zlib.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ ELSE()
163163
)
164164
ADD_DEPENDENCIES(dependencies ${_target}-stage-target)
165165
ELSE()
166-
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} TARGET_LIBS ZLIB::ZLIB USE_FLAG_FILE)
166+
RV_STAGE_DEPENDENCY_LIBS(TARGET ${_target} TARGET_LIBS ZLIB::ZLIB)
167167
ENDIF()
168168
ENDIF()
169169

cmake/macros/rv_stage_dependency_libs.cmake

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
# [STAGE_LIB_DIR <override>] # Override RV_STAGE_LIB_DIR (e.g., for OpenSSL/Linux)
2121
# [EXTRA_LIB_DIRS <dir1>...] # Additional lib dirs to copy to
2222
# [FILES <file1> [file2...]] # Individual files to copy_if_different to STAGE_LIB_DIR (alternative to LIB_DIR)
23-
# [TARGET_LIBS <t1> [t2...]] # Imported targets to stage via $<TARGET_FILE:...> generatos (requires USE_FLAG_FILE).
24-
# # Resolves actual library paths at build time — handles any naming convention.
23+
# [TARGET_LIBS <t1> [t2...]] # Imported targets to stage via $<TARGET_FILE:...> generators.
24+
# # At configure time, resolves IMPORTED_LOCATION to derive output filenames
25+
# # for proper incremental tracking (re-stages if files are deleted).
26+
# # Falls back to USE_FLAG_FILE if location cannot be resolved.
2527
# # On Windows: DLL→STAGE_BIN_DIR, import lib→STAGE_LIB_DIR.
2628
# [DEPENDS <dep1> [dep2...]] # Dependencies (default: ${TARGET})
2729
# [PRE_COMMANDS COMMAND <cmd1> [COMMAND <cmd2>...]] # Commands to run before copy; each must be prefixed with COMMAND keyword
@@ -71,13 +73,6 @@ FUNCTION(RV_STAGE_DEPENDENCY_LIBS)
7173
ENDIF()
7274
ENDIF()
7375

74-
# Validate TARGET_LIBS requires USE_FLAG_FILE (generators can't be used in OUTPUTS)
75-
IF(_ARG_TARGET_LIBS
76-
AND NOT _ARG_USE_FLAG_FILE
77-
)
78-
MESSAGE(FATAL_ERROR "RV_STAGE_DEPENDENCY_LIBS: TARGET_LIBS requires USE_FLAG_FILE (generator expressions cannot be used in OUTPUTS)")
79-
ENDIF()
80-
8176
# Default LIB_DIR to caller's _lib_dir if not explicitly passed
8277
IF(NOT _ARG_LIB_DIR
8378
AND NOT _ARG_FILES
@@ -111,6 +106,78 @@ FUNCTION(RV_STAGE_DEPENDENCY_LIBS)
111106
)
112107
ENDIF()
113108

109+
# When TARGET_LIBS is used without explicit USE_FLAG_FILE or OUTPUTS, resolve IMPORTED_LOCATION at configure time to derive output filenames for proper
110+
# incremental tracking. This way Ninja detects deleted staged files and re-runs the staging command automatically.
111+
IF(_ARG_TARGET_LIBS
112+
AND NOT _ARG_USE_FLAG_FILE
113+
AND NOT _ARG_OUTPUTS
114+
)
115+
SET(_rsdl_resolved_outputs)
116+
SET(_rsdl_failed
117+
FALSE
118+
)
119+
STRING(TOUPPER "${CMAKE_BUILD_TYPE}" _rsdl_config_upper)
120+
121+
FOREACH(
122+
_rsdl_tgt
123+
${_ARG_TARGET_LIBS}
124+
)
125+
SET(_rsdl_loc
126+
""
127+
)
128+
FOREACH(
129+
_rsdl_prop
130+
IMPORTED_LOCATION IMPORTED_LOCATION_${_rsdl_config_upper} IMPORTED_LOCATION_RELEASE IMPORTED_LOCATION_NOCONFIG
131+
)
132+
IF(NOT _rsdl_loc)
133+
GET_TARGET_PROPERTY(_rsdl_loc ${_rsdl_tgt} ${_rsdl_prop})
134+
ENDIF()
135+
ENDFOREACH()
136+
137+
IF(_rsdl_loc)
138+
GET_FILENAME_COMPONENT(_rsdl_fname "${_rsdl_loc}" NAME)
139+
IF(RV_TARGET_WINDOWS)
140+
LIST(APPEND _rsdl_resolved_outputs "${RV_STAGE_BIN_DIR}/${_rsdl_fname}")
141+
SET(_rsdl_implib
142+
""
143+
)
144+
FOREACH(
145+
_rsdl_prop
146+
IMPORTED_IMPLIB IMPORTED_IMPLIB_${_rsdl_config_upper} IMPORTED_IMPLIB_RELEASE IMPORTED_IMPLIB_NOCONFIG
147+
)
148+
IF(NOT _rsdl_implib)
149+
GET_TARGET_PROPERTY(_rsdl_implib ${_rsdl_tgt} ${_rsdl_prop})
150+
ENDIF()
151+
ENDFOREACH()
152+
IF(_rsdl_implib)
153+
GET_FILENAME_COMPONENT(_rsdl_impfname "${_rsdl_implib}" NAME)
154+
LIST(APPEND _rsdl_resolved_outputs "${_ARG_STAGE_LIB_DIR}/${_rsdl_impfname}")
155+
ENDIF()
156+
ELSE()
157+
LIST(APPEND _rsdl_resolved_outputs "${_ARG_STAGE_LIB_DIR}/${_rsdl_fname}")
158+
ENDIF()
159+
ELSE()
160+
SET(_rsdl_failed
161+
TRUE
162+
)
163+
MESSAGE(AUTHOR_WARNING "RV_STAGE_DEPENDENCY_LIBS: Cannot resolve IMPORTED_LOCATION for ${_rsdl_tgt}; falling back to flag file")
164+
BREAK()
165+
ENDIF()
166+
ENDFOREACH()
167+
168+
IF(NOT _rsdl_failed
169+
AND _rsdl_resolved_outputs
170+
)
171+
SET(_ARG_OUTPUTS
172+
${_rsdl_resolved_outputs}
173+
)
174+
ELSE()
175+
SET(_ARG_USE_FLAG_FILE
176+
TRUE
177+
)
178+
ENDIF()
179+
ENDIF()
180+
114181
# Build the command list
115182
SET(_commands)
116183

0 commit comments

Comments
 (0)