[CMake] defining my own build type

Joshua Jensen jjensen at workspacewhiz.com
Fri May 18 13:31:00 EDT 2007


Jesper Eskilson wrote:
> Hi all,
>
> I tried following the instructions on the wiki on how to define my own
> build type (configuration), however the new build type ("Develop")
> does not show up as a valid solution configuration in Visual Studio.
> Why is that?
>
Custom build types don't work under Visual Studio.  The following 
"patches" (not really a patch but the best I could do at the moment) 
gives you custom build types under Visual Studio.  These are against 
latest CVS.

I have a number of other changes in my CMake source.  I hope I got all 
the right ones.  If this doesn't work for you, I'll modify a pristine 
CMake CVS get and send a real patch.

Josh

In void 
cmGlobalVisualStudio7Generator::GenerateConfigurations(cmMakefile* mf), 
turn off the hardcoded config check and stop the error call if you 
aren't using one of the hardcoded build types:

//      if(config == "Debug" || config == "Release" ||
//         config == "MinSizeRel" || config == "RelWithDebInfo")
        {
        // only add unique configurations
        if(std::find(this->Configurations.begin(),
                     this->Configurations.end(),
                     config) == this->Configurations.end())
          {
          this->Configurations.push_back(config);
          }
        }
/*      else
        {
        cmSystemTools::Error(
          "Invalid configuration type in CMAKE_CONFIGURATION_TYPES: ",
          config.c_str(),
          " (Valid types are Debug,Release,MinSizeRel,RelWithDebInfo)");
        }*/


In void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& 
fout, const char* configName, cmTarget &target), turn off the .vcproj 
output that generates debug information.  The reason for this is a new 
flag in cmLocalVisualStudio7GeneratorLinkFlagTable that will translate a 
/DEBUG link line option to the GenerateDebugInformation .vcproj output 
for any configuration that specifies it.

/*    if(strcmp(configName, "Debug") == 0
       || strcmp(configName, "RelWithDebInfo") == 0)
      {
      fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
      }*/

and the second one:

/*    if(strcmp(configName, "Debug") == 0
       || strcmp(configName, "RelWithDebInfo") == 0)
      {
      fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n";
      }*/

In cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] =, add:

  {"IgnoreAllDefaultLibraries", "NODEFAULTLIB", "ignore all default libs",
   "TRUE", 0},
  {"OptimizeReferences", "OPT:REF", "optimize references", "2", 0},
  {"EnableCOMDATFolding", "OPT:ICF", "enable comdat folding", "2", 0},
  {"GenerateDebugInformation", "DEBUG", "debug support", "TRUE", 0},
  {"TargetMachine", "MACHINE:X86", "x86 support", "1", 0},
  {0,0,0,0,0}

In void cmLocalVisualStudio7GeneratorOptions::HandleFlag(const char* 
flag), turn off the /D check for the link command line.  If you don't, 
it thinks it is a #define:

  // Look for known arguments.
  if(flag[0] == '-' || flag[0] == '/')
    {
    // Look for preprocessor definitions.
    if(flag[1] == 'D'  &&  this->FlagTable != 
cmLocalVisualStudio7GeneratorLinkFlagTable)


Finally, in Windows-cl.cmake, add the properly capitalized /DEBUG 
(according to the MSVC documentation).  Compiler flags are case 
sensitive, but linker flags are not.  However, CMake treats linker flags 
in a case sensitive fashion, so it is best to specify them as the MSVC 
documentation describes, as uppercase.

# add /DEBUG and /INCREMENTAL:YES to DEBUG and RELWITHDEBINFO also add 
pdbtyp
# on versions that support it
IF (CMAKE_COMPILER_SUPPORTS_PDBTYPE)
  SET (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/DEBUG /PDBTYPE:sept 
/INCREMENTAL:YES")
  SET (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/DEBUG /PDBTYPE:sept 
/INCREMENTAL:YES")
ELSE (CMAKE_COMPILER_SUPPORTS_PDBTYPE)
  SET (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/DEBUG /INCREMENTAL:YES")
  SET (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/DEBUG /INCREMENTAL:YES")
ENDIF (CMAKE_COMPILER_SUPPORTS_PDBTYPE)



More information about the CMake mailing list