[CMake] cmake -E create_symlink for Windows

Michael Wild themiwi at gmail.com
Fri Dec 11 10:04:27 EST 2009


On 11. Dec, 2009, at 15:35 , Hendrik Sattler wrote:

> Zitat von Michael Wild <themiwi at gmail.com>:
>> On 11. Dec, 2009, at 15:17 , Hendrik Sattler wrote:
>>> Zitat von Michael Wild <themiwi at gmail.com>:
>>>> On 11. Dec, 2009, at 14:27 , Marcel Loose wrote:
>>>>> I was browsing the CMake sources for a problem I was facing with the
>>>>> creation of symlinks (on Unix that is) and I noticed that the
>>>>> SystemTools::CreateSymlink function simply returns false when building
>>>>> on a Windows platform.
>>>>> 
>>>>> Does that mean that I cannot use 'cmake -E create_symlink' on Windows.
>>>>> If that's the case I consider it a bug, because the documentation
>>>>> suggests that 'cmake -E create_symlink' provides a platform independent
>>>>> way of creating symbolic links. So, if the OS and/or filesystem does not
>>>>> support symbolic links, IMHO, it should just copy the file.
>>>> 
>>>> Simply copying the file might be just as bad if people assume it   really IS a symlink... IMHO, if the OS can't create a symlink,  cmake  -E create_symlink should fail loudly, not just silently  ignore it.  And somebody should implement this function for  Windows >=  Vista/2008 (i.e. WINVER >= 0x0600):
>>>> 
>>>> http://msdn.microsoft.com/en-us/library/aa363866(VS.85).aspx
>>> 
>>> For this, also see
>>> http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html
>>> Please note the UAC dialog when creating symlink on Vista. Have  fun, I'd say :-(
>>> 
>>> And what do you do on WindowsXP? What to do on FAT filesystems?
>>> Additionally, without that extension above, it is non-obvious for  Windows users that a specific file is a symbolic link.
>> 
>> The UAC-thing only applies to directories where the user has no  write-acces (including the admin), right? So if you're half-way  sane, and build in a user-owned directory, you should be UAC-free...
> 
> To cite from that page:
> Vista and UAC
> 
> One of the major Vista changes was the so called User Account Control (UAC). Due to UAC some API calls need elevation to administrative level, and this elevation must be acknowledged via the below shown dialog box. Unfortunately, and I still can't believe this, the API call CreateSymbolicLink is a call, which needs elevation, and thus causes this annoying dialog box come up every time a symbolic link is created.
> 

Bummer. What where they THINKING??? (if at all...). It seems to me that M$ just CAN'T get it right. No matter how many times they try, how many good examples are out there, they always manage to seriously screw something up... Come to think of it, they probably were thinking about symlink-attacks...

> 
> So, no, every time, even on own directories. I don't currently use Vista or Windows7, though. Also read the rest of that part of the page: cmake should not use functions directly that need elevation.
> 

Agreed, but then creating symlinks will be just plain impossible on Windows...

For the general interest: somebody did it for 4msysgit.

http://repo.or.cz/w/git/mingw/4msysgit.git/commitdiff/043a43e7ec1ca4aa492406f438d89e1f35df127a

Michael



More information about the CMake mailing list