Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 267
piwi Avatar asked Oct 04 '22 22:10

piwi


1 Answers

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.

like image 124
ixSci Avatar answered Oct 10 '22 02:10

ixSci