How to put CUDA rules file into the source code?

I have a Visual Studio 2008 application in which I want to make CUDA rules and CUDA libraries portable, so they are carried along with the source code and selectable or not according to the Visual Studio build configuration for the project. I have done this with other runtime libraries such as Visual Studio 2008 redistributable by keeping copies of libraries local to the source code folders. I can’t figure out how to do this with the CUDA rules file.

My problem is that Visual Studio requires that I specify a search path for rules files befor it will recognize and apply them. There is a default search path for rules files, which in my case is:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\VCProjectDefaults

And I can add additional search paths for rules using the Visual Studio menu selections Tools | Options | VC++ Project Settings | Rule File Search Paths. For example, I might specify

F:\VC++ Projects\code_version_1

The problem with the above is that the path is an absolute path. I cannot figure out how to make it a relative path, relative to the source code for the project. If I want to create code_version_2, I need to keep referring to the old path (F:\VC++ Projects\code_version_1) or else change my Visual Studio search path for each new code version. What I would like to do is have the rules carried along with the source automatically by specifying a path relative to the root of the source code. Specifically, I tried using $(SolutionDir), which works for the compiler and linker settings, but it does not work for the CUDA rules.

Another approach might be to ask all persons who might want to build the code to put the rules file in a standard directory such as C:\CUDA_rules. This presents a configuration management issue unless you rename the rules file for each code version, which would be a hassle.

The root reason for all this is that I want to share the source code with others and to allow these other people to have a different CUDA installation or none at all. In this way, someone who does not have CUDA toolkit installed could build project configurations (there are several) that do not use CUDA. For those who do use CUDA, having the rules local to the source would make the source code responsible for fixing the CUDA version and libraries, not leaving it to the users installation, which could present compatibility problems.

As it stands, if a user does not have a CUDA toolkit installation, he cannot even open the code project in the Visual Studio IDE because it complains that it can’t find the rules file. Putting the rules file relative to the source would make sure it is always there.

Does anyone know how to do this?

It never fails. Posting a question gives you new insight.

Inspection of the VCPROJ file disclosed an empty section

<\ToolFiles>

I did a Google search and found nothing useful about ToolFiles other than complaints about lack of documentation. So, I started experimenting with syntax, knowing nothing about it. By trial and error I found that the following syntax was able to reference the relative path of a rules file:

<ToolFiles>
	<ToolFile
		RelativePath="Recon_NvCudaRuntimeApi.rules"
	/>
</ToolFiles>

The path is relative to the root solution directory $(SolutionDir), which is not mentioned. Visual Studio knows where it is and fills in the rest of the path. The name of the .rules file is my own. In addition to the above, I removed the checkbox from the default CUDA rules file. This results in loading my custom rules file (and no other) and checking its checkbox in the custom build rules pulldown menu. With this, the CUDA build, using .cu files in the source, works just fine.

The above custom rules file is a copy of the one installed by the CUDA toolkit in the default directory. Now I can edit my custom rules file without affecting the original, and it is carried along with the source code as desired.