STYLE: Nightly Version update
[cmake.git] / Tests / LoadCommand / CMakeCommands / cmTestCommand.c
blob4bcaa33f12eb7f7da693c8e75f55a35365936edd
1 #include "cmCPluginAPI.h"
2 #include <string.h>
3 #include <stdlib.h>
4 #include <stdio.h>
6 typedef struct
8 char *LibraryName;
9 int Argc;
10 char** Argv;
11 } cmVTKWrapTclData;
14 /* do almost everything in the initial pass */
15 static int InitialPass(void *inf, void *mf, int argc, char *argv[])
17 char* file;
18 char* str;
19 const char* cstr;
20 char buffer[1024];
21 void *source_file;
22 cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
24 cmVTKWrapTclData *cdata =
25 (cmVTKWrapTclData *)malloc(sizeof(cmVTKWrapTclData));
26 cdata->LibraryName = "BOO";
27 cdata->Argc = argc;
28 cdata->Argv = argv;
29 info->CAPI->SetClientData(info,cdata);
31 /* Now check and see if the value has been stored in the cache */
32 /* already, if so use that value and don't look for the program */
33 if(!info->CAPI->IsOn(mf,"TEST_COMMAND_TEST1"))
35 info->CAPI->AddDefinition(mf, "TEST_DEF", "HOO");
36 return 1;
39 info->CAPI->AddDefinition(mf, "TEST_DEF", "HOO");
40 cdata->LibraryName = "HOO";
42 info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE", "ON",
43 "Test cache variable",
44 CM_CACHE_BOOL);
45 info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE1", "",
46 "Test cache variable 1",
47 CM_CACHE_PATH);
48 info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE2", "",
49 "Test cache variable 2",
50 CM_CACHE_FILEPATH);
51 info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE3", "",
52 "Test cache variable 3",
53 CM_CACHE_STRING);
54 info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE4", "",
55 "Test cache variable 4",
56 CM_CACHE_INTERNAL);
57 info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE5", "",
58 "Test cache variable 5",
59 CM_CACHE_STATIC);
62 file = info->CAPI->ExpandVariablesInString(mf, "${CMAKE_COMMAND}", 0, 0);
64 str = info->CAPI->GetFilenameWithoutExtension(file);
65 info->CAPI->DisplaySatus(mf, str);
66 info->CAPI->Free(str);
67 str = info->CAPI->GetFilenamePath(file);
68 info->CAPI->DisplaySatus(mf, str);
69 info->CAPI->Free(str);
70 str = info->CAPI->Capitalized("cmake");
71 info->CAPI->DisplaySatus(mf, str);
72 info->CAPI->Free(str);
74 info->CAPI->Free(file);
76 info->CAPI->DisplaySatus(mf, info->CAPI->GetProjectName(mf));
77 info->CAPI->DisplaySatus(mf, info->CAPI->GetHomeDirectory(mf));
78 info->CAPI->DisplaySatus(mf, info->CAPI->GetHomeOutputDirectory(mf));
79 info->CAPI->DisplaySatus(mf, info->CAPI->GetStartDirectory(mf));
80 info->CAPI->DisplaySatus(mf, info->CAPI->GetStartOutputDirectory(mf));
81 info->CAPI->DisplaySatus(mf, info->CAPI->GetCurrentDirectory(mf));
82 info->CAPI->DisplaySatus(mf, info->CAPI->GetCurrentOutputDirectory(mf));
83 sprintf(buffer, "Cache version: %d.%d, CMake version: %d.%d",
84 info->CAPI->GetCacheMajorVersion(mf),
85 info->CAPI->GetCacheMinorVersion(mf),
86 info->CAPI->GetMajorVersion(mf),
87 info->CAPI->GetMinorVersion(mf));
88 info->CAPI->DisplaySatus(mf, buffer);
89 if ( info->CAPI->CommandExists(mf, "SET") )
91 info->CAPI->DisplaySatus(mf, "Command SET exists");
93 if ( info->CAPI->CommandExists(mf, "SET_FOO_BAR") )
95 info->CAPI->SetError(mf, "Command SET_FOO_BAR should not exists");
96 return 0;
98 info->CAPI->AddDefineFlag(mf, "-DADDED_DEFINITION");
100 source_file = info->CAPI->CreateSourceFile();
101 cstr = info->CAPI->SourceFileGetSourceName(source_file);
102 sprintf(buffer, "Shold be empty (source file name): [%s]", cstr);
103 info->CAPI->DisplaySatus(mf, buffer);
104 cstr = info->CAPI->SourceFileGetFullPath(source_file);
105 sprintf(buffer, "Shold be empty (source file full path): [%s]", cstr);
106 info->CAPI->DisplaySatus(mf, buffer);
107 if ( info->CAPI->SourceFileGetPropertyAsBool(source_file, "SOME_PROPERTY") )
109 info->CAPI->SetError(mf, "Property SOME_PROPERTY should not be defined");
110 return 0;
112 cstr = info->CAPI->SourceFileGetProperty(source_file, "ABSTRACT");
113 sprintf(buffer, "Shold be 0 (source file abstract property): [%p]", cstr);
114 info->CAPI->DisplaySatus(mf, buffer);
116 info->CAPI->DestroySourceFile(source_file);
118 return 1;
121 static void FinalPass(void *inf, void *mf)
123 cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
124 /* get our client data from initial pass */
125 cmVTKWrapTclData *cdata =
126 (cmVTKWrapTclData *)info->CAPI->GetClientData(info);
127 if (strcmp(info->CAPI->GetDefinition(mf, "TEST_DEF"),"HOO") ||
128 strcmp(cdata->LibraryName,"HOO"))
130 fprintf(stderr,"*** Failed LOADED COMMAND Final Pass\n");
134 static void Destructor(void *inf)
136 cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
137 /* get our client data from initial pass */
138 cmVTKWrapTclData *cdata =
139 (cmVTKWrapTclData *)info->CAPI->GetClientData(info);
140 free(cdata);
143 #ifdef MUCHO_MUDSLIDE
144 void CM_PLUGIN_EXPORT CMAKE_TEST_COMMANDInit(cmLoadedCommandInfo *info)
146 info->InitialPass = InitialPass;
147 info->FinalPass = FinalPass;
148 info->Destructor = Destructor;
149 info->m_Inherited = 0;
150 info->Name = "CMAKE_TEST_COMMAND";
152 #endif