Skip to content
New issue

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

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

Already on GitHub? # to your account

Support IAR ARM compiler? #476

Closed
mkitby opened this issue Sep 2, 2019 · 4 comments
Closed

Support IAR ARM compiler? #476

mkitby opened this issue Sep 2, 2019 · 4 comments
Labels
question Further information is requested

Comments

@mkitby
Copy link

mkitby commented Sep 2, 2019

I use CMake and IAR ARM compiler to compile my code for an ARM processor. The CMake generates compile_commands.json and ccls knows the complete command line. I want ccls to support the IAR ARM compiler and can jump to the IAR ARM compiler header files.

The C runtime and compiler header files are installed in ../Config/exec/arm/inc/c, and __ICCARM__ is an internal preprocessor defined by the IAR ARM compiler.

Here is my .ccls file,

%compile_commands.json
-target
arm
-D__ICCARM__
-I../Config/exec/arm/inc/c

Now the problem is why macro __GNUC__ is defined with -target arm? If I remove -target arm in .ccls, then macro _MSC_VER will be defined. Is there a -target support the IAR ARM compiler? If no, how to set the configuration to not define any compiler macro like _MSC_VER and __GNUC__

@MaskRay
Copy link
Owner

MaskRay commented Sep 3, 2019

ccls is a clang based tool. It reuses clangDriver, clangLex, clangParse, clangSema, etc. The predefined macros are provided by the driver. According to the target triple and some command line options, the compiler supplies a set of predefined macros.

__GNUC__ is by default defined by clang unless MSVC compatibility is enabled. I don't think -fms-compatibility is what you desire, so you should probably use -U__GNUC__ to undefine the macro.

% clang -target armv7-linux-gnueabi -E -dM -xc /dev/null | grep GNUC              
#define __GNUC_MINOR__ 2
#define __GNUC_PATCHLEVEL__ 1
#define __GNUC_STDC_INLINE__ 1
#define __GNUC__ 4
% clang -target armv7-linux-gnueabi -E -dM -xc /dev/null -fms-compatibility | grep GNUC
% clang -target armv7-linux-gnueabi -E -dM -xc /dev/null -U __GNUC__ | grep GNUC  
#define __GNUC_MINOR__ 2
#define __GNUC_PATCHLEVEL__ 1
#define __GNUC_STDC_INLINE__ 1

You need to check what other macros your project detects and undefine them. An example .ccls:

%compile_commands.json
-target
armv7-linux-gnueabi
-D__ICCARM__
-U__GNUC__
-U__clang__
-isystem../Config/exec/arm/inc/c

@MaskRay MaskRay closed this as completed Sep 3, 2019
@MaskRay MaskRay added the question Further information is requested label Sep 3, 2019
@mkitby
Copy link
Author

mkitby commented Sep 3, 2019

Thanks for your help, it works.

@davidanderle
Copy link

@mkitby I wonder if you somehow managed to convert IAR .ewp files to CMake format automatically, or you just created the CMake by hand?

@mkitby
Copy link
Author

mkitby commented Oct 13, 2019

I created CMake by hand

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants