1

I configured clangd using nvim-lspconfig. Now I would like to enable AVX support for certain projects in Linux.

How can I detect OS type in .clangd file, and then add -mavx flag only when it is Linux?

CompileFlags:
  Add: [-xavx]
chenzhongpu
  • 6,193
  • 8
  • 41
  • 79

1 Answers1

1

I think it would be good to do that by leveraging an external script or a build system which is able to detect OS and construct if. As for Makefile:

arch := $(shell uname -m)

ifeq ($(arch), arm64)
define CLANG_FLAGS
CompileFlags:
    Add: [-Wall]
endef
else
define CLANG_FLAGS
CompileFlags:
    Add: [-Wall, -mavx]
endef
endif

config:
    @$(file > .clangd,$(CLANG_FLAGS))

To generate an OS-specific .clangd, just run make config.

chenzhongpu
  • 6,193
  • 8
  • 41
  • 79