John Doe
John Doe

Reputation: 419

CMake change forced DESTINATION directory name (install target)

I'm trying to add install target to my library. I have my source code & header files located in sub-directories under src/.

Relevant chunk of my CMakeLists.txt file:

install(
    TARGETS "${PROJECT_NAME}"
    EXPORT ionir-config LIBRARY
    DESTINATION ${CMAKE_INSTALL_LIBDIR} # Destination is relative to ${CMAKE_INSTALL_PREFIX}.
)

install(
    EXPORT ionir-config
    NAMESPACE ionir::
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ionir
)

install(
    DIRECTORY src
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
    FILES_MATCHING PATTERN "*.h" PATTERN "LICENSE" # Match only header files & LICENSE file.
)

The problem is that once installed, the output directory's name is src:

directory output as src instead of ionir

I would like it to be ionir, otherwise I'd have to import files like this:

#include <ionir/src/something/file.h>
                ^^^

How can I accomplish this?

Upvotes: 1

Views: 2048

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 65938

For avoid adding directory name to installation path, terminate the directory with a slash (/):

install(
    DIRECTORY src/
    ...
)

This is explicitly stated in the documentation for install command:

The last component of each directory name is appended to the destination directory but a trailing slash may be used to avoid this because it leaves the last component empty.

Upvotes: 7

Related Questions