0

Imagine the following lines in a CMakeFiles.txt:

add_custom_target( target
          cd bin
          COMMAND echo "test" > README
)

make target will not work as expected, as it will not modify the file bin/README but rather the file ./README. I found out that, in order to make CMake modify bin/README, I have to write

COMMAND cd bin && echo "test" > README

which is time consuming and blows the CMakeLists up when used multiple times. I want a behavior that is much like the behaviour of shell scripts. How can I achieve this?

4

1 回答 1

1

Use the WORKING_DIRECTORY directive:

add_custom_target( target
      COMMAND echo "test" > README
      WORKING_DIRECTORY bin
)

EDIT: Reversed COMMAND and WORKING_DIRECTORY order

于 2013-05-03T22:38:54.863 回答