简体   繁体   中英

Why EXECUTABLE_OUTPUT_PATH does not work?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM