cmake add_custom_target preserve directory

2019-08-30 07:33发布

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?

标签: cmake
1条回答
倾城 Initia
2楼-- · 2019-08-30 08:32

Use the WORKING_DIRECTORY directive:

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

EDIT: Reversed COMMAND and WORKING_DIRECTORY order

查看更多
登录 后发表回答