How use custom Post Build Steps with Multi Config Generators

Hey guys,
we are using Ninja Multi Config for Windows and Cross Platform ARM embedded builds.
On Windows (native) Ninja multi Config Works fine, however our Cross Platform Target Build needs some extra custom commands.

The simplified syntax is as follows


add_executable( ${APP_NAME} ${APP_SRC} )
target_include_directories(${APP_NAME} PRIVATE ...)
target_link_libraries(${APP_NAME} PRIVATE ...)

      # ###########################################################
      # create map files
      # ###########################################################


add_custom_command(
TARGET "${APP_NAME}"
   POST_BUILD
    COMMAND ${CMAKE_NM} --format=sysv --demangle --line-numbers "${PROJECT_BINARY_DIR}/bin/${APP_NAME}${CMAKE_EXECUTABLE_SUFFIX}" > "${PROJECT_BINARY_DIR}/bin/map/${APP_NAME}.nmap")

Now as you can see the custom command expects the binary to be located in ./bin.

However - due to the multi config generator - the binary is now located in
./bin/Debug
or
./bin/Release

How can I get the actual binary path? CMAKE_CURRENT_BINARY points to the ./bin folder and not the ./bin/Debug folder.

Thx for your help :slight_smile:

You can replace all of that with $<TARGET_FILE:${APP_NAME}> and it’ll work everywhere including when CMAKE_RUNTIME_DESTINATION changes where binaries end up or OUTPUT_NAME changes the name of the file on disk. You can also use $<TARGET_FILE_DIR> to compute the destination file path.

Thank you Ben, that worked nicely :slight_smile: