Windows-Clang platform adds -fPIC for shared dlls

Hello. I am compiling on linux host using clang-12 and CMAKE_SYSTEM_NAME Windows-Clang in my toolchain file. I have studied the Modules/Platform/Windows-Clang.cmake which makes a decission on choosing msvc/gnu variant basing on CMAKE_C_SIMULATE_ID and CMAKE_CXX_SIMULATE_ID variables. Setting them to “MSVC” makes the static libs and executables build succefully EXCEPT for dlls, with error

clang-12: unsupported option '-fPIC' for target i386-pc-windows-msvc

But the thing is this flag is not being set anywhere… there even are comments in the Windows toolchains:

Windows-Clang.cmake:37:  # No -fPIC on Windows
Windows-GNU.cmake:68:  # No -fPIC on Windows

So where does this -fPIC come from??
For now it is enough to sed after cmake project files generation to remove this flag from compile line and entire projects builds and runs.

Position Independent Code (PIC) is enabled by default for SHARED libraries. You can set CMAKE_POSITION_INDEPENDENT_CODE to False in order to disable that behavior.

That was it! :slight_smile:

That sounds like more like a hack, not like a solution.

The CMAKE_SYSTEM_NAME should be Windows, not Windows-Clang.

You may be right but I’ve went through so much of steps i do not remember what exactly was wrong with WIndows. I think it was assumming mingw ABI/commandline which is incompatible with clang, but i dont have will to dig right now.