I am using CMake to create and build my project solution. i am using the following command to add a post build event to copy a .tlb from the local bin to the program bin.
ADD_CUSTOM_COMMAND(TARGET ${PROJECT_NAME} POST_BUILD COMMAND xcopy /D /Y "${CMAKE_SOURCE_DIR}LocalBin\\example.tlb" "${CMAKE_SOURCE_DIR}ProgramBin\\$<CONFIGURATION>\\")
When this adds the command to the project properties , it is added as
xcopy /D /Y LocalBin\example.tlb ProgramBin\Debug\
However this gives me an error. Exited with Code 4.
If i go into the project properties and hack the command line and change it to add " "
xcopy /D /Y "LocalBin\example.tlb " "ProgramBin\Debug\"
It works.
Is there a way i can change the CMake add custom command to include the " " in the actual command line so it will work and there is no need to manually change the project properties.
You have to escape the quotation mark inside the string. Escaping is done in CMake with a back slash. So adding a quotation mark to your string, add \"
.
Quoting the CMake documentation https://cmake.org/cmake/help/v3.4/manual/cmake-language.7.html#escape-sequences
A
\
followed by a non-alphanumeric character simply encodes the literal character without interpreting it as syntax
In your case you'll end up with
"\"${CMAKE_SOURCE_DIR}LocalBin\\example.tlb\""
instead of
"${CMAKE_SOURCE_DIR}LocalBin\\example.tlb"
After struggling with this for some time, I found a workable solution using generator expressions:
ADD_CUSTOM_COMMAND(TARGET ${PROJECT_NAME} POST_BUILD COMMAND xcopy /D /Y $<1:"${CMAKE_SOURCE_DIR}LocalBin\\example.tlb"> $<1:"${CMAKE_SOURCE_DIR}ProgramBin\\$<CONFIGURATION>\\">)
This is an open bug in CMake.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With