ARMmbed / ARMmbed/mbed-crypto

Mklink issue when building on Windows

Open
#103 1 comment 0 reactions 0 assignees View on GitHub
Jira status: RESOLVED mirrored type: bug
Dominant language
C
Stars
108
Forks
95
PR merge metrics
No merged PRs in 30d

Description

### Description

When building with CMake on a Win 10 machine, creation of links using mklink (see [CMakeLists.txt](https://github.com/ARMmbed/mbed-crypto/blob/development/CMakeLists.txt#L85)) doesn't always work.

This is a similar issue to https://github.com/ARMmbed/mbedtls/issues/1496 reported for mbed-tls.

The root cause is: cmd.exe does allays only accept `\` as directory separator, but `file(TO_NATIVE_PATH )` is `target host system` specific and under some conditions will return PATHs with `/`.
In addition on some of our machines CMAKE_UNIX_HOST is set while `ln` is not available.
So I suggest checking if `CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows"` is true and to use string manipulation to convert directory separators and drive letters (i.e. `/c/foo/bar` -> `c:\foo\bar` and `/cygdrive/c/foo/bar` -> `c:\foo\bar`).

Howto reproduce:
Assumptions:
1. arm-none-eabi-gcc and gnumake is available on the PATH.
Steps:
1. Start menu -> run -> cmd.exe
2. `cd `
3. `mkdir build; cd build`
4. ` cmake -DCMAKE_C_COMPILER=arm-none-eabi-gcc -DCMAKE_C_COMPILER_WORKS=True -G"Unix Makefiles" ..`

Result:
```
C:\work\mbed-crypto\build>cmake -DCMAKE_C_COMPILER=arm-none-eabi-gcc -DCMAKE_C_COMPILER_WORKS=True -G"Unix Makefiles" ..
-- The C compiler identification is GNU 6.3.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting C compile features
-- Detecting C compile features - failed
-- Found PythonInterp: C:/Program Files/Python36/python.exe (found version "3.6.1")
-- Could NOT find Perl (missing: PERL_EXECUTABLE)
CMake Error at CMakeLists.txt:106 (message):
Could not create symbolic link for: C:/work/mbed-crypto/include/mbedtls -->
Invalid switch - "work".

Call Stack (most recent call first):
include/CMakeLists.txt:20 (link_to_source)

-- Configuring incomplete, errors occurred!
See also "C:/work/mbed-crypto/build/CMakeFiles/CMakeOutput.log".
See also "C:/work/mbed-crypto/build/CMakeFiles/CMakeError.log".

C:\work\mbed-crypto\build>
```

### Issue request type

[ ] Question
[ ] Enhancement
[x] Bug

Contributor guide

Open the contributing guide

Research direction

Start with CMakeLists.txt around line 85 and include/CMakeLists.txt line 20, where link_to_source is used. Reproduce the configuration command on Windows with the Unix Makefiles generator and inspect the generated paths and mklink failure. Done means the project configures successfully and creates the expected symbolic links on the reported Windows setups.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake
Domain
build-system, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.