13

I need to generate a C++ header file that describes the compiler used.

Traditionally we used the CMake command:

configure( ${PROJECT_SOURCE_DIR}/configure.h.in ${PROJECT_BINARY_DIR}/configure.h )

which replaces all string sandwiched by "@" (for example @cxx_compiler_name@) with the value of that variable in the cmake build system.

We have been given the requirement to face out CMake, so is there something equivalent in Visual Studio. I'd like to populate the header file with some of the values in the Visual Studio macros.

Hadi
  • 36,233
  • 13
  • 65
  • 124
KlingonJoe
  • 815
  • 8
  • 17
  • 2
    One trick is to add a C# projet in the same solution for that code generation purpose, add a configure.h.tt ("T4 template", they can output any file extension, like .h or .cpp) in this project, w/o any other C# code, and configure the solution so the C++ project has a dependency on the C# one so it builds after it. You can add an msbuild task to the vcxproj to copy the generated file over to c++ or include it in the c++ project directly. More on T4 here: http://www.hanselman.com/blog/T4TextTemplateTransformationToolkitCodeGenerationBestKeptVisualStudioSecret.aspx – Simon Mourier Feb 12 '17 at 09:30

1 Answers1

2

You can add your configure.h.in file to the project and set a custom build for it that will run perl or sed and replace whatever needed. Don't forget to add configure.h to output files property so Visual Studio can figure out the dependencies and "build" configure.h.in before other sources that use configure.h.

Paul
  • 13,042
  • 3
  • 41
  • 59
  • With Cmake, you can grab directly from the compilers their names and versions. sed would work, but it's going to be one long command for all the replacements I have. Perl would also work, but I rather script with CMake if I'm going to bring in another tool. – KlingonJoe Feb 09 '17 at 14:16
  • @KlingonJoe You can try using MSBuild for that http://stackoverflow.com/a/7888659/70930 but I'm not sure what is easier. – Paul Feb 09 '17 at 16:40