How to Simplify build time commands

Hi everyone,
i’m writing a target for building and uploading at build time a custom target, and i have written a monster like this:

add_custom_target(targetUploader
        # Install target in installDir within its binary folder
        COMMAND ${CMAKE_COMMAND} --install $<TARGET_PROPERTY:${targetName},BINARY_DIR> --config $<CONFIG> --prefix $<TARGET_PROPERTY:${targetName},BINARY_DIR>/installDir
        # Zip installed headers and upload them on remote repository
        COMMAND ${CMAKE_COMMAND} -E tar cf $<TARGET_PROPERTY:${targetName},BINARY_DIR>/includes.zip $<TARGET_PROPERTY:${targetName},BINARY_DIR>/installDir/${CMAKE_INSTALL_INCLUDEDIR}
        COMMAND ${CMAKE_COMMAND} -Durl=${BASE_URL}/$<CONFIG>/includes/${targetName}/includes.zip -DfileName=$<TARGET_PROPERTY:${targetName},BINARY_DIR>/installDir/${CMAKE_INSTALL_INCLUDEDIR}/includes.zip -P buildTimeNetworking.cmake
        # Zip generated target file and upload it on remote repository
        COMMAND ${CMAKE_COMMAND} -E tar cf $<TARGET_PROPERTY:${targetName},BINARY_DIR>/${targetName}.zip $<TARGET_PROPERTY:${targetName},BINARY_DIR>/installDir/${CMAKE_INSTALL_LIBDIR}/$<TARGET_FILE:${targetName}>
        COMMAND ${CMAKE_COMMAND} -Durl=${BASE_URL}/$<CONFIG>/libs/${targetName}/${targetName}.zip -DfileName=$<TARGET_PROPERTY:${targetName},BINARY_DIR>/installDir/${CMAKE_INSTALL_LIBDIR}/${targetName}.zip -P buildTimeNetworking.cmake
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

Is there a way to simplify build time commands creating variables (that contains generator expressions) to be shared among commands?
Thanks in advance for any help

You could probably write this as a CMake script that you execute with -P after doing file(GENERATE) to get the genexes expanded (or pass them as -D argument values).

1 Like

Thanks a lot, didn’t know about file(GENERATE) command