From 2362ee08ed6979f213827a8448106e5d5e5331bc Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Thu, 21 Jan 2021 12:37:28 +0000 Subject: [PATCH] BF,RF: Fix linux CFLAGS default assignment. Always add -fPIC on all platforms. For NVCC, use same variable naming conventions as used in conda-forge build env. Use -ccbin rather than --compiler-bindir (they are equivalent), as the conda-forge nvcc wrapper only checks for the former. Fix path to supportedGencodes.sh script. --- config/buildSettings.mk | 48 +++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/config/buildSettings.mk b/config/buildSettings.mk index f4334e7..9f5874b 100644 --- a/config/buildSettings.mk +++ b/config/buildSettings.mk @@ -39,10 +39,10 @@ TCLSH ?= ${FSLDIR}/bin/fsltclsh # environment. # Compiler flags for C projects -ARCHCFLAGS = -std=c99 +ARCHCFLAGS = -std=c99 -fPIC # Compiler flags for C++ projects. -ARCHCXXFLAGS = -std=c++11 +ARCHCXXFLAGS = -std=c++11 -fPIC # Preprocesor flags for C/C++ projects. ARCHCPPFLAGS = @@ -54,9 +54,11 @@ ARCHLDFLAGS = ARCHLIBS = # Compiler flags for CUDA projects. +# This is set in the nvcc block below. ARCHNVCCFLAGS = # Linker flags for CUDA projects. +# This is set in the nvcc block below. ARCHNVCCLDFLAGS = # Allow flags to be provided by the environment. @@ -77,8 +79,8 @@ ifeq ($(SYSTYPE), Darwin) # LDFLAGS may be overridden by the environment. CC ?= clang CXX ?= clang++ - CFLAGS ?= -arch x86_64 -Wall -pedantic -fPIC - CXXFLAGS ?= -arch x86_64 -Wall -pedantic -fPIC + CFLAGS ?= -arch x86_64 -Wall -pedantic + CXXFLAGS ?= -arch x86_64 -Wall -pedantic LDFLAGS ?= -Wl,-search_paths_first ARCHLIBS += -llapack -lblas -lz -lm endif @@ -95,8 +97,9 @@ ifeq ($(SYSTYPE), Linux) CC ?= gcc CXX ?= g++ CFLAGS ?= -fexpensive-optimizations \ - -Wall -pedantic -Wno-long-long -fPIC + -Wall -pedantic -Wno-long-long CXXFLAGS ?= -fexpensive-optimizations \ + -Wall -pedantic -Wno-long-long LDFLAGS ?= -Wl,-rpath,'$$ORIGIN/../lib' ARCHLIBS += -lopenblas -lz -lm endif # if Linux @@ -110,10 +113,15 @@ endif # if Linux # CUDA/nvcc compiler options ifneq ($(shell which nvcc), ) + # We specifically use variable names "CUDA_VER" + # and "CUDA_HOME" because they will be set in + # the conda-forge CUDA build environment (and + # will take precedence over these definitions + # here when they are set). NVCC ?= nvcc - CUDAVER ?= $(shell nvcc --version | grep -Po "release \K[0-9\.]+") - GENCODEFLAGS ?= $(shell ${FSLCONFDIR}/common/supportedGencodes.sh ${CUDAVER}) - CUDADIR ?= ${FSLDIR} + CUDA_HOME ?= ${FSLDIR} + CUDA_VER ?= $(shell nvcc --version | grep -Po "release \K[0-9\.]+") + GENCODEFLAGS ?= $(shell ${FSLCONFDIR}/supportedGencodes.sh ${CUDA_VER}) # nvcc-specific tweaks: # - Define ARMA_ALLOW_FAKE_GCC, otherwise byte-alignment issues @@ -122,16 +130,18 @@ ifneq ($(shell which nvcc), ) # - Do not use -pedantic, otherwise *every single line* of # transpiled cuda code will trigger "warning: style of line # directive is a GCC extension". - # - Specify the compiler to use with --compiler-bindir, as nvcc - # might otherwise naively call "gcc" - ARCHNVCCFLAGS = -I${CUDADIR}/include \ - -maxrregcount=64 \ - ${GENCODEFLAGS} \ - -DARMA_ALLOW_FAKE_GCC \ - --compiler-bindir \ - $(shell which $(CC)) \ - --compiler-options \ + # - Specify the compiler to use with -ccbin, as nvcc + # might otherwise naively call "gcc" (we specifically use + # "-ccbin" rather than "--compiler-bindir" here, because the + # conda-forge nvcc wrapper checks for -ccbin, and adds its own + # if not present). + ARCHNVCCFLAGS = -I${CUDA_HOME}/include \ + -maxrregcount=64 \ + ${GENCODEFLAGS} \ + -DARMA_ALLOW_FAKE_GCC \ + -ccbin $(CXX) \ + --compiler-options \ "$(filter-out -pedantic, ${ARCHCXXFLAGS})" - ARCHNVCCLDFLAGS = -L${CUDADIR}/lib \ - -L${CUDADIR}/lib/stubs + ARCHNVCCLDFLAGS = -L${CUDA_HOME}/lib \ + -L${CUDA_HOME}/lib/stubs endif -- GitLab