Skip to content

Commit 220cff8

Browse files
committed
Harden IPO wrapper: propagate exit status and parse -o flag
1 parent e6e992d commit 220cff8

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,22 @@ function(MFC_SETUP_TARGET)
501501
# exist. We use a wrapper script as RULE_LAUNCH_COMPILE that runs
502502
# the compiler and then touches the expected .o output file.
503503
set(_ipo_wrapper "${CMAKE_BINARY_DIR}/${ARGS_TARGET}_extract_wrapper.sh")
504-
file(WRITE "${_ipo_wrapper}" "#!/bin/sh\n\"$@\"\nfor arg; do :; done\ntouch \"$arg\"\n")
504+
file(WRITE "${_ipo_wrapper}" [=[#!/bin/sh
505+
# Find the -o argument (the object file CMake expects)
506+
out=
507+
prev=
508+
for arg do
509+
if [ "$prev" = "-o" ]; then out="$arg"; break; fi
510+
prev="$arg"
511+
done
512+
# Run the compiler; propagate its exit status on failure
513+
"$@"
514+
status=$?
515+
[ "$status" -eq 0 ] || exit "$status"
516+
# Touch the .o so CMake's dependency tracking sees it
517+
[ -n "$out" ] && touch "$out"
518+
exit 0
519+
]=])
505520
file(CHMOD "${_ipo_wrapper}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
506521
add_library(${ARGS_TARGET}_lib OBJECT ${ARGS_SOURCES})
507522
set_target_properties(${ARGS_TARGET}_lib PROPERTIES

0 commit comments

Comments
 (0)