visual-studiocmakepost-build-event

How to set a post build command to VS project from cmake?


I need to set this post-build event in cmake

how to do this?

I am using below command in my vs project, but I need to add it during CMake build in Cmakelists.txt

xcopy /y /d "$(TargetPath)" "$(ProjectDir)$(Platform)\$(Configuration)" 

I tried following but they didn't work for me VS cannot find the path

How to copy DLL files into the same folder as the executable using CMake?

CMake post-build-event: copy compiled libraries

add_custom_command(
    TARGET my 
    POST_BUILD        
    COMMAND ${CMAKE_COMMAND} xcopy /y /d "$(TargetPath)" "$(ProjectDir)$(Platform)\$(Configuration)" 
) 

error --> this $(ProjectDir)$(Platform)$(Configuration) not giving right path it shows x64Debug not x64\Debug


Solution

  • It works as explained in the above comment

    backslash should escaped: \\ 
    
    add_custom_command(TARGET my POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy
        "$(TargetPath)"
        "$(ProjectDir)$(Platform)\\$(Configuration)" 
    )