cmTestCommand.c 6.6 KB

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