开发者

How copy a file to the same directory as the .exe file

开发者_Python百科This i probably trival, but I haven't figured it out yet. I have a .ini file in the same directory as the source code and I want cmake to copythis inifile.ini to the directory where the .exe file is generated. This dirctory can vary depending on if I do a release or Debug build and if I do a insource or out-of-source build. I have come this far:

configure_file(${myapp_SOURCE_DIR}/src/myinifile.ini
               ${myapp_BINARY_DIR}/bin/${????}/myinifile.ini COPYONLY)

But I need to include bin/Debug or bin/Release in the destination path depending on the build type. Is there a cmake variable I can use that points to the actual directory where the .exe will be generated. Or what is the best way to do this.


You can get a LOCATION property to find the output path for your target. Next you can use its value in add_custom_command:

get_target_property(exepath target_name LOCATION)
get_filename_component(outputpath "${exepath}" PATH)
add_custom_command(TARGET target_name POST_BUILD
    COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${myapp_SOURCE_DIR}/src/myinifile.ini" "${outputpath}")

This code will automatically handle build type dependency.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜