[CMake] Install files at absolute position?

Zachary Pincus zpincus at stanford.edu
Wed Jan 18 19:17:57 EST 2006


Andy,

Thanks for the tip on installing things at absolute locations.

Here's a hackish macro to do this, in case anyone needs it. (Note --  
macro can only be used once per directory, and only one install path  
is allowed per use. Modifications are an exercise for the reader.)

Zach

MACRO(INSTALL_AT_ABSOLUTE_PATH PATH)
   # USAGE:
   # INSTALL_AT_ABSOLUTE_PATH("/path/to/install" "/path/to/file1" ...  
"path/to/fileN")
   #
   # Only use this macro once per directory -- otherwise the custom  
installation
   # will get overwritten.

   FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CustomInstall.cmake" "")

   FOREACH(file ${ARGN})
     GET_FILENAME_COMPONENT(filename "${file}" NAME)
     STRING(REGEX REPLACE "/$" "" stripped_path "${PATH}")
     FILE(APPEND "${CMAKE_CURRENT_BINARY_DIR}/CustomInstall.cmake"
      "MESSAGE(STATUS \"Installing ${stripped_path}/${filename}\")\n")
     FILE(APPEND "${CMAKE_CURRENT_BINARY_DIR}/CustomInstall.cmake"
      "FILE(INSTALL DESTINATION \"${PATH}\" TYPE FILE FILES \"${file} 
\")\n")
   ENDFOREACH(file)

   ADD_CUSTOM_TARGET("${CMAKE_CURRENT_BINARY_DIR}/CustomInstall" ALL)
   SET_TARGET_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/CustomInstall"  
PROPERTIES
     POST_INSTALL_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/ 
CustomInstall.cmake")

ENDMACRO(INSTALL_AT_ABSOLUTE_PATH)



On Jan 18, 2006, at 6:40 AM, Andy Cedilnik wrote:

> Hi Zach,
>
> There is a way to do installing using custom install script. What  
> you do is to create a cmake script that does whatever you want and  
> then set on some target a pre and/or post install script:
>
> SET_TARGET_PROPERTIES(myLib PROPERTIES PRE_INSTALL_SCRIPT "$ 
> {CMAKE_CURRENT_BINARY_DIR}/some_pre_install.cmake"
>  POST_INSTALL_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/ 
> some_post_install.cmake")
>
>
> Then you can put in that file:
> FILE(INSTALL DESTINATION "/etc" TYPE FILE FILES "/home/andy/ 
> MyProject/myetc.file")
>
> Andy
>
>
> Zachary Pincus wrote:
>
>> Hello again,
>>
>> I'm wondering if there is any good way to have CMake install a   
>> particular file at an absolute position in the filesystem (not   
>> prefixed by CMAKE_INSTALL_PREFIX) during 'make install'.
>>
>> It's clearly possible to send a file to any given location during  
>> the  configure or build step, but it's more appropriate to do this  
>> during  install, in my case.
>>
>> Any thoughts? (and yes, the files do need to be at specific   
>> positions; for example in a python site-packages directory).
>>
>> Thanks,
>>
>> Zach
>> _______________________________________________
>> CMake mailing list
>> CMake at cmake.org
>> http://www.cmake.org/mailman/listinfo/cmake
>
>
>
> -- 
> Andy Cedilnik
> Kitware Inc.
>
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list