6

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.

Gabriel Southern
  • 9,602
  • 12
  • 56
  • 95
  • Can you please show code, which installs these includes? Also, you can just make symlink absolute. – arrowd Feb 14 '12 at 07:57
  • @arrowdodger, thanks for looking at my question. I edited it to provide more detail but let me know if it's still unclear. I've been looking at the CMake documentation for `install` and I'm starting to think that what I wanted to do isn't possible so I'll probably have to come up with another solution. But I could be wrong because there is a lot I don't know about CMake. – Gabriel Southern Feb 14 '12 at 21:40
  • answer to the question is [here](https://stackoverflow.com/a/11525966/671509) – John McFarlane Feb 12 '23 at 11:20

1 Answers1

4

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.

arrowd
  • 33,231
  • 8
  • 79
  • 110
  • 1
    it looks like it's not possible to follow symbolic links with the install command. But this answer was helpful for me in figuring out how to restructure my CMakeLists.txt and add more install statements that pointed to the other directories that I wanted to copy. – Gabriel Southern Feb 16 '12 at 19:45