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:
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)
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" )
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!