# Operating on Target after it's built to modify based on input file

**URL:** https://discourse.cmake.org/t/operating-on-target-after-its-built-to-modify-based-on-input-file/13575
**Category:** Code
**Created:** [February 13, 2025, 10:07pm UTC](https://discourse.cmake.org/t/operating-on-target-after-its-built-to-modify-based-on-input-file/13575 "2025-02-13T22:07:12Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [February 15, 2025, 5:48am UTC](https://discourse.cmake.org/t/operating-on-target-after-its-built-to-modify-based-on-input-file/13575/5 "2025-02-15T05:48:33Z")

</div>

You may use a checksum check to trigger the build again if needed:

```cmake

add_library(ObjLib OBJECT ${CMAKE_BINARY_DIR}/gtest-tidy-mwe.cpp)

# NOTE: OBJECT_DEPENDS does not help? CK
# TODO: set_property(TARGET ObjLib PROPERTY OBJECT_DEPENDS ${CMAKE_BINARY_DIR}/verify/gtest-tidy-mwe.md5)

add_executable(gtest-tidy-mwe $<TARGET_OBJECTS:ObjLib>)

target_link_libraries(gtest-tidy-mwe PRIVATE GTest::gtest_main)

# enable clang-tidy for my target only!
target_enable_clang_tidy(gtest-tidy-mwe)

enable_testing()
add_test(NAME gtest-tidy-mwe COMMAND gtest-tidy-mwe)
install(TARGETS gtest-tidy-mwe)

# Additional command which will run after the above from a different directory
add_custom_command(
    TARGET gtest-tidy-mwe
    POST_BUILD
    COMMAND md5sum $<TARGET_OBJECTS:ObjLib> $<TARGET_FILE:gtest-tidy-mwe> > gtest-tidy-mwe.md5
    BYPRODUCTS ${CMAKE_BINARY_DIR}/verify/gtest-tidy-mwe.md5
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/verify
)

# Additional target the depends on BYPRODUCT above ...
add_custom_target(
    check
    COMMAND md5sum -c gtest-tidy-mwe.md5 || touch $<TARGET_OBJECTS:ObjLib>
    DEPENDS gtest-tidy-mwe
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/verify
)

```

---

_[View the full topic](https://discourse.cmake.org/t/operating-on-target-after-its-built-to-modify-based-on-input-file/13575)._
