I want to create a bash helper script to diff a generated file against its source. The directory structure of the output matches the source, so I should be able to find the name of the source file if I had this data:
My plan to get this is:
How do I do that? Preferably without having to configure/generate(as that introduces a bit of delay). Should I instead grep a specific file in the build folder? Which one?
Once you have located the CMakeCache.txt
you can grep for the project source dir in it in the following way:
cat CMakeCache.txt | grep -E '.*_SOURCE_DIR:STATIC=.*' | grep -E -o '/.*'
This outputs the value of the _SOURCE_DIR variable.
You can grep for home directory in CMakeCache.txt:
grep ^CMAKE_HOME_DIRECTORY CMakeCache.txt | cut -d = -f2-
My cmake version:
$ cmake --version
cmake version 3.28.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With