robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
7840760776
master
1# Fix CMAKE_INSTALL_MANDIR on BSD before including GNUInstallDirs. #6771 2if ( CMAKE_SYSTEM_NAMEMATCHES "BSD" AND NOT DEFINED CMAKE_INSTALL_MANDIR) 3if ( DEFINED ENV{MANPREFIX}) 4set ( CMAKE_INSTALL_MANDIR " $ ENV { MANPREFIX } /man" ) 5elseif ( CMAKE_INSTALL_PREFIXMATCHES "^/usr/local $ " ) 6set ( CMAKE_INSTALL_MANDIR "man" ) 7endif () 8endif () 9 10# This will create any directories that need to be created in the destination 11# path with the typical owner, group, and user permissions--independent of the 12# umask setting. 13function ( create_install_dir_with_perms ) 14cmake_parse_arguments ( _install_dir 15"" 16"DESTINATION" 17"DIRECTORY_PERMISSIONS" 18${ ARGN } 19) 20 21if ( NOT _install_dir_DESTINATION) 22message ( FATAL_ERROR "Must specify DESTINATION" ) 23endif () 24 25if ( NOT _install_dir_DIRECTORY_PERMISSIONS) 26set ( _install_dir_DIRECTORY_PERMISSIONS 27OWNER_READ OWNER_WRITE OWNER_EXECUTE 28GROUP_READ GROUP_EXECUTE 29WORLD_READ WORLD_EXECUTE ) 30endif () 31 32install ( CODE 33" 34set(_current_dir \"\${CMAKE_INSTALL_PREFIX}/ ${ _install_dir_DESTINATION } \") 35set(_dir_permissions \" ${ _install_dir_DIRECTORY_PERMISSIONS } \") 36 37set(_parent_dirs) 38set(_prev_dir) 39 40# Explicitly prepend DESTDIR when using EXISTS. 41# file(INSTALL ...) implicitly respects DESTDIR, but EXISTS does not. 42while(NOT EXISTS \$ENV{DESTDIR}\${_current_dir} AND NOT \${_prev_dir} STREQUAL \${_current_dir}) 43list(APPEND _parent_dirs \${_current_dir}) 44set(_prev_dir \${_current_dir}) 45get_filename_component(_current_dir \${_current_dir} DIRECTORY) 46endwhile() 47 48if(_parent_dirs) 49list(REVERSE _parent_dirs) 50endif() 51 52# Create any missing folders with the useful permissions. Note: this uses 53# a hidden option of CMake, but it's been shown to work with 2.8.11 thru 54# 3.0.2. 55foreach(_current_dir \${_parent_dirs}) 56if(NOT IS_DIRECTORY \${_current_dir}) 57# file(INSTALL ...) implicitly respects DESTDIR, so there's no need to 58# prepend it here. 59file(INSTALL DESTINATION \${_current_dir} 60TYPE DIRECTORY 61DIR_PERMISSIONS \${_dir_permissions} 62FILES \"\") 63endif() 64endforeach() 65" ) 66endfunction () 67 68# This is to prevent the user's umask from corrupting the expected permissions 69# for the parent directories. We want to behave like the install tool here: 70# preserve what's there already, but create new things with useful permissions. 71function ( install_helper ) 72cmake_parse_arguments ( _install_helper 73"" 74"DESTINATION;DIRECTORY;RENAME" 75"FILES;PROGRAMS;TARGETS;DIRECTORY_PERMISSIONS;FILE_PERMISSIONS" 76${ ARGN } 77) 78 79if ( NOT _install_helper_DESTINATIONAND NOT _install_helper_TARGETS) 80message ( FATAL_ERROR "Must specify the DESTINATION path" ) 81endif () 82 83if ( NOT _install_helper_FILESAND NOT _install_helper_DIRECTORYAND 84NOT _install_helper_PROGRAMSAND NOT _install_helper_TARGETS) 85message ( FATAL_ERROR "Must specify FILES, PROGRAMS, TARGETS, or a DIRECTORY to install" ) 86endif () 87 88if ( NOT _install_helper_DIRECTORY_PERMISSIONS) 89set ( _install_helper_DIRECTORY_PERMISSIONS 90OWNER_READ OWNER_WRITE OWNER_EXECUTE 91GROUP_READ GROUP_EXECUTE 92WORLD_READ WORLD_EXECUTE ) 93endif () 94 95if ( NOT _install_helper_FILE_PERMISSIONS) 96set ( _install_helper_FILE_PERMISSIONS 97OWNER_READ OWNER_WRITE 98GROUP_READ 99WORLD_READ ) 100endif () 101 102if ( NOT _install_helper_PROGRAM_PERMISSIONS) 103set ( _install_helper_PROGRAM_PERMISSIONS 104OWNER_READ OWNER_WRITE OWNER_EXECUTE 105GROUP_READ GROUP_EXECUTE 106WORLD_READ WORLD_EXECUTE ) 107endif () 108 109if ( _install_helper_RENAME) 110set ( RENAME RENAME ${ _install_helper_RENAME }) 111endif () 112 113if ( _install_helper_TARGETS) 114set ( _install_helper_DESTINATION "" ) 115endif () 116 117if ( _install_helper_TARGETS) 118# Ensure the bin area exists with the correct permissions. 119create_install_dir_with_perms ( DESTINATION ${ CMAKE_INSTALL_BINDIR }) 120 121install ( 122TARGETS ${ _install_helper_TARGETS } 123RUNTIME DESTINATION ${ CMAKE_INSTALL_BINDIR }) 124else () 125create_install_dir_with_perms ( 126DESTINATION ${ _install_helper_DESTINATION } 127DIRECTORY_PERMISSIONS ${ _install_helper_DIRECTORY_PERMISSIONS }) 128endif () 129 130if ( _install_helper_DIRECTORY) 131install ( 132DIRECTORY ${ _install_helper_DIRECTORY } 133DESTINATION ${ _install_helper_DESTINATION } 134DIRECTORY_PERMISSIONS ${ _install_helper_DIRECTORY_PERMISSIONS } 135FILE_PERMISSIONS ${ _install_helper_FILE_PERMISSIONS }) 136endif () 137 138if ( _install_helper_FILES) 139install ( 140FILES ${ _install_helper_FILES } 141DESTINATION ${ _install_helper_DESTINATION } 142PERMISSIONS ${ _install_helper_FILE_PERMISSIONS } 143${ RENAME }) 144endif () 145 146if ( _install_helper_PROGRAMS) 147install ( 148PROGRAMS ${ _install_helper_PROGRAMS } 149DESTINATION ${ _install_helper_DESTINATION } 150PERMISSIONS ${ _install_helper_PROGRAM_PERMISSIONS } 151${ RENAME }) 152endif () 153endfunction ()