-- set(TGT_LOCATION $<TARGET_FILE:gtest-tidy-mwe>)
CMake Warning at CMakeLists.txt:66 (message):
TGT_LOCATION: $<TARGET_FILE:gtest-tidy-mwe>
but this works fine?
# Additional command which will run after the above from a different directory
add_custom_command(TARGET gtest-tidy-mwe
POST_BUILD
COMMAND md5sum $<TARGET_FILE:gtest-tidy-mwe> > gtest-tidy-mwe.md5
BYPRODUCTS ${CMAKE_BINARY_DIR}/verify/gtest-tidy-mwe.md5
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/verify
)
You can’t reliably get the location of a target at configure time. For a multi-config generator, the location depends on the configuration, and the configuration is only selected at build time.
Don’t use the LOCATION target property. It should be considered an old historical hangover from before generator expressions existed. It cannot give you the location of the binary in a multi-config world.
The message() command doesn’t and can never understand generator expressions because it executes at configure time. By definition, generator expressions can only be evaluated at generation time, which occurs after the configure stage has finished.
If you pass a string to message() and it contains generator expressions, they won’t be evaluated.
Also, for file(GENERATE), it doesn’t write out the file immediately. It essentially schedules the file to be written during the generation phase. You can’t read it at configure time (if you try to, at best you’ll be reading the file that was generated in the previous run).