[CMake] header files with visual studio

Michael Jackson mike.jackson at bluequartz.net
Mon Nov 15 12:56:18 EST 2010


On Nov 15, 2010, at 12:29 PM, Oliver kfsone Smith wrote:

> Michael Jackson said the following on 11/15/2010 9:33 AM:
>>
>> I have been casually following this thread and I understand the OPs  
>> hesitation when trying to add thousands of files into a CMake build  
>> system but what I think one needs to think about is that you are  
>> only going to add the files ONCE for the project. After that the  
>> CMake files are correctly created and any other additions are in  
>> the form of only a few files at a time during the course of normal  
>> development. What I end up doing in the cases where this happened  
>> to me was to create my CMake files and figure out what needs to  
>> added to a CMake file and the syntax that it needs to be added in.  
>> Then a one off shell script (or pick your favorite language) is  
>> created to look at the project, get a list of files needed, then  
>> "generate" a CMake file that can be incorporated into your project.  
>> After that is done the shell script is no longer needed because you  
>> have your CMake files and you will not need your dependency  
>> analysis tool because CMake and/or Visual Studio will have what it  
>> needs.
>>
>> You can place the CMake code in files called "Sources.cmake" in  
>> each source directory then have your higher level CMake files  
>> simply "include" Sources.cmake for each project. Yes there is  
>> development time for this but the shell script does not have to be  
>> pretty or efficient. It is only going to be run once to generate  
>> the cmake files.
> Ah - you've kind of both missed the nuance.
>
> The very last thing I want is one singular header list. Infact, the  
> header lists for any given project will be relatively small  
> (potentially hundreds of headers, but not thousands).
>
> The scanner only has to search the source files listed under "+  
> Sources" for each project and only has to include the resulting  
> headers. The lists are thus likely to be relatively small and pretty  
> easily generated.
>
> The result would be
>
> +- Solution
> |  +- Target 1
> |  |  +- Sources
> |  |  +- Headers
> |  +- Target 2
> |  |  +- Sources
> |  |  +- Headers
> ...
>
> instead of
>
> +- Solutions
> |  +- Target 1
> |  |  +- Sources
> |  +- Target 2
> |  |  +- Sources
> |  +- Target 3
> |  |  +- Sources
> ...
>
> Caveat: a header may appear under more than one target for a given  
> CMakeLists/solution/cbp file, but that's ok.
>
>
> - Oliver
>


Ahh. It is a bit clearer the tract you are taking. What I am  
suggesting is that you only have to run the "scanner" once and keep  
the results in CMake syntax files so that CMake can just simply re-use  
the list. As you add headers during development you can add headers to  
the lists that were generated. It is the first big lump of headers  
which is the daunting task. After that general maintenance of the  
CMake files is simple and straight forward.

For example in the folder:

+- Solution
|  +- Target 1
|  |  +- Sources
|  |  +- Headers
you can have a file Headers.cmake which contains

set (TARGET_1_HEADERS foo.h bar.h other.h)

which can be generated once by a script. And in the CMakelists.txt  
file for Target 1 you can have:
include (Headers/Headers.cmake)

Just an idea.
___________________________________________________________
Mike Jackson                      www.bluequartz.net



More information about the CMake mailing list