Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, multiple commands can have different working directories in a custom target in CMake. Each command in a custom target can specify its own working directory using the WORKING_DIRECTORY option. For example:

add_custom_target(my_target
  COMMAND my_command1 arg1 arg2
  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/dir1
  COMMAND my_command2 arg3 arg4
  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/dir2
)

In this example, my_command1 will be executed in the ${CMAKE_SOURCE_DIR}/dir1 directory, and my_command2 will be executed in the ${CMAKE_SOURCE_DIR}/dir2 directory.