Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I install a hierarchy of files using CMake?

Tags:

cmake

I've created a list of files using:

file(GLOB_RECURSE DEPLOY_FILES "${PROJECT_SOURCE_DIR}/install/*") 

I want to install all of these files in /usr/myproject/, but I want to maintain the file tree on the installed folder:

install/junk install/other/junk2 install/other/junk3 

If I use:

install(FILES ${DEPLOY_FILES} DESTINATION "usr/myproject") 

All the files end up in /usr/myproject as:

/usr/myproject/junk /usr/myproject/junk2 /usr/myproject/junk3 

How can I make the install command keep track of relative paths?

I've worked around the issue by doing it manually in a for loop:

set(BASE "${PROJECT_SOURCE_DIR}/install") foreach(ITEM ${DEPLOY_FILES})   get_filename_component(ITEM_PATH ${ITEM} PATH)   string(REPLACE ${BASE} "" ITEM_PATH ${ITEM_PATH})   install(FILES ${ITEM} DESTINATION "usr/myproject${ITEM_PATH}") endforeach() 

...but this is annoying to do. Surely there's an easier way?

(I can't see anything in the install documentation though...)

like image 218
Doug Avatar asked Jun 19 '12 07:06

Doug


1 Answers

The simplest way to install everything from a given directory is:

install(DIRECTORY mydir/ DESTINATION dir/newname) 

Trailing '/' is significant. Without it mydir would be installed to newname/mydir.

From the CMake documentation:

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.

like image 162
marcin Avatar answered Oct 11 '22 08:10

marcin