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.
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.
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 .
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With