2

I have a python script that generates .cpp sources that are used in consequent compilation. The script uses some 3rd-party modules, and I'm trying to set PYTHONPATH to modules location.

I tried to do set(ENV${PYTHONPATH} "/path/to/modules"), but unfortunately it works only for generation time i.e. execute_process(COMMAND python the_script.py), while I need it to work for add_custom_command/add_custom_target.

I am using Visual Studio 14 2015 Win64 generator.

ivaigult
  • 6,198
  • 5
  • 38
  • 66

1 Answers1

5

You can use CMake's Command-Line Tool Mode:

add_custom_command(
    ... 
    COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH="/path/to/modules" python the_script.py
)
Florian
  • 39,996
  • 9
  • 133
  • 149