CMake sets Target output directory and suffix

Original link: https://ifmet.cn/posts/4af498c8/

**Brief description: ** CMake sets Target output directory and suffix name

 set ( EXECUTABLE_OUTPUT_PATH "xxx/path" ) # 可执行文件的输出目录set ( LIBRARY_OUTPUT_PATH "xxx/path" ) # 库文件的输出目录set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "xxx/path" ) # debug 可执行文件的输出目录set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "xxx/path" ) # release 可执行文件的输出目录set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "xxx/path" ) # debug 库文件的输出目录set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "xxx/path" ) # release 库文件的输出目录set ( CMAKE_DEBUG_POSTFIX "xxx/path" ) # debug 库文件的后缀名set ( CMAKE_RELEASE_POSTFIX "xxx/path" ) # release 库文件的后缀名set_target_properties ( ${ TARGET_NAME } PROPERTIES DEBUG_POSTFIX "_d" ) # debug 可执行文件的后缀名set_target_properties ( ${ TARGET_NAME } PROPERTIES RELEASE_POSTFIX "_r" ) # release 可执行文件的后缀名

[TOC]

This article was originally published on ” Xie Zang’s Small Station “, and is reproduced here simultaneously.

text

1. set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../bin)

The above statement can set the output directory of the executable file

In the Win + VS environment, a <CONFIG> directory will be automatically expanded behind the directory you set, so the final generated Debug version program will be in the ${PROJECT_SOURCE_DIR}/../bin/Debug directory, the Release version program will be in the ${PROJECT_SOURCE_DIR}/../bin/Release directory.

In Linux + GCC environment, whether it is Debug or Release, the generated executable program will be directly placed in the directory you set, and there will be no difference.

2. set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../lib)

The above statement can set the output directory of the library file

In the Win + VS environment, a <CONFIG> directory will be automatically expanded behind the directory you set, so the final generated Debug version library will be in the ${PROJECT_SOURCE_DIR}/../lib/Debug directory, Release version library will be in the ${PROJECT_SOURCE_DIR}/../lib/Release directory.

In Linux + GCC environment, whether it is Debug or Release, the generated library files will be directly placed in the directory you set, and there will be no difference.

3. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/../bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/../bin)

The above two statements set the output directory of the executable file of the Debug version and the Release version, respectively.

Once the above properties are set, the executable generated in any environment will be placed directly in the directory you set.

Four. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/../lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/../lib)

The above two statements set the output directory of the Debug version and the Release version library file respectively.

Once the above properties are set, the library files generated in any environment will be placed directly in the directory you set.

Five. set(CMAKE_DEBUG_POSTFIX "_d") set(CMAKE_RELEASE_POSTFIX "_r")

The above two statements set the suffix names of the library files in the Debug version and the Release version respectively.

6. set_target_properties(${TARGET_NAME} PROPERTIES DEBUG_POSTFIX "_d") set_target_properties(${TARGET_NAME} PROPERTIES RELEASE_POSTFIX "_r")

The above two statements set the suffix of the executable file in the Debug version and the Release version respectively.

Serial address

ExCMake

Welcome to star ⭐ and fork 🍴 this series of CMake learning, with a directory of learning from shallow to deep.

This article is reproduced from: https://ifmet.cn/posts/4af498c8/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment

Your email address will not be published.