0

I'm sorry if this is obvious, but I have a command that basically does the following:

mkdir -p /home/developer/cmake-build-debug cd /home/developer/cmake-build-debug cmake -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=/home/developer/cmake-build-debug -DCMAKE_BUILD_TYPE=Debug ..

I'm expecting this to build the CMake project in /home/developer and output the Makefile etc. to /home/developer/cmake-build-debug. However, the output I get is

Output Directory: /home/developer/cmake-build-debug -- Boost version 1.58.0 -- Configuring done -- Generating done -- Build files have been written to: /home/developer

and the build artifacts get created in /home/developer.

The reason I get the first line is my CMakeLists.txt has the following line in it for debugging: message("Output Directory: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}").

This has happened before and I think it kind of "randomly" stopped happening, but I just rebuilt the docker container in which I'm doing this and I'm at a loss for why this is happening. Can someone explain why this is happening and how to fix it?

River Tam
  • 3,096
  • 4
  • 31
  • 51
  • IIUC, you want the build files (like the generated `Makefile`) to be placed under the directory you specified with `-DCMAKE_RUNTIME_OUTPUT_DIRECTORY`? That's not what that flag is for. [`CMAKE_RUNTIME_OUTPUT_DIRECTORY`](https://cmake.org/cmake/help/latest/variable/CMAKE_RUNTIME_OUTPUT_DIRECTORY.html) sets the location for generated executables, basically, where any executable file created via `add_executable(...)` will be placed. – Justin May 29 '18 at 18:55
  • @Justin Oh, I see. Thank you! Is it possible to also place the build files somewhere else? I'm not seeing a `CMAKE_BUILD_OUTPUT_DIRECTORY` or anything like that. – River Tam May 29 '18 at 19:01
  • Usually what I do is navigate to the build directory and invoke cmake there: `cd /home/developer/cmake-build-debug`, `cmake -DCMAKE_BUILD_TYPE=Debug /path/with/cmakelists ` – Justin May 29 '18 at 19:08
  • @Justin I'm not sure what you mean. This is what I'm doing. However, the `Makefile` still gets generated in /home/developer – River Tam May 29 '18 at 19:10
  • I'm seeing evidence that other people are doing the same thing. I'm confused as to why this isn't working for me. I'm literally typing `pwd && cmake ..` and it's saying `/home/developer/cmake-build-debug ... Build files have been written to: /home/developer` – River Tam May 29 '18 at 19:16
  • I removed `/home/developer/CMakeCache.txt` and that seems to have worked, though I am very unclear why. – River Tam May 29 '18 at 19:17
  • Make sure the project doesn't modify `CMAKE_BINARY_DIR` or some other *read-only* variables. – Tsyvarev May 29 '18 at 19:18
  • @RiverTam Yes, that would do it. You don't want `/home/developer/CMakeCache.txt` or `/home/developer/CMakeFiles/`. That file and directory should be in the build directory, not in the source directory. – Justin May 29 '18 at 19:26

0 Answers0