Max Beikirch
Max Beikirch

Reputation: 2143

cmake add_custom_target preserve directory

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?

Upvotes: 0

Views: 1946

Answers (1)

SethMMorton
SethMMorton

Reputation: 48725

Use the WORKING_DIRECTORY directive:

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

EDIT: Reversed COMMAND and WORKING_DIRECTORY order

Upvotes: 1

Related Questions