SCons is a really nice make replacement that allows you to describe your build process in a Python script.
I’ve attached a script that allows SCons to recognize CUDA files and automatically compile and link them correctly with nvcc and gcc. It’s also easy to do common things such as target different builds like emurelease, emudebug, etc.
Here’s an example SCons script that will build the simpleGL example in the SDK:
# create a SCons environment
env = Environment()
# direct SCons to the nvcc.py script
env.Tool('nvcc', toolpath = ['/home/jared/dev/src/cudascons/'])
# add the CUDA SDK include path to the CPPPATH
env.Append(CPPPATH = ['/home/jared/NVIDIA_CUDA_SDK/common/inc'])
# add the CUDA library paths to the LIBPATH
env.Append(LIBPATH Â = ['/home/jared/NVIDIA_CUDA_SDK/lib',
           '/usr/local/cuda/lib'])
# link to glut, glew, the cuda runtime, and the cuda utility libraries
env.Append(LIBS = ['glut', 'GLEW', 'cudart', 'cutil'])
# now create the simpleGL program
env.Program('simpleGL', 'simpleGL.cu')
To try out the example, assuming you have installed the NVIDIA CUDA SDK, download and unzip nvcc.py.zip, putting nvcc.py somewhere in your file system. Next, download SConstruct and put it in the NVIDIA_CUDA_SDK/projects/simpleGL directory. This file serves as a makefile. Edit line #5 of SConstruct to point to the directory containing nvcc.py, and lines #8 & #11 to point to the location of the SDK inc and lib directories.
Next, install SCons. If you are on a Debian-based system like Ubuntu, you can run
sudo apt-get install scons
from the command line to automatically install SCons.
To build simpleGL, run “scons” from the simpleGL directory and it should build in release mode. To build in a different mode, like emudebug, run “scons mode=emudebug”.
nvcc.py assumes CUDA is installed to ‘/usr/local/cuda’. If it is installed in a different location on your system, edit lines 81 & 84 of nvcc.py to point to the appropriate location.
Find out more about SCons here.
Edit: Fixed SharedLibrary bug.
Edit 2: Fixed SharedLibrary bug in SCons v 0.98.1 and higher.
nvcc.py.zip (1.34 KB)
SConstruct.zip (611 Bytes)