Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CMake on Windows with Clang and MinGW headers #712

Open
papadokolos opened this issue Jul 21, 2020 · 4 comments
Open

Support CMake on Windows with Clang and MinGW headers #712

papadokolos opened this issue Jul 21, 2020 · 4 comments

Comments

@papadokolos
Copy link
Contributor

System info:

  • Sublime Text version: Version 3.2.2, Build 3211
  • Which system are you on: Windows 7 64 bit
  • Clang version: 10.0.0
  • gcc version : 8.1.0 (i686-posix-dwarf-rev0, Built by MinGW-W64 project)

What happens:

I want to use EasyClangComplete for a CMake based project on Windows.
My goal is to use Clang compiler with MinGW (mingw-w64) headers.

In order to achieve that, I had to fulfill the following requirements:

  1. Clang should get the flag -target i686-pc-windows-gnu when compiling.
  2. CMake should get the flags -DCMAKE_CXX_COMPILER=clang++, -DCMAKE_CXX_FLAGS="-target i686-pc-windows-gnu" and -G "MinGW Makefiles" when executed.
  3. EasyClangComplete needs to add support for two things:
    • Parsing a UNC (non posix) path in the generated compilation database
    • Treat -target as a flag

My current approach - Internal modifications

I successfully got it working by making the following modifications to EasyClangComplete's source code.

Diff view

EasyClangComplete CMake Clang on MinGW Windows

Example compile_commands.json

Here is an example for such a generated compilation database:
[
{
  "directory": "C:/Users/Secret/AppData/Local/Temp/EasyClangComplete/cmake_builds/afeee6ac216a4e3cad7a41f5cf6958c1",
  "command": "C:\\PROGRA~1\\LLVM\\bin\\CLANG_~1.EXE    -target i686-pc-windows-gnu -g   -Wall -Wextra -Wpedantic -Werror -std=c++14 -o CMakeFiles\\space-age.dir\\space_age_test.cpp.obj -c C:\\Users\\Secret\\Exercism\\cpp\\space-age\\space_age_test.cpp",
  "file": "C:/Users/Secret/Exercism/cpp/space-age/space_age_test.cpp"
},
{
  "directory": "C:/Users/Secret/AppData/Local/Temp/EasyClangComplete/cmake_builds/afeee6ac216a4e3cad7a41f5cf6958c1",
  "command": "C:\\PROGRA~1\\LLVM\\bin\\CLANG_~1.EXE    -target i686-pc-windows-gnu -g   -Wall -Wextra -Wpedantic -Werror -std=c++14 -o CMakeFiles\\space-age.dir\\space_age.cpp.obj -c C:\\Users\\Secret\\Exercism\\cpp\\space-age\\space_age.cpp",
  "file": "C:/Users/Secret/Exercism/cpp/space-age/space_age.cpp"
},
{
  "directory": "C:/Users/Secret/AppData/Local/Temp/EasyClangComplete/cmake_builds/afeee6ac216a4e3cad7a41f5cf6958c1",
  "command": "C:\\PROGRA~1\\LLVM\\bin\\CLANG_~1.EXE    -target i686-pc-windows-gnu -g   -Wall -Wextra -Wpedantic -Werror -std=c++14 -o CMakeFiles\\space-age.dir\\test\\tests-main.cpp.obj -c C:\\Users\\Secret\\Exercism\\cpp\\space-age\\test\\tests-main.cpp",
  "file": "C:/Users/Secret/Exercism/cpp/space-age/test/tests-main.cpp"
}
]

Reaching out for help:

I would love to hear your opinion. How would you implement support for this?
I might be able to make a PR for this myself, but first I would like to get an idea of how big is this task 😉

@niosus
Copy link
Owner

niosus commented Jul 24, 2020

From your changes the only non-trivial one is the change to posix in the shlex. All the others, you can already pass to cmake, see flag_sources in the documentation. I am also a bit unsure what adding -target gets you. The flags there are the flags that clang supports, are you sure this change is necessary?

@papadokolos
Copy link
Contributor Author

Thanks for the tip on flag_sources! 😄

shlex

Regarding shlex, would it be appropriate to make the posix boolean value determined by the condition sys,platform != "wind32"?

image

-target

I need -target to be recognized as a flag by ECC, otherwise it isn't being passed to Clang compiler. Adding -target to SEPARABLE_PREFIXES makes it work (perhaps there is a better way?).

From the comment above SEPARABLE_PREFIXES:

# Generated from clang -help with regex: ([-/][\w-]+)\s<\w+>\s
SEPARABLE_PREFIXES = set([

When I execute clang -help, I get a long list of flags, including -target. The list is considerabely larger than SEPARABLE_PREFIXES. So it seems that many clang flags are missing. Also, applying the provided regex pattern on clang -help output yields inaccurate results, at least within Sublime Find (with regex enabled).

image

@stale
Copy link

stale bot commented Jan 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Just comment here to prevent this from happening.

@stale stale bot added the wontfix label Jan 8, 2022
@niosus
Copy link
Owner

niosus commented Jan 10, 2022

This seems to be an easy fix, I think I'll be able to look into this soon. Ping.

@stale stale bot removed the wontfix label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants