0

I have a DDS project that takes IDL files and generates C++ header and footer files from them using a "ProcessIDL.py" script. Previously this was done in as a pre build step in Visual Studio. I am in the process of converting the project to CMake to come in line with other repositories so thought it made sense to run the ProcessIDL.py as part of the cmake build step.

I have tried using execute_process but it doesn't seem to be doing anything, no error, no output from the python script so I don't think it is being run at all. Here is my attempt:

include(FindPythonInterp)
set (py_cmd "python ProcessIDL.py")
message(STATUS ${PYTHON_EXECUTABLE})

execute_process(
                  COMMAND ${py_cmd}
                  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/DdsIdl
                  ERROR_VARIABLE error
                  OUTPUT_VARIABLE output
               )

I have also tried this:

include(FindPythonInterp)
set (py_cmd "python ProcessIDL.py")
message(STATUS ${PYTHON_EXECUTABLE})

execute_process(
                  COMMAND ${PYTHON_EXECUTABLE} ${py_cmd}
                  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/DdsIdl
                  ERROR_VARIABLE error
                  OUTPUT_VARIABLE output
               )

The "error" and "output" variables are empty.

I am pretty stumped so any tips would be appreciated!!

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • Not sure if I got it right but if I did: Have a look for [add_custom_command](https://cmake.org/cmake/help/latest/command/add_custom_command.html). Also FYI: [Cmake: How to build custom compiler binary and then use it for some targets?](https://stackoverflow.com/a/55227658/7478597) about how to build C++ sources in a custom build step which are then compiled with the rest to a binary. – Scheff's Cat Mar 31 '22 at 16:38
  • So the output files are defined and created within the python script, I'm not sure if CMake needs to know what they are to run a script so I wasn't sure how I'd use add_custom_command to do this – tashywashyy Mar 31 '22 at 16:52

1 Answers1

0

This was solved by changing the working directory:

execute_process(COMMAND python ProcessIDL.py 
    WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})