<div dir="ltr">Dear all, <div><br></div><div class="cye-lm-tag">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 class="cye-lm-tag">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 class="cye-lm-tag"><br></div><div class="cye-lm-tag">and as a matter of facts this does the string replacement I'm interested in.</div><div class="cye-lm-tag"><br></div><div class="cye-lm-tag">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 class="cye-lm-tag"><br></div><div class="cye-lm-tag"><code></div><div class="cye-lm-tag"><br></div><div class="cye-lm-tag"><div class="gmail-cye-lm-tag">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 class="gmail-cye-lm-tag"></div></div><div class="cye-lm-tag">ExternalProject_Add( </div><div class="cye-lm-tag">...</div><div class="cye-lm-tag"><br></div><div class="cye-lm-tag">PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/patch_script.cmake</div><div class="cye-lm-tag"><br></div><div class="cye-lm-tag">... )</div><div class="cye-lm-tag"><br></div><div class="cye-lm-tag"></code></div><div class="cye-lm-tag"><br></div><div class="cye-lm-tag">Notice that I write the patch_script.cmake before the ExternalProject_Add</div><div class="cye-lm-tag"><br></div><div class="cye-lm-tag"><br></div><div class="cye-lm-tag">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 class="cye-lm-tag"><br></div><div class="cye-lm-tag">I get</div><div class="cye-lm-tag">CMake Error at build/patch_script.cmake:3 (string):<br>  string sub-command REPLACE requires at least four arguments.<br></div><div class="cye-lm-tag"><br></div><div class="cye-lm-tag">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 class="cye-lm-tag"><br></div><div class="cye-lm-tag">cmake version 3.15.2</div><div class="cye-lm-tag"><br></div><div class="cye-lm-tag">Thanks for any help.</div><div class="cye-lm-tag"><br></div><div class="cye-lm-tag">Edo<br></div><div class="cye-lm-tag"><br></div><div class="cye-lm-tag"><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><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>