I've to use 1 command :
python <somepythonscript.py> <input_file_path> > <output_file_path>
somepythonscript.py => It's a python script which takes a file as an input, processes it & generates an output file.
Now, I've to add this command into my CMakeLists.txt so that whenever I make, this script will be invoked via command & I can get the generated output file also.
Asked
Active
Viewed 445 times
0

Tsyvarev
- 60,011
- 17
- 110
- 153

Nitesh Singh
- 37
- 8
1 Answers
1
You can use the FindPython
module in combination with add_custom_command
find_package(Python REQUIRED COMPONENTS Interpreter)
add_custom_command(
OUTPUT <output_path>
COMMAND ${Python_EXECUTABLE} <somepythonscript.py> <input_file_path> <output_file_path>
DEPENDS <somepythonscript.py> <input_file_path>
)
For the file to be generated though, you need to add it as dependency somewhere, e.g. by listing it as source of a target.
If you are sure the file doesn't need to be regenerated, you can use execute_process
instead of add_custom_command

fabian
- 80,457
- 12
- 86
- 114
-
Output file needs to be regenerated – Nitesh Singh Mar 17 '22 at 20:12