Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why EXECUTABLE_OUTPUT_PATH does not work?

Tags:

c++

build

cmake

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?

like image 641
tem Avatar asked Feb 25 '18 10:02

tem


1 Answers

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).

like image 179
arrowd Avatar answered Oct 25 '22 23:10

arrowd