CMake/Tests/LoadCommand/CMakeCommands/cmTestCommand.c

152 lines
4.7 KiB
C
Raw Normal View History

2002-09-17 00:27:00 +04:00
#include "cmCPluginAPI.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
typedef struct
{
char *LibraryName;
} cmVTKWrapTclData;
/* do almost everything in the initial pass */
2002-09-23 23:56:28 +04:00
static int InitialPass(void *inf, void *mf, int argc, char *argv[])
2002-09-17 00:27:00 +04:00
{
2003-07-22 20:21:15 +04:00
char* file;
char* str;
char buffer[1024];
void *source_file;
2002-09-17 00:27:00 +04:00
cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
cmVTKWrapTclData *cdata =
(cmVTKWrapTclData *)malloc(sizeof(cmVTKWrapTclData));
cdata->LibraryName = "BOO";
info->CAPI->SetClientData(info,cdata);
2002-09-20 18:06:00 +04:00
/* Now check and see if the value has been stored in the cache */
/* already, if so use that value and don't look for the program */
2002-09-17 00:27:00 +04:00
if(!info->CAPI->IsOn(mf,"TEST_COMMAND_TEST1"))
{
info->CAPI->AddDefinition(mf, "TEST_DEF", "HOO");
return 1;
}
info->CAPI->AddDefinition(mf, "TEST_DEF", "HOO");
cdata->LibraryName = "HOO";
2003-07-22 20:21:15 +04:00
info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE", "ON",
"Test cache variable",
CM_CACHE_BOOL);
info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE1", "",
"Test cache variable 1",
CM_CACHE_PATH);
info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE2", "",
"Test cache variable 2",
CM_CACHE_FILEPATH);
info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE3", "",
"Test cache variable 3",
CM_CACHE_STRING);
info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE4", "",
"Test cache variable 4",
CM_CACHE_INTERNAL);
info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE5", "",
"Test cache variable 5",
CM_CACHE_STATIC);
file = info->CAPI->ExpandVariablesInString(mf, "${CMAKE_COMMAND}", 0, 0);
str = info->CAPI->GetFilenameWithoutExtension(file);
info->CAPI->DisplaySatus(mf, str);
info->CAPI->Free(str);
str = info->CAPI->GetFilenamePath(file);
info->CAPI->DisplaySatus(mf, str);
info->CAPI->Free(str);
str = info->CAPI->Capitalized("cmake");
info->CAPI->DisplaySatus(mf, str);
info->CAPI->Free(str);
info->CAPI->Free(file);
info->CAPI->DisplaySatus(mf, info->CAPI->GetProjectName(mf));
info->CAPI->DisplaySatus(mf, info->CAPI->GetHomeDirectory(mf));
info->CAPI->DisplaySatus(mf, info->CAPI->GetHomeOutputDirectory(mf));
info->CAPI->DisplaySatus(mf, info->CAPI->GetStartDirectory(mf));
info->CAPI->DisplaySatus(mf, info->CAPI->GetStartOutputDirectory(mf));
info->CAPI->DisplaySatus(mf, info->CAPI->GetCurrentDirectory(mf));
info->CAPI->DisplaySatus(mf, info->CAPI->GetCurrentOutputDirectory(mf));
sprintf(buffer, "Cache version: %d.%d, CMake version: %d.%d",
info->CAPI->GetCacheMajorVersion(mf),
info->CAPI->GetCacheMinorVersion(mf),
info->CAPI->GetMajorVersion(mf),
info->CAPI->GetMinorVersion(mf));
info->CAPI->DisplaySatus(mf, buffer);
if ( info->CAPI->CommandExists(mf, "SET") )
{
info->CAPI->DisplaySatus(mf, "Command SET exists");
}
if ( info->CAPI->CommandExists(mf, "SET_FOO_BAR") )
{
info->CAPI->SetError(mf, "Command SET_FOO_BAR should not exists");
return 0;
}
info->CAPI->AddDefineFlag(mf, "-DADDED_DEFINITION");
source_file = info->CAPI->CreateSourceFile();
str = info->CAPI->SourceFileGetSourceName(source_file);
sprintf(buffer, "Shold be empty (source file name): [%s]", str);
info->CAPI->DisplaySatus(mf, buffer);
str = info->CAPI->SourceFileGetFullPath(source_file);
sprintf(buffer, "Shold be empty (source file full path): [%s]", str);
info->CAPI->DisplaySatus(mf, buffer);
if ( info->CAPI->SourceFileGetPropertyAsBool(source_file, "SOME_PROPERTY") )
{
info->CAPI->SetError(mf, "Property SOME_PROPERTY should not be defined");
return 0;
}
str = info->CAPI->SourceFileGetProperty(source_file, "ABSTRACT");
sprintf(buffer, "Shold be 0 (source file abstract property): [%p]", str);
info->CAPI->DisplaySatus(mf, buffer);
info->CAPI->DestroySourceFile(source_file);
2002-09-17 00:27:00 +04:00
return 1;
}
2002-09-23 23:56:28 +04:00
static void FinalPass(void *inf, void *mf)
2002-09-17 00:27:00 +04:00
{
cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
2002-09-20 18:06:00 +04:00
/* get our client data from initial pass */
2002-09-17 00:27:00 +04:00
cmVTKWrapTclData *cdata =
(cmVTKWrapTclData *)info->CAPI->GetClientData(info);
if (strcmp(info->CAPI->GetDefinition(mf, "TEST_DEF"),"HOO") ||
strcmp(cdata->LibraryName,"HOO"))
{
fprintf(stderr,"*** Failed LOADED COMMAND Final Pass\n");
}
}
2002-09-23 23:56:28 +04:00
static void Destructor(void *inf)
2002-09-17 18:38:34 +04:00
{
cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
2002-09-20 18:06:00 +04:00
/* get our client data from initial pass */
2002-09-17 18:38:34 +04:00
cmVTKWrapTclData *cdata =
(cmVTKWrapTclData *)info->CAPI->GetClientData(info);
free(cdata);
}
2002-09-18 19:38:15 +04:00
#ifdef MUCHO_MUDSLIDE
2002-10-08 23:55:24 +04:00
void CM_PLUGIN_EXPORT CMAKE_TEST_COMMANDInit(cmLoadedCommandInfo *info)
2002-09-17 00:27:00 +04:00
{
info->InitialPass = InitialPass;
info->FinalPass = FinalPass;
2002-09-17 18:38:34 +04:00
info->Destructor = Destructor;
2002-09-17 00:27:00 +04:00
info->m_Inherited = 0;
2002-09-23 22:57:41 +04:00
info->Name = "CMAKE_TEST_COMMAND";
2002-09-17 00:27:00 +04:00
}
2002-09-18 19:38:15 +04:00
#endif
2002-09-17 00:27:00 +04:00