cmTestCommand.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #include "cmCPluginAPI.h"
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. typedef struct
  6. {
  7. char *LibraryName;
  8. int Argc;
  9. char** Argv;
  10. } cmVTKWrapTclData;
  11. /* do almost everything in the initial pass */
  12. static int CCONV InitialPass(void *inf, void *mf, int argc, char *argv[])
  13. {
  14. char* file;
  15. char* str;
  16. char *srcs;
  17. const char* cstr;
  18. char buffer[1024];
  19. void *source_file;
  20. char *args[2];
  21. char *ccArgs[4];
  22. char *ccDep[1];
  23. char *ccOut[1];
  24. cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
  25. cmVTKWrapTclData *cdata =
  26. (cmVTKWrapTclData *)malloc(sizeof(cmVTKWrapTclData));
  27. cdata->LibraryName = "BOO";
  28. cdata->Argc = argc;
  29. cdata->Argv = argv;
  30. 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"))
  34. {
  35. info->CAPI->AddDefinition(mf, "TEST_DEF", "HOO");
  36. return 1;
  37. }
  38. info->CAPI->AddDefinition(mf, "TEST_DEF", "HOO");
  39. cdata->LibraryName = "HOO";
  40. info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE", "ON",
  41. "Test cache variable",
  42. CM_CACHE_BOOL);
  43. info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE1", "",
  44. "Test cache variable 1",
  45. CM_CACHE_PATH);
  46. info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE2", "",
  47. "Test cache variable 2",
  48. CM_CACHE_FILEPATH);
  49. info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE3", "",
  50. "Test cache variable 3",
  51. CM_CACHE_STRING);
  52. info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE4", "",
  53. "Test cache variable 4",
  54. CM_CACHE_INTERNAL);
  55. info->CAPI->AddCacheDefinition(mf, "SOME_CACHE_VARIABLE5", "",
  56. "Test cache variable 5",
  57. CM_CACHE_STATIC);
  58. file = info->CAPI->ExpandVariablesInString(mf, "${CMAKE_COMMAND}", 0, 0);
  59. str = info->CAPI->GetFilenameWithoutExtension(file);
  60. info->CAPI->DisplaySatus(mf, str);
  61. info->CAPI->Free(str);
  62. str = info->CAPI->GetFilenamePath(file);
  63. info->CAPI->DisplaySatus(mf, str);
  64. info->CAPI->Free(str);
  65. str = info->CAPI->Capitalized("cmake");
  66. info->CAPI->DisplaySatus(mf, str);
  67. info->CAPI->Free(str);
  68. info->CAPI->DisplaySatus(mf, info->CAPI->GetProjectName(mf));
  69. info->CAPI->DisplaySatus(mf, info->CAPI->GetHomeDirectory(mf));
  70. info->CAPI->DisplaySatus(mf, info->CAPI->GetHomeOutputDirectory(mf));
  71. info->CAPI->DisplaySatus(mf, info->CAPI->GetStartDirectory(mf));
  72. info->CAPI->DisplaySatus(mf, info->CAPI->GetStartOutputDirectory(mf));
  73. info->CAPI->DisplaySatus(mf, info->CAPI->GetCurrentDirectory(mf));
  74. info->CAPI->DisplaySatus(mf, info->CAPI->GetCurrentOutputDirectory(mf));
  75. sprintf(buffer, "Cache version: %d.%d, CMake version: %d.%d",
  76. info->CAPI->GetCacheMajorVersion(mf),
  77. info->CAPI->GetCacheMinorVersion(mf),
  78. info->CAPI->GetMajorVersion(mf),
  79. info->CAPI->GetMinorVersion(mf));
  80. info->CAPI->DisplaySatus(mf, buffer);
  81. if ( info->CAPI->CommandExists(mf, "SET") )
  82. {
  83. info->CAPI->DisplaySatus(mf, "Command SET exists");
  84. }
  85. if ( info->CAPI->CommandExists(mf, "SET_FOO_BAR") )
  86. {
  87. info->CAPI->SetError(mf, "Command SET_FOO_BAR should not exists");
  88. return 0;
  89. }
  90. info->CAPI->AddDefineFlag(mf, "-DADDED_DEFINITION");
  91. source_file = info->CAPI->CreateSourceFile();
  92. cstr = info->CAPI->SourceFileGetSourceName(source_file);
  93. sprintf(buffer, "Shold be empty (source file name): [%s]", cstr);
  94. info->CAPI->DisplaySatus(mf, buffer);
  95. cstr = info->CAPI->SourceFileGetFullPath(source_file);
  96. sprintf(buffer, "Shold be empty (source file full path): [%s]", cstr);
  97. info->CAPI->DisplaySatus(mf, buffer);
  98. if ( info->CAPI->SourceFileGetPropertyAsBool(source_file, "SOME_PROPERTY") )
  99. {
  100. info->CAPI->SetError(mf, "Property SOME_PROPERTY should not be defined");
  101. return 0;
  102. }
  103. info->CAPI->SourceFileSetProperty(source_file, "SOME_PROPERTY2", "HERE");
  104. cstr = info->CAPI->SourceFileGetProperty(source_file, "ABSTRACT");
  105. sprintf(buffer, "Should be 0 (source file abstract property): [%p]", cstr);
  106. info->CAPI->DisplaySatus(mf, buffer);
  107. info->CAPI->DestroySourceFile(source_file);
  108. srcs = argv[2];
  109. info->CAPI->AddExecutable(mf,"LoadedCommand",1, &srcs, 0);
  110. /* add customs commands to generate the source file */
  111. ccArgs[0] = "-E";
  112. ccArgs[1] = "copy";
  113. ccArgs[2] = argv[0];
  114. ccArgs[3] = argv[1];
  115. ccDep[0] = ccArgs[2];
  116. ccOut[0] = ccArgs[3];
  117. info->CAPI->AddCustomCommand(mf, "LoadedCommand.cxx.in",
  118. file,
  119. 4, ccArgs,
  120. 1, ccDep,
  121. 1, ccOut,
  122. "LoadedCommand");
  123. ccArgs[2] = argv[1];
  124. ccArgs[3] = argv[2];
  125. ccDep[0] = ccArgs[2];
  126. ccOut[0] = ccArgs[3];
  127. info->CAPI->AddCustomCommandToOutput(mf, ccOut[0],
  128. file,
  129. 4, ccArgs,
  130. ccDep[0],
  131. 0, 0);
  132. ccArgs[1] = "echo";
  133. ccArgs[2] = "Build has finished";
  134. info->CAPI->AddCustomCommandToTarget(mf, "LoadedCommand",
  135. file,
  136. 3, ccArgs,
  137. CM_POST_BUILD);
  138. info->CAPI->Free(file);
  139. args[0] = "TEST_EXEC";
  140. args[1] = "TRUE";
  141. /* code coverage */
  142. if (info->CAPI->GetTotalArgumentSize(2,args) != 13)
  143. {
  144. return 0;
  145. }
  146. info->CAPI->ExecuteCommand(mf,"SET",2,args);
  147. /* make sure we can find the source file */
  148. if (!info->CAPI->GetSource(mf,argv[1]))
  149. {
  150. info->CAPI->SetError(mf, "Source file could not be found!");
  151. return 0;
  152. }
  153. return 1;
  154. }
  155. static void CCONV FinalPass(void *inf, void *mf)
  156. {
  157. cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
  158. /* get our client data from initial pass */
  159. cmVTKWrapTclData *cdata =
  160. (cmVTKWrapTclData *)info->CAPI->GetClientData(info);
  161. if (strcmp(info->CAPI->GetDefinition(mf, "TEST_DEF"),"HOO") ||
  162. strcmp(cdata->LibraryName,"HOO"))
  163. {
  164. fprintf(stderr,"*** Failed LOADED COMMAND Final Pass\n");
  165. }
  166. }
  167. static void CCONV Destructor(void *inf)
  168. {
  169. cmLoadedCommandInfo *info = (cmLoadedCommandInfo *)inf;
  170. /* get our client data from initial pass */
  171. cmVTKWrapTclData *cdata =
  172. (cmVTKWrapTclData *)info->CAPI->GetClientData(info);
  173. free(cdata);
  174. }
  175. #ifdef MUCHO_MUDSLIDE
  176. void CM_PLUGIN_EXPORT CCONV CMAKE_TEST_COMMANDInit(cmLoadedCommandInfo *info)
  177. {
  178. info->InitialPass = InitialPass;
  179. info->FinalPass = FinalPass;
  180. info->Destructor = Destructor;
  181. info->m_Inherited = 0;
  182. info->Name = "CMAKE_TEST_COMMAND";
  183. }
  184. #endif