Issue
Is there a way in CMake to find a binary target complete name (mybin.exe) by inspecting target properties? Like
get_target_property(EXENAME targetname OUTPUT_NAME)
(or RUNTIME_OUTPUT_NAME)
Or I have to use a custom command like in How to get library full-native name on cmake?
With get_target_property seems I'm only able to get the "logical" target name out of it (mybin), with no other information. Am I missing something?
Thank you
Solution
There's a reason this is not possible without generator expressions: There are multi configuration generators such as the Visual Studio generators that create a build system for multiple build configurations (Release, Debug, ...) in a single CMake configuration run (cmake -S ... -B ...
). It's even the default to create binaries in a directory with a name matching the configuration built.
Depending on what you want to do with the information, there are some alternatives:
You may be able to use generator expressions, e.g. if you need the information as part of
add_custom_command
,add_custom_target
,add_test
or similar. Several target properties also allow for use of generator expressions.You may be able to establish the desired directory structure during an install step, see the
install()
command.You may be able to get the build system to generate the files in a specific location e.g. by setting the
CMAKE_RUNTIME_OUTPUT_DIRECTORY
variable in the toplevelCMakeLists.txt
. Note that this will still result in configuration dependent subdirectories being created for multi configuration generators, unless the variable value contains a generator expression. (You could, simply be adding$<0:>
, but this could easily result in binaries of different configurations overwriting one another.)If you cannot specify this in the toplevel
CMakeLists.txt
, via command line or cmake presets, you could still use a path relative toCMAKE_BINARY_DIR
; this should make the binaries easy to locate.
Answered By - fabian Answer Checked By - David Marino (WPSolving Volunteer)