this repo has no description
1# This macro can be used to install symlinks, which turns out to be
2# non-trivial due to CMake version differences and limitations on how
3# files can be installed when building binary packages.
4#
5# The rule for binary packaging is that files (including symlinks) must
6# be installed with the standard CMake install() macro.
7#
8# The rule for non-binary packaging is that CMake 2.6 cannot install()
9# symlinks, but can create the symlink at install-time via scripting.
10# Though, we assume that CMake 2.6 isn't going to be used to generate
11# packages because versions later than 2.8.3 are superior for that purpose.
12#
13# _filepath: the absolute path to the file to symlink
14# _sympath: absolute path of the installed symlink
15
16macro(InstallSymlink _filepath _sympath)
17 cmake_parse_arguments(INSTALL_SYMLINK "EXCLUDE_FROM_ALL" "COMPONENT" "" ${ARGN})
18
19 get_filename_component(_symname ${_sympath} NAME)
20 get_filename_component(_installdir ${_sympath} PATH)
21
22 if (INSTALL_SYMLINK_EXCLUDE_FROM_ALL)
23 set(EXCLUDE_FROM_ALL_ARG "EXCLUDE_FROM_ALL")
24 else()
25 set(EXCLUDE_FROM_ALL_ARG "")
26 endif()
27
28 if (DEFINED INSTALL_SYMLINK_COMPONENT)
29 set(COMPONENT_ARG COMPONENT "${INSTALL_SYMLINK_COMPONENT}")
30 else()
31 set(COMPONENT_ARG "")
32 endif()
33
34 if (BINARY_PACKAGING_MODE)
35 execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink
36 ${_filepath}
37 ${CMAKE_CURRENT_BINARY_DIR}/${_symname})
38 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_symname}
39 DESTINATION ${_installdir} ${EXCLUDE_FROM_ALL_ARG} ${COMPONENT_ARG})
40 else ()
41 # scripting the symlink installation at install time should work
42 # for CMake 2.6.x and 2.8.x
43 install(CODE "
44 if (\"\$ENV{DESTDIR}\" STREQUAL \"\")
45 execute_process(COMMAND \"${CMAKE_COMMAND}\" -E make_directory ${_installdir})
46 execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink
47 ${_filepath}
48 ${_installdir}/${_symname})
49 else ()
50 execute_process(COMMAND \"${CMAKE_COMMAND}\" -E make_directory \$ENV{DESTDIR}/${_installdir})
51 execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink
52 ${_filepath}
53 \$ENV{DESTDIR}/${_installdir}/${_symname})
54 endif ()
55 " ${EXCLUDE_FROM_ALL_ARG} ${COMPONENT_ARG})
56 endif ()
57endmacro(InstallSymlink)