How to get target install location from CMake?

Viewed 2065

I would like to create a "post-install" script for my CMake build, but for this I need the install location for a given target.

For example:

function(post_install_target target)
    set(target_install_loc ???) # Somehow
    message("Target install location is ${target_install_loc}")
endfunction(post_install_target)

# ...

post_install_target(A) # Some target defined elsewhere.

This could print:

-- Target install location is /usr/local/lib/libA.so

I already tried this answer, (by using $<TARGET_FILE:tgt>) but the result is the location in the build tree, not in the install tree (i.e. it prints /home/me/project/build/libA.so).

1 Answers

The variable responsible for the installation path is CMAKE_INSTALL_PREFIX, try it, its default value should be /usr/local/ cmake documentation

Related