<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 17, 2019 at 2:14 AM Edoardo Pasca <<a href="mailto:edo.paskino@gmail.com">edo.paskino@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">Hi Tom,<div><br></div><div>I thought ${testdata} was going to be filled in by the actual patch_script.cmake at this line.</div><div><br></div><div><span style="color:rgb(0,0,0)">file (STRINGS TestData.py testdata NEWLINE_CONSUME)</span> </div></div></blockquote><div><br></div><div>Sorry, some nasty formatting in my email client had me misreading your script. My advice is mainly based on this error:</div><div><br></div><div> CMake Error at build/patch_script.cmake:3 (string):<br> string sub-command REPLACE requires at least four arguments </div><div><br></div><div>Looking at this line:</div><div>string(REPLACE \"sys.prefix\" \"os.environ[\\\'SIRF_INSTALL_PATH\\\']\" patched \${testdata})<br></div><div><br></div><div>The most likely possible reason for that error being reported by CMake is that ${testdata} is not defined when that line of script is executed. What does line 3 of patch_script.cmake look like immediately after the error message is output? My guess is that it looks something like this:</div><div><br></div><div> string(REPLACE "sys.prefix" "os.environ[\'SIRF_INSTALL_PATH\']" patched ) <br></div><div><br></div><div>As you'll notice REPLACE is only receiving 3 args in the above version.</div><div><br></div><div>Also note: I don't think you need to escape the single quotes in the os.environ argument (unless they must be escaped in the final output). Basic toy scripts here show it as unnecessary unless they must be escaped in the patched file.</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><br></div><div> So it appears that this command doesn't quite work.<br></div><div><br></div><div>I'll try also Alan's suggestion.</div><div><br></div><div>Thanks</div><div><br></div><div>Edo</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 15, 2019 at 7:00 PM Tom Finegan <<a href="mailto:tomfinegan@google.com" target="_blank">tomfinegan@google.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">It looks like you aren't passing the $testdata variable down to the script. From your message it looks like you need to add the following to your PATCH_COMMAND:<div><br></div><div>-Dtestdata=${testdata}</div><div><br></div><div>You must explicitly pass $testdata (and any other variables defined in the calling script) to patch_script.cmake via -D parameters on the command line. Also note that the -Dvar=value args must precede the -P <script> argument for the arguments to be defined in the script.</div><div><br></div><div>Note: I'm not certain about the rules for ExternalProject_Add. The above is based on the behavior of execute_process(), but the error message you've sent leads me to believe that the problem here is the same: Variables from the calling CMake scope are not automatically passed along to the scope of child CMake instances.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 14, 2019 at 4:01 AM Edoardo Pasca <<a href="mailto:edo.paskino@gmail.com" target="_blank">edo.paskino@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">Dear all, <div><br></div><div>I am using external project. I would like to patch a source file. I came out with a cmake script that does the string replacement I'm interested in.</div><div><br></div><div>I tested in a standalone project, with the following CMakeLists.txt</div><div><br></div><div>cmake_minimum_required(VERSION 3.4)<br>project(patching_string)<br>file (STRINGS TestData.py testdata NEWLINE_CONSUME)<br>string(REPLACE "sys.prefix" "os.environ[\'SIRF_INSTALL_PATH\']" patched ${testdata})<br>file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/TestData.py ${patched} )<br clear="all"><div><br></div><div>and as a matter of facts this does the string replacement I'm interested in.</div><div><br></div><div>Good, now I would like to use this to the project I'm really interested in which uses the ExternalProject_Add machinery. I added the patch step:</div><div><br></div><div><code></div><div><br></div><div><div>file (WRITE ${CMAKE_BINARY_DIR}/patch_script.cmake "<br>file (STRINGS ${${proj}_SOURCE_DIR}/Wrappers/Python/ccpi/framework/TestData.py testdata NEWLINE_CONSUME)<br>string(REPLACE \"sys.prefix\" \"os.environ[\\\'SIRF_INSTALL_PATH\\\']\" patched \${testdata})<br>file( WRITE ${${proj}_SOURCE_DIR}/Wrappers/Python/ccpi/framework/TestData.py \${patched} ) ")<br></div><div></div></div><div>ExternalProject_Add( </div><div>...</div><div><br></div><div>PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/patch_script.cmake</div><div><br></div><div>... )</div><div><br></div><div></code></div><div><br></div><div>Notice that I write the patch_script.cmake before the ExternalProject_Add</div><div><br></div><div><br></div><div>Now, all of this WORKS. Or at least I get the patch_script.cmake file in the proper directoty, with the content I want. However, execution with cmake -P patch_script.cmake doesn't work as expected.</div><div><br></div><div>I get</div><div>CMake Error at build/patch_script.cmake:3 (string):<br> string sub-command REPLACE requires at least four arguments.<br></div><div><br></div><div>Given that the patch_script.cmake has the same content of the standalone CMakeLists.txt above (without the first 2 lines), I don't know where things don't go well, except that I execute the script with cmake -P</div><div><br></div><div>cmake version 3.15.2</div><div><br></div><div>Thanks for any help.</div><div><br></div><div>Edo<br></div><div><br></div><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div>Edo</div><div>I know you think you understand what you thought I said, but I'm not sure you realize that what you heard is not what I meant (prob. Alan Greenspan)<br>:wq</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>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div>Edo</div><div>I know you think you understand what you thought I said, but I'm not sure you realize that what you heard is not what I meant (prob. Alan Greenspan)<br>:wq</div></div></div></div></div>
</blockquote></div></div>