/
output_options.cmake
27 lines (22 loc) · 1.22 KB
/
output_options.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Ensure that all outputs (shared libraries, static libraries, executables, etc.) end up in the same
# directory as the executable:
# See also:
# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#runtime-output-artifacts
# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#library-output-artifacts
# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#archive-output-artifacts
#
# Attention!
# If the binary directory already contains a directory with the same name as the resulting build
# target (executable) then the linker will complain: 'ld: cannot open output file .: Is a directory'
# This will most likely only happen under Linux, because executables don't get an .exe extension.
# https://stackoverflow.com/questions/38168725/cmake-trying-to-link-directory-as-an-executable-if-their-names-match
function(set_default_output_target_options targetName)
report("Setting default output options for target '${targetName}'")
set(outputDirectory ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
set_target_properties(${targetName}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${outputDirectory}
LIBRARY_OUTPUT_DIRECTORY ${outputDirectory}
ARCHIVE_OUTPUT_DIRECTORY ${outputDirectory}
)
endfunction()