cmTestCommand.c 4.84 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
2
3
4
5
6
7
8
#include "cmCPluginAPI.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

typedef struct 
{
  char *LibraryName;
Andy Cedilnik's avatar
Andy Cedilnik committed
9
10
  int Argc;
  char** Argv;
Ken Martin's avatar
Ken Martin committed
11
12
13
14
} cmVTKWrapTclData;


/* do almost everything in the initial pass */
Andy Cedilnik's avatar
Andy Cedilnik committed
15
static int InitialPass(void *inf, void *mf, int argc, char *argv[])
Ken Martin's avatar
Ken Martin committed
16
{
Andy Cedilnik's avatar
Andy Cedilnik committed
17
  char* file;
Bill Hoffman's avatar
Bill Hoffman committed
18
19
  char* str;
  const char* cstr;
Andy Cedilnik's avatar
Andy Cedilnik committed
20
21
  char buffer[1024];
  void *source_file;
Ken Martin's avatar
Ken Martin committed
22
23
24
25
26
  cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;

  cmVTKWrapTclData *cdata = 
    (cmVTKWrapTclData *)malloc(sizeof(cmVTKWrapTclData));
  cdata->LibraryName = "BOO";
Andy Cedilnik's avatar
Andy Cedilnik committed
27
28
  cdata->Argc = argc;
  cdata->Argv = argv;
Ken Martin's avatar
Ken Martin committed
29
30
  info->CAPI->SetClientData(info,cdata);
  
Ken Martin's avatar
Ken Martin committed
31
32
  /* 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 */
Ken Martin's avatar
Ken Martin committed
33
34
35
36
37
38
39
40
  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";
Andy Cedilnik's avatar
Andy Cedilnik committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

  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();
Bill Hoffman's avatar
Bill Hoffman committed
101
102
  cstr = info->CAPI->SourceFileGetSourceName(source_file);
  sprintf(buffer, "Shold be empty (source file name): [%s]", cstr);
Andy Cedilnik's avatar
Andy Cedilnik committed
103
  info->CAPI->DisplaySatus(mf, buffer);
Bill Hoffman's avatar
Bill Hoffman committed
104
105
  cstr = info->CAPI->SourceFileGetFullPath(source_file);
  sprintf(buffer, "Shold be empty (source file full path): [%s]", cstr);
Andy Cedilnik's avatar
Andy Cedilnik committed
106
107
108
109
110
111
  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;
    }
Bill Hoffman's avatar
Bill Hoffman committed
112
113
  cstr = info->CAPI->SourceFileGetProperty(source_file, "ABSTRACT");
  sprintf(buffer, "Shold be 0 (source file abstract property): [%p]", cstr);
Andy Cedilnik's avatar
Andy Cedilnik committed
114
115
116
117
  info->CAPI->DisplaySatus(mf, buffer);

  info->CAPI->DestroySourceFile(source_file);

Ken Martin's avatar
Ken Martin committed
118
119
120
  return 1;
}

Andy Cedilnik's avatar
Andy Cedilnik committed
121
static void FinalPass(void *inf, void *mf) 
Ken Martin's avatar
Ken Martin committed
122
123
{
  cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
Ken Martin's avatar
Ken Martin committed
124
  /* get our client data from initial pass */
Ken Martin's avatar
Ken Martin committed
125
126
127
128
129
130
131
132
133
  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");
    }
}

Andy Cedilnik's avatar
Andy Cedilnik committed
134
static void Destructor(void *inf) 
Ken Martin's avatar
Ken Martin committed
135
136
{
  cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
Ken Martin's avatar
Ken Martin committed
137
  /* get our client data from initial pass */
Ken Martin's avatar
Ken Martin committed
138
139
140
141
142
  cmVTKWrapTclData *cdata = 
    (cmVTKWrapTclData *)info->CAPI->GetClientData(info);
  free(cdata);
}

Ken Martin's avatar
Ken Martin committed
143
#ifdef MUCHO_MUDSLIDE
Ken Martin's avatar
Ken Martin committed
144
void CM_PLUGIN_EXPORT CMAKE_TEST_COMMANDInit(cmLoadedCommandInfo *info)
Ken Martin's avatar
Ken Martin committed
145
146
147
{
  info->InitialPass = InitialPass;
  info->FinalPass = FinalPass;
Ken Martin's avatar
Ken Martin committed
148
  info->Destructor = Destructor;
Ken Martin's avatar
Ken Martin committed
149
  info->m_Inherited = 0;
Ken Martin's avatar
cleanup    
Ken Martin committed
150
  info->Name = "CMAKE_TEST_COMMAND";
Ken Martin's avatar
Ken Martin committed
151
}
Ken Martin's avatar
Ken Martin committed
152
#endif
Ken Martin's avatar
Ken Martin committed
153
154
155
156