# cmake does not follow symlinks on windows

**URL:** <https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [June 4, 2020, 11:02am UTC](https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322 "2020-06-04T11:02:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephan268](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@Stephan268](https://discourse.cmake.org/u/Stephan268)\
**Post date:** [June 4, 2020, 11:02am UTC](https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322/1 "2020-06-04T11:02:06Z")

</div>

```
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)?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [June 4, 2020, 12:45pm UTC](https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322/2 "2020-06-04T12:45:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stephan268](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@Stephan268](https://discourse.cmake.org/u/Stephan268)\
**Post date:** [June 4, 2020, 1:05pm UTC](https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322/3 "2020-06-04T13:05:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [June 4, 2020, 1:06pm UTC](https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322/4 "2020-06-04T13:06:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stephan268](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@Stephan268](https://discourse.cmake.org/u/Stephan268)\
**Post date:** [June 4, 2020, 1:12pm UTC](https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322/5 "2020-06-04T13:12:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stephan268](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@Stephan268](https://discourse.cmake.org/u/Stephan268)\
**Post date:** [June 4, 2020, 1:22pm UTC](https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322/6 "2020-06-04T13:22:43Z")

</div>

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;

```

}

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [June 4, 2020, 1:41pm UTC](https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322/7 "2020-06-04T13:41:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Stephan268](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@Stephan268](https://discourse.cmake.org/u/Stephan268)\
**Post date:** [June 4, 2020, 1:54pm UTC](https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322/8 "2020-06-04T13:54:19Z")

</div>

> [@ben.boeckel](#):
>
> 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/](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.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [June 4, 2020, 5:04pm UTC](https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322/9 "2020-06-04T17:04:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stephan268](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@Stephan268](https://discourse.cmake.org/u/Stephan268)\
**Post date:** [June 4, 2020, 5:20pm UTC](https://discourse.cmake.org/t/cmake-does-not-follow-symlinks-on-windows/1322/10 "2020-06-04T17:20:33Z")

</div>

> [@ben.boeckel](#):
>
> They don’t really work well as tourists

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.
