[CMake] INSTALL with RENAME

Michael Hertling mhertling at online.de
Fri May 27 11:40:13 EDT 2011


On 05/26/2011 09:42 PM, J Decker wrote:
> It's a windows XP target, so symlinks aren't doable...
> 
> On Thu, May 26, 2011 at 12:12 PM, Alexander Neundorf
> <a.neundorf-work at gmx.net> wrote:
>> On Thursday 26 May 2011, J Decker wrote:
>>> How do I install a single target as multiple names? (for something like
>>> busybox)
>>
>> Did you try install(CODE ... ) or install(SCRIPT ... ) to create symlinks at
>> install time ?
>>
>> Alex

AFAIK, the RENAME clause isn't available for the INSTALL(TARGETS ...)
signature, and when using INSTALL(CODE|SCRIPT ...), you will probably
lose the INSTALL() command's advanced features, e.g. the COMPONENT or
CONFIGURATIONS clause. Therefore, I'd suggest to create the symlinks/
copies already in the build tree via a POST_BUILD custom command and
install them afterwards regularly by INSTALL(PROGRAMS ...):

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(MULTINST C)
SET(CMAKE_VERBOSE_MAKEFILE ON)
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "int main(void){return 0;}\n")
ADD_EXECUTABLE(main main.c)
INSTALL(TARGETS main DESTINATION bin)
FOREACH(i rm ls mv cp)
    ADD_CUSTOM_COMMAND(TARGET main POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E create_symlink
            $<TARGET_FILE_NAME:main> ${CMAKE_BINARY_DIR}/util_${i})
    INSTALL(PROGRAMS ${CMAKE_BINARY_DIR}/util_${i} DESTINATION bin)
ENDFOREACH()

Instead of create_symlink, you might also use copy_if_different.
Besides, having the symlinks/copies already available in the
build tree could be convenient w.r.t. testing.

Regards,

Michael


More information about the CMake mailing list