[CMake] Creating links / Uninstalling links

Brad King brad.king at kitware.com
Thu May 25 10:23:13 EDT 2006


Michael Biebl wrote:
> what's the the correct way to do the following:
> 1) Compile and install a binary foo to /usr/bin/foo
> 2) Create a link /usr/bin/bar -> /usr/bin/foo
> 3) On "make uninstall" remove /usr/bin/foo and /usr/bin/bar
> 
> For 1+2, I used
> SET_TARGET_PROPERTIES(foo PROPERTIES POST_INSTALL_SCRIPT make_links.cmake)

In CMake 2.4 you can do

ADD_EXECUTABLE(foo foo1.cxx ...)
INSTALL(TARGETS foo DESTINATION bin)
INSTALL(CODE "
   EXECUTE_PROCESS(
     COMMAND \${CMAKE_COMMAND} -E remove \${CMAKE_INSTALL_PREFIX}/bin/bar
     COMMAND \${CMAKE_COMMAND} -E create_symlink foo 
\${CMAKE_INSTALL_PREFIX}/bin/bar
     )
   LIST(APPEND CMAKE_INSTALL_MANIFEST_FILES 
\${CMAKE_INSTALL_PREFIX}/bin/bar)
")

The INSTALL(CODE ...) command puts code directly into the install 
script.  Note that by escaping the dollar signs '\$' they are placed 
literally into the script which will evaluate the variables at install 
time.  The CMAKE_INSTALL_MANIFEST_FILES variable maintains a list of 
installed files.

Use this with care...the code will still try to run on Windows platforms 
where there are no symlinks and the executables have a .exe extension.

-Brad


More information about the CMake mailing list