cmake: fix make-clean as add_custom_command() deletes output files.
there is no way to mark output file as "precious", then cmake's suggestion is to use add_custom_target() instead. However that will always execute, so our generator script needs to be smarter and only touch stuff when actually needed.
This commit is contained in:
parent
525d1e0629
commit
4792069634
|
@ -105,8 +105,7 @@ set(SOURCES
|
|||
software/ector_software_surface.c
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${EFL_LIB_SOURCE_DIR}/gl/shader/ector_gl_shaders.x
|
||||
add_custom_target(ector-update-shaders
|
||||
COMMAND /bin/sh ${EFL_LIB_SOURCE_DIR}/gl/shader/gen_shaders.sh
|
||||
DEPENDS
|
||||
${EFL_LIB_SOURCE_DIR}/gl/shader/gen_shaders.sh
|
||||
|
@ -114,5 +113,7 @@ add_custom_command(
|
|||
${EFL_LIB_SOURCE_DIR}/gl/shader/vertex.glsl
|
||||
${EFL_LIB_SOURCE_DIR}/gl/shader/include.glsl
|
||||
WORKING_DIRECTORY "${EFL_LIB_SOURCE_DIR}"
|
||||
COMMENT "SHADERS ${EFL_LIB_SOURCE_DIR}/gl/shader/ector_gl_shaders.x"
|
||||
COMMENT "SHADERS src/lib/ector/gl/shader/ector_gl_shaders.x (if needed)"
|
||||
)
|
||||
|
||||
set(DEPENDENCIES ector-update-shaders)
|
||||
|
|
|
@ -10,30 +10,43 @@ OUTPUT="$DIR/ector_gl_shaders.x"
|
|||
if ! git rev-parse 2>> /dev/null >> /dev/null ; then exit 0 ; fi
|
||||
if git diff --quiet --exit-code -- "$DIR"
|
||||
then
|
||||
touch "$OUTPUT"
|
||||
for f in gen_shaders.sh fragment.glsl vertex.glsl include.glsl; do
|
||||
if [ "$DIR/$f" -nt "$OUTPUT" ]; then
|
||||
touch "$OUTPUT"
|
||||
break
|
||||
fi
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exec 1<&-
|
||||
exec 1>"$OUTPUT"
|
||||
|
||||
# Write header
|
||||
printf "/* DO NOT MODIFY THIS FILE AS IT IS AUTO-GENERATED */\n"
|
||||
printf "/* IF IT IS CHANGED PLEASE COMMIT THE CHANGES */\n\n"
|
||||
rm -f "$OUTPUT.tmp"
|
||||
cat <<EOF >> $OUTPUT.tmp
|
||||
/* DO NOT MODIFY THIS FILE AS IT IS AUTO-GENERATED */
|
||||
/* IF IT IS CHANGED PLEASE COMMIT THE CHANGES */
|
||||
|
||||
EOF
|
||||
|
||||
for SHD in fragment vertex ; do
|
||||
m4 "$DIR/include.glsl" "$DIR/$SHD.glsl" > "$SHD.tmp"
|
||||
|
||||
OIFS="$IFS"
|
||||
IFS=`printf '\n+'`
|
||||
IFS=${IFS%+}
|
||||
printf "static const char "$SHD"_glsl[] ="
|
||||
IFS=$'\n'
|
||||
echo -n "static const char ${SHD}_glsl[] =" >> "$OUTPUT.tmp"
|
||||
for LINE in `cat "$SHD.tmp"` ; do
|
||||
printf "\n \"$LINE\\\n\""
|
||||
printf "\n \"$LINE\\\n\"" >> "$OUTPUT.tmp"
|
||||
done
|
||||
printf ";\n\n"
|
||||
printf ";\n\n" >> "$OUTPUT.tmp"
|
||||
IFS="$OIFS"
|
||||
|
||||
rm "$SHD.tmp"
|
||||
done
|
||||
|
||||
if ! cmp "$OUTPUT" "$OUTPUT.tmp" >/dev/null 2>/dev/null; then
|
||||
echo "$OUTPUT updated, please 'git commit' it."
|
||||
rm -f "$OUTPUT"
|
||||
mv "$OUTPUT.tmp" "$OUTPUT"
|
||||
else
|
||||
rm -f "$OUTPUT.tmp"
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue