cmake does not follow symlinks on windows

get_filename_component(... REALPATH)

and

file (INSTALL ...  DESTINATION ...  USE_SOURCE_PERMISSIONS FOLLOW_SYMLINK_CHAIN)

do not process symbolic links on windows.

Is this a known problem (cmake 3.17.2)?

It looks like the codepath should handle it, but where it falls down would need investigation.

To be precise: I did the build in cygwin. The symlinks however are Windows symlinks and not cygwin symlinks.

Ah, that’s probably the problem. Cygwin is a different platform than Windows and expects Unix-like symlinks.

The symlinks are windows symlinks and cygwin can follow them. This works for cygwin bash and own programs.

We are working around the problem with an external tool “read_symlink” that we call from with CMakeLists.txt. The code uses boost.

// resolves symbolic links. 
// compile this and install it on $PATH
// cl read_symlink.cpp /I\usr\local64\packages\libraries\boost_1_60_0_a\include /O2 /EHsc /MD /DBOOST_ALL_DYN_LINK=0 /link /LIBPATH:\usr\local64_vs2015\packages\libraries\boost_1_60_0_a\lib

int main(int argc, char* argv[])
{
  for(int i=1; i < argc; ++i){
    boost::filesystem::path ph_in(argv[i]);
  try{
    boost::filesystem::path const ph_out(boost::filesystem::read_symlink(ph_in));
    if(ph_out.empty()){
      std::cout << ph_in.string() << std::endl;
    }
    else{
      std::cout << ph_out.string() << std::endl;
    }
  }
  catch(...){
    std::cout << ph_in.string() << std::endl;
  }
}

return 0;

}

If they don’t respond to readlink under Cygwin, there’s not much CMake does about it. The platform is treated as Unix pretty much everywhere within CMake and no Win32 calls are made from that build of CMake.

Understood. The cmake installation that I am using is a Windows build downloaded from https://cmake.org/download/

When redesigning our build system to use cmake I was torn in how to treat the cygwin platform on multiple occasions. The hardliner in me said that cygwin is an attempt to emulate POSIX so treat it as POSIX. The softy in me said that developers that have ever used Unix will usually touch a windows box only if it has the usual unix tools. In order to support them I now treat cygwin as windows with some rare posix goodies. Example: On cygwin bourne shell scripts are generated in addition to windows bat scripts. This allows developers to call scripts using the same name on windows command and bash prompt.

There are two different builds of CMake for Windows and Cygwin. They don’t really work well as tourists :slight_smile: .

In that case I was pretty lucky so far. I hope that covid-19 and restrictions in tourism does not make the situation worse. Thanks for all your help and your dedication to cmake.

1 Like