[CMake] Visual Studio 2005: Make header files without corresponding source files viewable in the solution explorer

Marcus yhadin002 at sneakemail.com
Fri Nov 30 16:55:27 EST 2007


Dear Peter,  (sorry if you receive two copies of this)

> I have some header files containing only template code which I would 
> like to see in the solution explorer. They are not logically associated 
> with any libraries or executables in my project.

I am also new to CMake, but as I understand it, the only way to do this
is to associate the files with some sort of build target or action.
This is a limitation of Visual Studio, rather than CMake.

The way I have solved this is to create a unit test suite to accompany
each of my libraries, and I compile a separate 'test runner' executable
for every suite.  This means that when my library consists only of
header files, I can associate the headers with the corresponding test
runner.  The headers will then appear as a 'test project' in Visual Studio.

For example, when I build a shared library, I will have two projects in
Visual Studio:

MySharedLibrary <- This project compiles the dll, and includes all of
the source files

MySharedLibrary_TEST <- This project compiles the test runner, and
contains only test code


But when my library consists only of header files, I will see a single
test project in Visual Studio:

MyHeaderLibrary_TEST <- This project compiles the test runner, and
contains both the library's header files and the test code.


> I would also like to 
> simply link to some Perl test scripts in the solution explorer in their 
> own project or so.

I recommend looking at ADD_CUSTOM_COMMAND or ADD_CUSTOM_TARGET.

Marcus


More information about the CMake mailing list