0

So i am using cmake command to build and run certain stuff now if I run this command directly in shell it works

and build file

but if I run it inside python with the help of subprocess nothing is happening.

code cmake file

enter image description here

now to run this I used the following command in terminal $ mkdir build && cd build

$ cmake .. && make

it totally works

now in python first command is working and the build directory is formed but cmake is not working.

enter image description here

  • [Do not use `aux_source_directory` for getting lists of source files.](https://stackoverflow.com/a/65191951/2137996) It is outright incorrect. – Alex Reinking Jan 31 '21 at 10:14
  • Also do not use `include_directories`. Use `target_include_directories(COSMO PRIVATE inc)` instead. – Alex Reinking Jan 31 '21 at 10:19
  • 1
    Using **images** for code is **discouraged** on Stack Overflow. Please, [edit] the question and paste the code into it as **text**. See also [ask]. – Tsyvarev Jan 31 '21 at 10:37

1 Answers1

0

Your problem is that subprocess.run does not maintain the current working directory between calls. so cmake .. runs in the directory above the build folder, not in the build folder. You should use the following two commands, instead anyway:

$ cmake -S . -B build
$ cmake --build build

The first command tells CMake to use the current directory (.) for sources (-S) and to use the directory build for build outputs (-B). It will create that directory if it does not exist.

The second command asks CMake to invoke the native build tool (in your case make) in the given directory (build).

You should be able to paste those into your subprocess.run calls and have it work without shell=True.

Alex Reinking
  • 16,724
  • 5
  • 52
  • 86