c++visual-studio-2010custom-build-stepodb

Visual Studio custom build event always executing


I am using the odb compiler as a custom build tool. The build tool is always executing even though the input file is not changing.

The command line:

odb -Ic:\menuplan\src\ingredient -o c:\menuplan\src\ingredient  
 -d mysql --hxx-prologue "#include \"odb/traits.hxx\"" --generate-query  
--generate-schema --schema-format separate 
c:\menuplan\src\ingredient\ing_odb_category.hpp`  

The input file is:
ing_odb_category.hpp.

The outputs:

ing_odb_category-odb.hxx;ing_odb_category-odb.ixx;ing_odb_category-odb.cxx;ing_odb_category-schema.cxx   

The additional dependencies:
ing_odb_category.hpp

The description:
odb ing_odb_category.hpp

The output from Visual Studio 2010:

2>------ Build started: Project: vs_2010, Configuration: Debug Win32 ------
2>  odb ing_odb_category.hpp

The odb tool takes the ing_odb_category.hpp as input and produces ing_odb_category-odb.hxx, ing_odb_category-odb.ixx,ing_odb_category-odb.cxx,ing_odb_category-schema.cxx files.

I can build the solution many times in a row and the custom build event will always run, even though the ing_odb_category.hpp file never changes.

How can I make Visual Studio only perform the custom build if the header file changes?

From the vcxproj file:

<CustomBuild Include="..\ing_odb_category.hpp">
  <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">odb -Ic:\menuplan\src\ingredient -o c:\menuplan\src\ingredient -d mysql --hxx-prologue "#include \"odb/traits.hxx\"" --generate-query --generate-schema --schema-format separate  c:\menuplan\src\ingredient\ing_odb_category.hpp</Command>
  <Command Condition="'$(Configuration)|$(Platform)'=='Debug_Static_Unicode|Win32'">odb -Ic:\menuplan\src\ingredient -o c:\menuplan\src\ingredient -d mysql --hxx-prologue "#include \"odb/traits.hxx\"" --generate-query --generate-schema --schema-format separate  c:\menuplan\src\ingredient\ing_odb_category.hpp</Command>
  <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">odb ing_odb_category.hpp</Message>
  <Message Condition="'$(Configuration)|$(Platform)'=='Debug_Static_Unicode|Win32'">odb ing_odb_category.hpp</Message>
  <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ing_odb_category-odb.hxx;ing_odb_category-odb.ixx;ing_odb_category-odb.cxx;ing_odb_category-schema.cxx</Outputs>
  <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug_Static_Unicode|Win32'">ing_odb_category-odb.hxx;ing_odb_category-odb.ixx;ing_odb_category-odb.cxx;ing_odb_category-schema.cxx</Outputs>
  <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ing_odb_category.hpp</AdditionalInputs>
</CustomBuild>

Environment:


Solution

  • Visual Studio was always building the files because it said they didn't exist.

    Using the Visual Studio project logging article, especially running the DebugView showed that Visual Studio was using a different path for the dependencies. I did not specify the path of the output files and dependencies, so it was trying to locate them in the default project directory.

    Also, Visual Studio expects only one output file, according to Specifying Custom Build Tools article. I was supplying all the output filenames.

    Summary

    In the Custom Build Tool window:

    1. There should only be one output file.
    2. Additional output files are listed in the Additional Dependencies slot.
    3. All output files should be prefixed with the path of their location, relative or absolute.

    Useful build process debugging aids can be found in the Visual Studio Project Logging article, especially the DebugView application.