0

I am USing cmake 3.14, and part of the script it's calling another python script and giving it the build path as an argument but the python doesn't receive this argument

set(arg ${CMAKE_BINARY_DIR})    
add_custom_command(TARGET res POST_BUILD
  COMMAND ${PYTHON_TEST}  ${CMAKE_BINARY_DIR}/../script.py ${arg}
  DEPENDS ${arg}
  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  COMMENT "Generating results"
             )

python log :

Traceback (most recent call last):
File "script.py", line 8, in <module>
BuildPath = sys.argv[1]
IndexError: list index out of range

of course the python script is running ok if called from CMD .. when i looked on the cmake documentation it says it's ignoring the arguments indeed but i didn't understand what's to be done to pass arguments?

enter image description here

8
  • 1
    What's stored in PYTHON_TEST? What does the message("COMMAND ${PYTHON_TEST} ${CMAKE_BINARY_DIR}/../script.py ${arg}") command print, if inserted directly befor the add_custom_command? What's the command cmake --build ... --verbose prints? Commented Aug 10, 2023 at 17:10
  • Note also, that TARGET flow of the add_custom_command doesn't support DEPENDS keyword. You won't find that keyword in the documentation for that command flow. Commented Aug 13, 2023 at 13:54
  • @fabian PYTHON_TEST is python.exe .... and this command prints (pathToPython/python.exe PathToScript/script.py arg) exactly as i want Commented Aug 21, 2023 at 22:34
  • @Tsyvarev actually it supports DEPENDS in this documentation Commented Aug 21, 2023 at 22:40
  • @mr.Arrow: No, it doesn't. You use "Build Events" subtype of the command. If you look into the command signature for that subtype, you won't find DEPENDS in it. Commented Aug 21, 2023 at 23:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.