0

so I have the following project layout:

- CMakeLists.txt
- include/
  - ...
- src/
  - CMakeLists.txt
  - binary1.cc
  - binary2.cc
  - ...
- third_party/
  - project1/
     - CMakeLists.txt
     - ...
- bin/

The CMakeLists.txt in the root directory basically contains the following statements:

add_subdirectory(src)
add_subdirectory(third_party/project1)
...

To build I do the following:

cd bin/
cmake ..
make

.. which will happily build everything, but it places binary1 and binary2 into /bin/src whereas I would prefer them to live in /bin/ directly (for some compatibility reasons).

I tried the following, but cmake will not configure because " ../bin is already used to build a source directory. It cannot be used to build.":

add_subdirectory(src .)

Can someone provide hints?

2
  • 1
    You could maybe use CMAKE_RUNTIME_OUTPUT_DIRECTORY like adding -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=$PWD to the cmake command. You could also use set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR)
    – Justin
    Feb 17, 2021 at 7:41
  • `set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) worked. Previously I had tried set(CMAKE_RUNTIME_OUTPUT_DIRECTORY .) but that didn't do it. Thanks.
    – milck
    Feb 17, 2021 at 9:10

0

Browse other questions tagged or ask your own question.