Home > Backend Development > C++ > How to Configure CMake to Separate Binaries and Libraries from Source Code?

How to Configure CMake to Separate Binaries and Libraries from Source Code?

Mary-Kate Olsen
Release: 2024-12-17 14:09:10
Original
700 people have browsed it

How to Configure CMake to Separate Binaries and Libraries from Source Code?

How to Configure CMake Output Directory for Binaries

To resolve the issue where CMake generates binaries and libraries within the source directory hierarchy, you can modify CMake's output settings to specify a dedicated destination directory.

Solution:

To direct CMake to place the compiled artifacts in a separate directory like "./bin", employ the following techniques:

  1. Global Output Directories:

    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
    Copy after login
  2. Target-Specific Output Directories:

    set_target_properties(targets...
        PROPERTIES
        ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
        LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
        RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
    )
    Copy after login

In both scenarios, you can append "_[CONFIG]" (e.g., "_DEBUG") to the variable or property name to customize the output directory for a particular configuration (e.g., "Debug").

The above is the detailed content of How to Configure CMake to Separate Binaries and Libraries from Source Code?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template