<div dir="ltr"><div><div><div><div><div>Hello Paul,<br><br></div>Many thanks, seems a better solution than mine. <br><br></div>I created a custom target calling my script but doing this way I had to do make install && make install_files, it doesn't look good.<br><br></div>Also had to change install(FILES) to file( COPY ).<br></div><div><br></div><div>I will try install(SCRIPT) later today.<br></div><div><br></div>Once again, thanks for the answer.<br></div>Daniel Yoshizawa.<br></div><div class="gmail_extra"><br><div class="gmail_quote">2017-10-18 20:36 GMT-02:00 paul <span dir="ltr"><<a href="mailto:pfultz2@yahoo.com" target="_blank">pfultz2@yahoo.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You can use install(CODE) or install(SCRIPT) to run custom cmake code at<br>
install time. The only caveat is the install location is actually<br>
`$ENV{DESTDIR}${CMAKE_INSTALL_<wbr>PREFIX}` instead of just<br>
`${CMAKE_INSTALL_PREFIX}`. This can happen when the user calls `make<br>
DESTDIR=<path>` or during cpack.<br>
<div><div class="h5"><br>
On Wed, 2017-10-18 at 15:03 -0200, Daniel Yoshizawa wrote:<br>
> Hello everyone,<br>
><br>
> I have a problem and couldn't find a solution over the internet, the<br>
> situation is that I must copy some files at make install, the trick is, I<br>
> must check if the files exists at install time if they don't, I must copy<br>
> the files, otherwise do nothing.<br>
><br>
> It doesn't feel anywhere near fine to me, but this is what are asking me to<br>
> do, so there is no other way.<br>
><br>
> My initial solution was to check if the file don't exist, if so I create a<br>
> INSTALL command for it, the problem is that it runs at the configuration<br>
> phase and I need something at install or post install, this files have<br>
> nothing to do with the build, are just configuration files or other non-<br>
> related stuff, so no target for them.<br>
><br>
> One more thing, I know just the cmake basics, so please any help is welcome.<br>
><br>
> Below is my original code that create the INSTALL commands at configuration<br>
> phase.<br>
><br>
> ------------------------------<wbr>------------------------------<wbr>----------------<br>
> ------------------------------<wbr>------------------------------<wbr>----------------<br>
> -----<br>
><br>
> ##############################<wbr>##############################<wbr>################<br>
> ##############<br>
> #<br>
> #   Desc : Files installation script, checks if the file exist on<br>
> destination folder,<br>
> #          if so, doesn't overwrite the files.<br>
> #<br>
> #   Params : input_file - File path with <source file>:<destination><br>
> #            must be one entry per line following the model above.<br>
> #<br>
> #   Obs : It is advised create .in files using ${CMAKE_SOURCE_DIR} to<br>
> describe the path,<br>
> #         calling configure_file to generate the correct path.<br>
> #<br>
> #   Ref : <a href="https://cmake.org/cmake/help/v3.2/command/configure_file.html" rel="noreferrer" target="_blank">https://cmake.org/cmake/help/<wbr>v3.2/command/configure_file.<wbr>html</a><br>
> #<br>
> ##############################<wbr>##############################<wbr>################<br>
> ##############<br>
><br>
> function (install_files input_file)<br>
><br>
>     MESSAGE("Files to be installed.")<br>
><br>
>     file(STRINGS ${input_file} contents)<br>
><br>
>     foreach(tuple ${contents})<br>
>         string(REPLACE ":" ";" tuple_list ${tuple})<br>
>         list(GET tuple_list 0 source)<br>
>         list(GET tuple_list 1 destination)<br>
><br>
>         if(IS_DIRECTORY ${source})<br>
>             install_directory(${source} ${destination})<br>
>         else(IS_DIRECTORY ${source})<br>
>             install_file(${source} ${destination})<br>
>         endif()<br>
><br>
>     endforeach()<br>
><br>
> endfunction(install_files input_file)<br>
><br>
> function (install_directory path_to_dir path_to_destination)<br>
><br>
>     file(GLOB folder_files "${path_to_dir}/*")<br>
><br>
>     foreach(filename ${folder_files})<br>
><br>
>         if(IS_DIRECTORY ${filename})<br>
>             get_filename_component( dir ${filename} NAME )<br>
>             install_directory(${filename} ${path_to_destination}/${dir})<br>
>         else(IS_DIRECTORY ${filename})<br>
>             install_file(${filename} ${path_to_destination})<br>
>         endif()<br>
><br>
>     endforeach(filename)<br>
><br>
> endfunction(install_directory path_to_dir path_to_destination)<br>
><br>
> function (install_file path_to_file path_to_destination)<br>
><br>
>     get_filename_component( filename ${path_to_file} NAME )<br>
>     <br>
>     if (NOT EXISTS ${path_to_destination}/${<wbr>filename})<br>
>         MESSAGE("source path      : ${path_to_file}")<br>
>         MESSAGE("destination path : ${path_to_destination}")<br>
><br>
>         install (FILES "${path_to_file}"<br>
>                     DESTINATION "${path_to_destination}"<br>
>                     PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE<br>
> GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE<br>
>                 )<br>
>     endif()<br>
><br>
> endfunction (install_file path_to_file path_to_destination)<br>
><br>
> ------------------------------<wbr>------------------------------<wbr>----------------<br>
> ------------------------------<wbr>------------------------------<wbr>----------------<br>
> -----<br>
><br>
> Sorry for any mistakes and many thanks in advance,<br>
> Daniel Yoshizawa.<br>
</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.o" rel="noreferrer" target="_blank">http://www.cmake.o</a><br>
> rg/Wiki/CMake_FAQ<br>
><br>
> Kitware offers various services to support the CMake community. For more<br>
> 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/<wbr>support.html</a><br>
> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>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/<wbr>training.html</a><br>
><br>
> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensourc" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensourc</a><br>
> e/opensource.html<br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/cmake</a><br>
</blockquote></div><br></div>