Skip to content

Instantly share code, notes, and snippets.

@ken-matsui
Created May 26, 2022 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ken-matsui/6ddc2c3414520060b0d1084afd93f283 to your computer and use it in GitHub Desktop.
Save ken-matsui/6ddc2c3414520060b0d1084afd93f283 to your computer and use it in GitHub Desktop.
Generate files with detecting changed files in CMake
#!/bin/bash
set -eu
: $1 $2
INPUT_FILE_PATH=$1
OUTPUT_FILE_PATH=$2
printf "std::string(R\"(%s\n)\")" "$(cat "$INPUT_FILE_PATH")" > "$OUTPUT_FILE_PATH"
file(GLOB_RECURSE ExpectationInputFiles CONFIGURE_DEPENDS "*.stdout" "*.stderr")
foreach(InputFilePath ${ExpectationInputFiles})
get_filename_component(FileBaseDir ${InputFilePath} DIRECTORY)
get_filename_component(FileName ${InputFilePath} NAME)
set(OutputFilePath "${FileBaseDir}/gen/${FileName}.gen")
add_custom_command(
OUTPUT ${OutputFilePath}
COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/generate-expectation-files.sh ${InputFilePath} ${OutputFilePath}
DEPENDS ${InputFilePath}
)
list(APPEND ExpectationOutputFiles ${OutputFilePath})
endforeach()
add_custom_target(GenerateExpectationFiles ALL DEPENDS ${ExpectationOutputFiles})
add_dependencies(poac GenerateExpectationFiles)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment