0

I have a script, performCrc32.py, which I want to call after my build has completed. I've modified my CMakeLists.txt file in order to have the build fork to performCrc32.py, however, my script is not executing. Here are my Cmake commands:

    add_custom_command(
       DEPENDS performCrc32.py
       OUTPUT  performCrc32.out
       COMMAND ${PYTHON_EXECUTABLE}
       ARGS performCrc32.py
)

add_custom_target(
    performCrc32 ALL
)

The compiler is not complaining, however, my Python (2.7.10) script is not executing. I'm not quite sure what is missing from my calls to add_custom_command() and add_custom_target(). Perhaps there's a more straightforward approach? What am I missing?

I have even tried this, but to no avail:

    add_custom_command(
    DEPENDS performCrc32.py
    OUTPUT  performCrc32.out
    COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/performCrc32.py
    POST_BUILD
    COMMENT "Running CRC32 check"
)

add_custom_target(
    performCrc32
    DEPENDS performCrc32.py
    performCrc32.out
)

I was able to solve the problem. Thank you to all who helped and contributed such great ideas:

    add_custom_command(
    POST_BUILD
    COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/performCrc32.py
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    OUTPUT  performCrc32.out
    COMMENT "Running CRC32 check..."
)
add_custom_target(
    performCrc32 ALL
    DEPENDS performCrc32.py
    performCrc32.out
) 
S_Balb
  • 197
  • 1
  • 1
  • 7
  • shoudlnt be like COMMAND python performCrc32.py ? – Eliethesaiyan May 26 '17 at 02:06
  • See if [this](https://stackoverflow.com/questions/11551779/how-to-make-cmake-execute-some-script-after-it-generates-visual-studio-solution) helps. – AmeyaVS May 26 '17 at 05:54
  • @Tsyvarev, I believe my question is different because it involves running a Python script, which may or may not have specific Cmake syntax to execute a Python script. – S_Balb May 26 '17 at 16:40
  • Python is unrelated: your *COMMAND* passed to `add_custom_command` simply isn't executed. And duplicate question asks exactly about that. The first its answer suggests to use `add_custom_target` command with appropriate *DEPENDS* option. And your code lacks for this option. – Tsyvarev May 26 '17 at 20:29
  • @Tsyvarev, I added in the command you recommended. I also added in the command you recommended by Eliethesaiyan, however, the script still isn't doing anything. Something is still incorrect... – S_Balb May 26 '17 at 21:25
  • It works with `make performCrc32`. If you want it to be worked with `make`, add *ALL* option to the `add_custom_target`: `add_custom_target( performCrc32 ALL DEPENDS performCrc32.py performCrc32.out )` – Tsyvarev May 26 '17 at 22:09
  • @Tsyvarev, thank you. Some progress has been made once I added the _ALL_ option after "performCrc32". Now the compiler is complaining about a binary directory: '[1/1] Running CRC32 check... Bin Directory doesn't exist: performCrc32.py'. I believe that I need to manually add in the path of where the .py must execute. – S_Balb May 26 '17 at 22:38

0 Answers0