I have a python script, which generates some files for me, and in my script, I have an argument --outputdir
to specify the location of output files. I want to run this script to generate these files and install them later. I used
add_custom_command(
COMMAND python3.6 ${CMAKE_CURRENT_SOURCE_DIR}/generateFiles.py
ARGS --outputdir ${CMAKE_CURRENT_BINARY_DIR})
So output files are generated under ${CMAKE_CURRENT_BINARY_DIR}
, and I can install them later.
but above code did not work, because I have to use a TARGET
or OUTPUT
from the error message. So if I use a dummy one:
add_custom_target(dummy ALL)
add_custom_command(
TARGET dummy
COMMAND python3.6 ${CMAKE_CURRENT_SOURCE_DIR}/generateFiles.py
ARGS --outputdir ${CMAKE_CURRENT_BINARY_DIR})
This just worked and I can see files are generated under ${CMAKE_CURRENT_BINARY_DIR}
. I believe if I use something like:
add_custom_target(dummy
COMMAND python3.6 ${CMAKE_CURRENT_SOURCE_DIR}/generateFiles.py
ARGS --outputdir ${CMAKE_CURRENT_BINARY_DIR})
this should also work. My question is why do I need a dummy
target anyway? Actually just with COMMAND
I can run my script and with args I can specify where the output files are generated, then with some install command I can install files around. So Am I correct to use a dummy
target in this case and do I have to use a it? Note generateFiles.py
are not changed during the build process and will generate the same files every time. Thanks, i am new to CMake.