<div dir="ltr">It just can't copy to the same source directory. <br></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Sep 21, 2018 at 4:32 PM J Decker <<a href="mailto:d3ck0r@gmail.com">d3ck0r@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Fri, Sep 21, 2018 at 3:29 PM J Decker <<a href="mailto:d3ck0r@gmail.com" target="_blank">d3ck0r@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Fri, Sep 21, 2018 at 3:24 PM Ke Gao <<a href="mailto:ke.gao.ut@gmail.com" target="_blank">ke.gao.ut@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div>Thanks. I forgot to say my CMakeList.txt is not located together with the source files. So I used the following, it seems not working:</div><div>
<span class="m_-4440568739938406751m_-8245040714888366822gmail-m_-758922598119219225gmail-im"><div><div>add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/../../aaa_file.c</div><div>                           DEPENDS 
<span class="m_-4440568739938406751m_-8245040714888366822gmail-m_-758922598119219225gmail-im">${CMAKE_CURRENT_SOURCE_DIR}/../../</span>file.c</div><div>                           COMMAND ${CMAKE_COMMAND} -E copy_if_different 
<span class="m_-4440568739938406751m_-8245040714888366822gmail-m_-758922598119219225gmail-im">${CMAKE_CURRENT_SOURCE_DIR}/../../</span>file.c 
<span class="m_-4440568739938406751m_-8245040714888366822gmail-m_-758922598119219225gmail-im">${CMAKE_CURRENT_SOURCE_DIR}/../../</span>aaa_file.c</div></div></span><div>    )</div><div>Is there an easier way to do this?</div></div></div></div></blockquote><div>not really...</div><div>NOt sure why it wouldn't work unless current_source_dir isn't what you think it is.</div><div>I actually copy mine into </div></div></div></div></blockquote><div><br></div><div>It also wouldn't work if you didn't use ${CMAKE_CURRENT_SORUCE_DIR}/../../aaa_file.c in another target.</div><div>(and by the same path... which is partially why I copy into BINARY_DIR, then it's in a known place for all projects int he tree</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div> </div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div><br></div><div><div>                           COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SOURCE} ${CMAKE_BINARY_DIR}/${BASENAME}</div></div><div><br></div><div> (basename is the path part of the ${SOURCE})</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div><div><br></div>

</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Sep 21, 2018 at 4:10 PM J Decker <<a href="mailto:d3ck0r@gmail.com" target="_blank">d3ck0r@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Fri, Sep 21, 2018 at 3:00 PM Ke Gao <<a href="mailto:ke.gao.ut@gmail.com" target="_blank">ke.gao.ut@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>In a project, I need to first duplicate a source file and rename it. For example, I want to change "file.c" to "aaa_file.c", and after compiling, I will delete it. This is similar to using "cp file.c aaa_file.c". How to easily do this in CMake? I found "file" command doesn't work well for this.</div><div><br></div></div></blockquote><div><br></div><div><div><div>add_custom_command( OUTPUT aaa_file.c</div><div>                           DEPENDS file.c</div><div>                           COMMAND ${CMAKE_COMMAND} -E copy_if_different file.c aaa_file.c</div></div><div>    )</div><div><br></div><div>then you just have to reference the source file 'aaa_file.c' and it will get updated if file.c is different. I also do</div></div><div>                             COMMAND ${CMAKE_COMMAND} -E touch aaa_file.c</div><div><br></div><div>just to make sure it is new.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div></div><div>Thank you very much.</div><div><br>-- <br><div dir="ltr" class="m_-4440568739938406751m_-8245040714888366822gmail-m_-758922598119219225m_-424420261291211824gmail-m_2135251374350216418gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><font size="1" face="arial,helvetica,sans-serif" color="#000000">..............................................................................................................................................</font></div><font face="tahoma,sans-serif" color="#3366ff"><div><font style="background-color:rgb(255,255,255)" face="arial black,sans-serif" color="#000000">Ke Gao</font></div></font></div></div></div></div></div></div></div></div>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div></div></div>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="m_-4440568739938406751m_-8245040714888366822gmail-m_-758922598119219225gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><font color="#000000" face="arial,helvetica,sans-serif" size="1">..............................................................................................................................................</font></div><font color="#3366ff" face="tahoma,sans-serif"><div><font color="#000000" face="arial black,sans-serif" style="background-color:rgb(255,255,255)">Ke Gao</font></div></font></div></div></div></div></div></div>
</blockquote></div></div></div>
</blockquote></div></div>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><font color="#000000" face="arial,helvetica,sans-serif" size="1">..............................................................................................................................................</font></div><font color="#3366ff" face="tahoma,sans-serif"><div><font color="#000000" face="arial black,sans-serif" style="background-color:rgb(255,255,255)">Ke Gao</font></div></font></div></div></div></div></div></div>