I have such files
.
├── CMakeLists.txt
└── src
├── CMakeLists.txt
└── main.c
And this is the content about this files
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
PROJECT (HELLO)
ADD_SUBDIRECTORY(src bin)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/binarydir)
$ cat src/CMakeLists.txt
ADD_EXECUTABLE(hello main.c)
$ cat src/main.c
#include <stdio.h>
int main()
{
printf("Hello World from t1 main().\n");
return 0;
}
Then I build it with following command
$ mkdir build
$ cd build
$ cmake ..
$ make
This is the result directory structure
Then the binary hello
will produced in directory build/bin
as the picture, but it should be in build/binarydir
since I have set
the value for EXECUTABLE_OUTPUT_PATH
, isn't it? What I have missed?
You are creating executable target before setting EXECUTABLE_OUTPUT_PATH
. Move SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/binarydir)
line before ADD_SUBDIRECTORY(src bin)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With