开发者

How do I use a target's path in add_custom_command in CMake?

开发者 https://www.devze.com 2023-02-19 12:19 出处:网络
In CMakeLists.txt have a library called \"library.dll\". I want to add a post build event to copy the resulting file to a different directory. The documentation says to use generator events, but it\'s

In CMakeLists.txt have a library called "library.dll". I want to add a post build event to copy the resulting file to a different directory. The documentation says to use generator events, but it's not working:

add_custom_command(TARGET library.dll POST_BUILD COMMAND co开发者_如何转开发py $<TARGET_FILE:library.dll> \"${SOME_DIR}/bin\")

I'm using CMake 2.8.3 to generate VC++ 2010 project files on Windows 7.


Try the following changes:

Add the VERBATIM option which ensures that all arguments to the command will be escaped properly.

Instead of using the Windows built-in copy command, invoke CMake in command mode which has a platform independent copy command built-in.

The modified command looks like this:

add_custom_command(TARGET library.dll POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:library.dll> ${SOME_DIR}/bin VERBATIM)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号