enable_language(C) add_executable(echo echo.c) add_custom_command( OUTPUT echo_raw_$.txt COMMAND echo $ echo_raw_$.txt WORKING_DIRECTORY $ ) add_custom_command( OUTPUT echo_genex_$,Debug,$,Release,$,MinSizeRel,RelWithDebInfo>>>.txt COMMAND $ $> echo_genex_$>.txt WORKING_DIRECTORY $> ) add_custom_command( OUTPUT echo_genex_out_$.txt COMMAND $> $ echo_genex_out_$.txt WORKING_DIRECTORY $> ) add_custom_command( OUTPUT depend_$.txt COMMAND ${CMAKE_COMMAND} -E echo depend_$.txt ) add_custom_command( OUTPUT echo_depend_$.txt COMMAND ${CMAKE_COMMAND} -E echo echo_depend_$.txt DEPENDS depend_$.txt ) add_custom_command( OUTPUT echo_depend_out_$.txt COMMAND ${CMAKE_COMMAND} -E echo echo_depend_out_$.txt DEPENDS $.txt> ) add_custom_command( OUTPUT echo_depend_cmd_$.txt COMMAND ${CMAKE_COMMAND} -E echo echo_depend_cmd_$.txt DEPENDS $.txt> ) add_custom_command( OUTPUT depend_echo_raw_$.txt COMMAND ${CMAKE_COMMAND} -E echo depend_echo_raw_$.txt DEPENDS echo ) add_custom_command( OUTPUT depend_echo_genex_$.txt COMMAND ${CMAKE_COMMAND} -E echo depend_echo_genex_$.txt DEPENDS $ ) add_custom_command( OUTPUT depend_echo_genex_out_$.txt COMMAND ${CMAKE_COMMAND} -E echo depend_echo_genex_out_$.txt DEPENDS $> ) add_custom_command( OUTPUT depend_echo_genex_cmd_$.txt COMMAND ${CMAKE_COMMAND} -E echo depend_echo_genex_cmd_$.txt DEPENDS $> ) # An OUTPUT that is not per-config prevents cross-config generation. add_custom_command( OUTPUT echo_no_cross_output.txt echo_no_cross_output_$.txt COMMAND echo $ echo_no_cross_output_$.txt WORKING_DIRECTORY $ ) add_custom_command( OUTPUT echo_no_cross_output_$,a,b>.txt echo_no_cross_output_if_$.txt COMMAND echo $ echo_no_cross_output_if_$.txt WORKING_DIRECTORY $ ) # BYPRODUCTS that are not per-config prevent cross-config generation. add_custom_command( OUTPUT echo_no_cross_byproduct_$.txt BYPRODUCTS echo_no_cross_byproduct.txt COMMAND echo $ echo_no_cross_byproduct_$.txt WORKING_DIRECTORY $ ) add_custom_command( OUTPUT echo_no_cross_byproduct_if_$.txt BYPRODUCTS echo_no_cross_byproduct_$,a,b>.txt COMMAND echo $ echo_no_cross_byproduct_if_$.txt WORKING_DIRECTORY $ ) foreach(case echo_raw echo_genex echo_genex_out echo_depend echo_depend_out echo_depend_cmd depend depend_echo_raw depend_echo_genex depend_echo_genex_out depend_echo_genex_cmd echo_no_cross_output echo_no_cross_output_if echo_no_cross_byproduct echo_no_cross_byproduct_if ) set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${case}_Debug.txt ${CMAKE_CURRENT_BINARY_DIR}/${case}_Release.txt ${CMAKE_CURRENT_BINARY_DIR}/${case}_MinSizeRel.txt ${CMAKE_CURRENT_BINARY_DIR}/${case}_RelWithDebInfo.txt PROPERTY SYMBOLIC 1) add_custom_target(${case} DEPENDS ${case}_$.txt) endforeach() # An OUTPUT in only one configuration. add_custom_command( OUTPUT "$<$:echo_dbg_Debug.txt>" COMMAND echo $ "$<$:echo_dbg_Debug.txt>" ) set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/echo_dbg_Debug.txt PROPERTY SYMBOLIC 1) add_custom_target(echo_dbg DEPENDS "$<$:echo_dbg_Debug.txt>") # An OUTPUT in only one configuration with BYPRODUCTS in every configuration. add_custom_command( OUTPUT "$<$:echo_dbgx_Debug.txt>" BYPRODUCTS echo_dbgx_byproduct_$.txt COMMAND echo $ "$<$:echo_dbgx_Debug.txt>" echo_dbgx_byproduct_$.txt COMMAND_EXPAND_LISTS ) set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/echo_dbgx_Debug.txt ${CMAKE_CURRENT_BINARY_DIR}/echo_dbgx_byproduct_Debug.txt ${CMAKE_CURRENT_BINARY_DIR}/echo_dbgx_byproduct_Release.txt ${CMAKE_CURRENT_BINARY_DIR}/echo_dbgx_byproduct_MinSizeRel.txt ${CMAKE_CURRENT_BINARY_DIR}/echo_dbgx_byproduct_RelWithDebInfo.txt PROPERTY SYMBOLIC 1) add_custom_target(echo_dbgx DEPENDS "$<$:echo_dbgx_Debug.txt>") # A non-cross-config custom command expresses target dependencies in command config. add_custom_command( OUTPUT echo_depend_target.txt COMMAND ${CMAKE_COMMAND} -E env $ $ # A real project should do: # DEPENDS $ # but here we are testing the target-level dependency implied by TARGET_FILE. ) add_custom_target(echo_depend_target DEPENDS echo_depend_target.txt) add_custom_target(echo_target_raw BYPRODUCTS echo_target_raw_$.txt COMMENT echo_target_raw COMMAND echo $ echo_target_raw_$.txt WORKING_DIRECTORY $ ) add_custom_target(echo_target_genex BYPRODUCTS echo_target_genex_$.txt COMMENT echo_target_genex COMMAND $ $> echo_target_genex_$>.txt WORKING_DIRECTORY $> ) add_custom_target(echo_target_genex_out BYPRODUCTS echo_target_genex_out_$.txt COMMENT echo_target_genex_out COMMAND $> $ echo_target_genex_out_$.txt WORKING_DIRECTORY $> ) add_custom_target(echo_target_depend COMMAND ${CMAKE_COMMAND} -E echo echo_target_depend_$.txt DEPENDS depend_$.txt COMMENT echo_target_depend ) add_custom_target(echo_target_depend_out COMMAND ${CMAKE_COMMAND} -E echo echo_target_depend_out_$.txt DEPENDS $.txt> COMMENT echo_target_depend_out ) add_custom_target(echo_target_depend_cmd COMMAND ${CMAKE_COMMAND} -E echo echo_target_depend_cmd_$.txt DEPENDS $.txt> COMMENT echo_target_depend_cmd ) # BYPRODUCTS that are not per-config block cross-configs. add_custom_target(target_no_cross_byproduct BYPRODUCTS target_no_cross_byproduct.txt COMMENT target_no_cross_byproduct COMMAND echo $ target_no_cross_byproduct.txt WORKING_DIRECTORY $ ) add_custom_target(target_post_build COMMENT target_post_build COMMAND ${CMAKE_COMMAND} -E echo "target main build" ) add_custom_command(TARGET target_post_build POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo "target post build" )