I have a custom command that is executed in the pre linking stage. What I want to do is calculate a checksum of all parts that are going to be part of my executable. Then I want to link link this checksum as a global variable into my executable.
So far I can calculate the checksum of all libraries that are going to be linked into my executable. But I also need the checksum of the already existing (because its already been built) object file of the exe. Is there a way to get access to this object file?
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/checksum.cpp
PRE_LINK
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/checksum_generator.cmake" ${LIB_DEPENDENCIES} <object_file_of_executable_target>
DEPENDS ${LIB_DEPENDENCIES}
)
add_library(checksum STATIC ${CMAKE_CURRENT_BINARY_DIR}/checksum.cpp)
target_link_libraries(executable_target PUBLIC checksum)
So my question is: How can I get the object file of the executable target?
Every time I try to access some generator expression of the executable_target and pass it, CMake crashes because of cyclic dependencies (which is true for the output executable, but not for the object files since they already exists in the pre link stage).