In CMake, how to run a script after targets get installed?

cmake, installation

Solution

If you found that cmake places sub-dir install targets to the end of the cmake_install you can just add another sub-dir with cmake containing what you need to be done after all other targets.

Problem

I am trying to run a script after CMake install completes. I found this thread on SO, but it still does not work, because my script depends on the installed targets. Basically my script gets ran before the targets are installed. This is because CMake seems to put the code which installs the targets of sub-directories at the end of `cmake_install.cmake` Here is an example that illustrates the problem; the sub-directory CMake file: ``` # src/CMakeLists.txt add_executable(foo main.cpp) install(TARGETS foo DESTINATION bin) ``` The top-level CMake file: ``` # Top-level CMakeLists.txt cmake_minimum_required(VERSION 2.8) add_subdirectory(src) install(CODE "execute_process(COMMAND ls ${CMAKE_INSTALL_PREFIX}/bin/foo)") ``` Running `make install` yields: ``` -- Install configuration: "debug" ls: cannot access /tmp/dummy/bin/foo: No such file or directory -- Installing: /tmp/dummy/bin/foo ``` Any idea how I can work around this behavior? Thanks!

Original source

Related problems