[CMake] Header files excluded from build in Visual Studio

Claus Höfele claus at claushoefele.com
Sun Mar 15 21:51:22 EDT 2009


> What is the default if you have VS create the project?

When adding a new header file 'asd.h', this is what Visual Studio
writes into the project file:
<Filter
  ...
  >
  <File
    RelativePath=".\asd.h"
    >
  </File>
  ...
</Filter>

Properties as displayed by the properties page are "Excluded from
Build: No" and "Tool: Custom Build Tool."

When you manually set the file to Custom Build Tool, the project file
also contains a <FileConfiguration> tag, but this seems to be
optional.

> http://public.kitware.com/Bug/view.php?id=7845

It looks to me that neither .h nor .idl should be excluded from build
by default. Instead, it should be possible to override this behaviour
by setting a flag.

-Claus




On Sat, Mar 14, 2009 at 12:46 AM, Bill Hoffman <bill.hoffman at kitware.com> wrote:
> Claus Höfele wrote:
>>
>> Thanks for the quick replies.
>>
>> I'm using cmake 2.6.3 + Visual Studio 8 2005 SP1
>>
>> Playing around further with the file properties in Visual Studio, it
>> looks like VS only checks the syntax of a file if the Tool property is
>> set to C/C++ Compiler Tool. However, this setting will cause the
>> header file to be compiled, which is obviously not what you want.
>>
>> So the setting for a header file should be:
>> 1.) Excluded From Build: No
>> 2.) Tool: Custom Build Tool
>>
>> 2.) is already done, 1.) is not.
>>
>> For my purposes, it was enough to change cmSourceFile::CheckExtension()
>> like so:
>>
>>  // Look for header files.
>>  if ...
>>  else
>>    {
>>    // This is a known header file extension.  The source cannot be
>> compiled.
>>    if(!this->GetProperty("HEADER_FILE_ONLY"))
>>      {
>>      this->SetProperty("HEADER_FILE_ONLY", "1");
>>      }
>>    }
>>
>> This allows me to override the HEADER_FILE_ONLY setting to false in my
>> CMakeLists.txt and produces the project files I want.
>>
>> Would be great if a similar fix would make it into the next release.
>>
>
> What is the default if you have VS create the project?  BTW, this all came
> from this bug fix:
> http://public.kitware.com/Bug/view.php?id=7845
>
> I am not sure you want to make that false in your file, as the makefile
> generator may then try and compile it.  CMake should handle a .h file
> without having to change anything.
>
> -Bill
>
>


More information about the CMake mailing list