Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake follow symbolic links during install

Tags:

llvm

cmake

Short question: Is it possible to set CMake to follow symlinks when copying files during an install, and if so how is this done?

Details: I am using CMake to build and install LLVM. In my LLVM source tree in the include directory I have a symbolic link to another subproject that is being developed against LLVM. Everything seems to work, except that I noticed that when I ran "cmake install" that it copied the include directory without following the symlinks. The problem that I have is that my symlinks have a relative path (because it is inside a git repo). So when the symlinks are copied (instead of followed and copying the contents) they no longer point to the correct files. For example I have dsa -> ../../llvm-poolalloc/include/dsa/ I would like to copy the contents of this link when I do the install rather than just copying the link. But I did not find a cmake flag for doing this yet.

I realize that this is probably not the idea way to structure my project, but I am working with something that's already in place and it would be preferable to not have to change too much of the directory structures because other people I am working with expect it to be this way. So I think that being able to follow symlinks might solve my problem without having to restructure the whole build system. But I am open to other suggestions for better ways to accomplish what I am trying to do.

Note that I am working in Linux (Ubuntu 10.04) and using LLVM 2.6 (that I am compiling from source along with llvm-gcc). Also I am using CMake version 2.8.

Edit:

Here is the source code from the CMakeLists.txt file that is associated with the install instruction:

install(DIRECTORY include
  DESTINATION .
  PATTERN ".svn" EXCLUDE
  PATTERN "*.cmake" EXCLUDE
  PATTERN "*.in" EXCLUDE
  PATTERN "*.tmp" EXCLUDE
  )

install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include
  DESTINATION .
  )

the directory listing for the include directory is:

dsa -> ../../llvm-poolalloc/include/dsa/
llvm
llvm-c
poolalloc -> ../../llvm-poolalloc/include/poolalloc

What I want is for the dsa and poolalloc directories to be copied rather than just copying the symbolic links. The reason that I don't use absolute paths in the symbolic links is that I have them checked into a git repo. So my absolute path would differ from someone else working on the project when they do a checkout from the repo.

like image 736
Gabriel Southern Avatar asked Oct 08 '22 16:10

Gabriel Southern


1 Answers

Hmm, let's try this:

get_filename_component(ABS_DIR include REALPATH)

install(DIRECTORY ${ABS_DIR}
  DESTINATION .
  PATTERN ".svn" EXCLUDE
  PATTERN "*.cmake" EXCLUDE
  PATTERN "*.in" EXCLUDE
  PATTERN "*.tmp" EXCLUDE
  )

If it wouldn't help, you can try to install not the include dir itself (which is symlink), but it's contents. But in your case you would need to came up with smart regex:

file(GLOB INCLUDES include/*) # filter there .svn and others

install(FILES ${INCLUDES}
  DESTINATION include
)

Finally, make the symlink absolute.

like image 73
arrowd Avatar answered Oct 13 '22 12:10

arrowd