I wanna run a bash script using cmake. And I am partially successful. I am not understanding the workflow properly.
main.cxx
# include <iostream>
int main()
{
std::cout << "hello\n";
}
script.sh
#!/bin/bash
touch file;
CMakeLists.txt
cmake_minimum_required(VERSION 3.21.1)
project(testdir)
add_executable(mainbin "main.cxx")
add_custom_command(TARGET mainbin
POST_BUILD
COMMAND /bin/sh /path/to/testdir/script.sh
)
So, this is my directory tree.
testdir
|
|---CMakeLists.txt
|
|---main.cxx
|
|---script.sh
When I do "cmake . ; make ;", cmake runs the bash script and except the cmake build related files, the directory tree looks like this:
testdir
|
|---file
|
|---CMakeLists.txt
|
|---main.cxx
|
|---script.sh
So it worked. But now I would want to rename "file" to "renamed_file". So I would edit script.sh. New script.sh looks like this:
#!/bin/bash
mv file renamed_file;
Now when I do "cmake . ; make ;" again, it doesn't work. I mean file "file" doesn't change to "renamed_file". I wanna run script.sh everytime I call "cmake . ; make ;".
Maybe I am missing a very simple thing/basic understanding. What should I do to achieve that?