Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake install header files and maintain directory heirarchy

Tags:

cmake

Using cmake 2.8

I would like to maintain the directory heirarchy while copying the header files from the source to the destination directory. For example, the header file that needs to be copied are abc/1.h, def/2.h and they should also be copied in the same order in the destination directly ( set via CMAKE_INSTALL_PREFIX )

This is what I have tried, but it just copies the header files and not the header files inclusive parent directory name

set(HEADERS "abc/1.h;def/2.h")
install(FILES ${HEADERS} DESTINATION include)

The final output should be dest_directory/abc/1.h and dest_directory/def/2.h.

like image 353
infoclogged Avatar asked Jan 11 '18 17:01

infoclogged


People also ask

How do I specify the install directory in CMake?

The installation directory is usually left at its default, which is /usr/local . Installing software here ensures that it is automatically available to users. It is possible to specify a different installation directory by adding -DCMAKE_INSTALL_PREFIX=/path/to/install/dir to the CMake command line.

Do you include header files in CMake?

To include headers in CMake targets, use the command target_include_directories(...) . Depending on the purpose of the included directories, you will need to define the scope specifier – either PUBLIC , PRIVATE or INTERFACE .

What is Cmake_install CMake file?

As previous answer tells, the cmake_install. cmake contains the commands generated by install command from your CMakeLists. txt . You can execute it by cmake -P cmake_install. cmake and it performs the installation of your project even on windows.

What does install command do in CMake?

CMake provides the install command to specify how a project is to be installed. This command is invoked by a project in the CMakeLists file and tells CMake how to generate installation scripts. The scripts are executed at install time to perform the actual installation of files.


1 Answers

If you have many files in the directory for install, you may consider to install the directory with install(DIRECTORY) command flow. You may select which files in the directory should be installed with PATTERN or REGEX options:

install(DIRECTORY "${CMAKE_SOURCE_DIR}/" # source directory
        DESTINATION "include" # target directory
        FILES_MATCHING # install only matched files
        PATTERN "*.h" # select header files
)

See CMake documentation for more information about the install(DIRECTORY). Also, it describes meaning '/' at the end of source directory.

like image 109
Tsyvarev Avatar answered Sep 28 '22 00:09

Tsyvarev