check if nvcc is available in makefile

我怕爱的太早我们不能终老 提交于 2019-12-06 04:30:42

This should work, included in your Makefile:

        NVCC_RESULT := $(shell which nvcc 2> NULL)
        NVCC_TEST := $(notdir $(NVCC_RESULT))
ifeq ($(NVCC_TEST),nvcc)
        CC := nvcc
else
        CC := g++
endif
test:
        @echo $(CC)

For GNU make, the recipe line(s) (after test:) actually start with tab characters.

With the above preamble, you can use conditionals based on the CC variable to control the remainder of your Makefile.

You would change the test: target to whatever target you want to be built conditionally.

As a test, just run the above with make. You should get output of nvcc or g++ based on whatever was detected.

You could try a conditional, like

ifeq (($shell which nvcc),) # No 'nvcc' found
func.o: func.c func.h
HEADERS += func.h
else
func.o: cudafunc.cu cudafunc.h
        nvcc -o $@ -c $< . . . 
CFLAGS += -DUSE_CUDA_FUNC
HEADERS += cudafunc.h
endif

And then in the code that will call this function, it can test #if USE_CUDA_FUNC to decide which header to include and which interface to call.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!