Skip to content

Commit 2cb6106

Browse files
committed
Added a check for Apple gcc/clang with OpenMP. Also checking that CC is a valid compiler
1 parent 2ff3b95 commit 2cb6106

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

common.mk

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ endif
4545
# Now check if gcc is set to be the compiler but if clang is really under the hood.
4646
export CC_IS_CLANG ?= -1
4747
ifeq ($(CC_IS_CLANG), -1)
48-
CC_VERSION := $(shell $(CC) --version)
48+
CC_VERSION := $(shell $(CC) --version 2>/dev/null)
49+
ifndef CC_VERSION
50+
$(error $(ccred)Could not find $$CC = ${CC}$(ccreset))
51+
endif
4952
ifeq (clang,$(findstring clang,$(CC_VERSION)))
5053
export CC_IS_CLANG := 1
5154
else
@@ -122,18 +125,23 @@ else ## not icc -> gcc or clang follow
122125
CFLAGS += -funroll-loops
123126
ifeq (USE_OMP,$(findstring USE_OMP,$(OPT)))
124127
ifeq (clang-omp,$(findstring clang-omp,$(CC)))
125-
CLANG_OMP_AVAIL :=true
128+
CLANG_OMP_AVAIL:=true
126129
else
127-
## Need to do a version check clang >= 3.7 supports OpenMP. If it is Apple clang, then it doesn't support OpenMP.
128-
## All of the version checks go here. If OpenMP is supported, update CLANG_OMP_AVAIL to 1.
129-
CLANG_VERSION_FULL := $(shell $(CC) --version | grep version | grep -oP '(?<=version )\S+')
130-
CLANG_VERSION_FULL := $(subst ., ,$(CLANG_VERSION_FULL))
131-
CLANG_VERSION_MAJOR := $(word 1,${CLANG_VERSION_FULL})
132-
CLANG_VERSION_MINOR := $(word 2,${CLANG_VERSION_FULL})
133-
CLANG_MAJOR_MIN_OPENMP := 3
134-
CLANG_MINOR_MIN_OPENMP := 7
135-
CLANG_OMP_AVAIL := $(shell [ $(CLANG_VERSION_MAJOR) -gt $(CLANG_MAJOR_MIN_OPENMP) -o \( $(CLANG_VERSION_MAJOR) -eq $(CLANG_MAJOR_MIN_OPENMP) -a $(CLANG_VERSION_MINOR) -ge $(CLANG_MINOR_MIN_OPENMP) \) ] && echo true)
136-
endif
130+
# Apple clang/gcc does not support OpenMP
131+
ifeq (Apple, $(findstring Apple, $(CC_VERSION)))
132+
CLANG_OMP_AVAIL:= false
133+
else
134+
## Need to do a version check clang >= 3.7 supports OpenMP. If it is Apple clang, then it doesn't support OpenMP.
135+
## All of the version checks go here. If OpenMP is supported, update CLANG_OMP_AVAIL to 1.
136+
CLANG_VERSION_FULL := $(shell $(CC) --version | grep version | grep -oP '(?<=version )\S+')
137+
CLANG_VERSION_FULL := $(subst ., ,$(CLANG_VERSION_FULL))
138+
CLANG_VERSION_MAJOR := $(word 1,${CLANG_VERSION_FULL})
139+
CLANG_VERSION_MINOR := $(word 2,${CLANG_VERSION_FULL})
140+
CLANG_MAJOR_MIN_OPENMP := 3
141+
CLANG_MINOR_MIN_OPENMP := 7
142+
CLANG_OMP_AVAIL := $(shell [ $(CLANG_VERSION_MAJOR) -gt $(CLANG_MAJOR_MIN_OPENMP) -o \( $(CLANG_VERSION_MAJOR) -eq $(CLANG_MAJOR_MIN_OPENMP) -a $(CLANG_VERSION_MINOR) -ge $(CLANG_MINOR_MIN_OPENMP) \) ] && echo true)
143+
endif #Apple check
144+
endif #clang-omp check
137145

138146
ifeq ($(CLANG_OMP_AVAIL),true)
139147
CFLAGS += -fopenmp=libomp
@@ -143,7 +151,7 @@ else ## not icc -> gcc or clang follow
143151
# be visible if the entire codebase is being compiled.
144152
# export WARNING_PRINTED ?= 0
145153
# ifeq ($(WARNING_PRINTED), 0)
146-
$(warning $(ccmagenta)clang does not support OpenMP - please use gcc/icc for compiling with openmp. Removing USE_OMP from compile options. $(ccreset))
154+
$(warning $(ccmagenta) $$CC = ${CC} does not support OpenMP - please use gcc/icc for compiling with openmp. Removing USE_OMP from compile options. $(ccreset))
147155
infovar := "OPT:=$$(filter-out -DUSE_OMP,$$(OPT))"
148156
$(info $(ccmagenta)If you are sure your version of clang ($(ccblue) must be >= 3.7, NOT Apple clang $(ccmagenta)) does support OpenMP, then comment out the line $(ccred) $(infovar) $(ccmagenta) in the file $(ccgreen)"common.mk"$(ccreset))
149157
# export WARNING_PRINTED := 1

0 commit comments

Comments
 (0)