Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmCPluginAPI.cxx
blobbe6a693fc00635671e8529dcfaf51c48f6088102
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCPluginAPI.cxx,v $
5 Language: C++
6 <<<<<<< cmCPluginAPI.cxx
7 Date: $Date: 2008/01/23 15:27:59 $
8 Version: $Revision: 1.42 $
9 =======
10 Date: $Date: 2009-03-16 18:30:24 $
11 Version: $Revision: 1.43 $
12 >>>>>>> 1.43
14 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
15 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
17 This software is distributed WITHOUT ANY WARRANTY; without even
18 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 PURPOSE. See the above copyright notices for more information.
21 =========================================================================*/
23 this file contains the implementation of the C API to CMake. Generally
24 these routines just manipulate arguments and then call the associated
25 methods on the CMake classes. */
27 #include "cmMakefile.h"
28 #include "cmCPluginAPI.h"
29 #include "cmVersion.h"
31 #include "cmSourceFile.h"
33 #include <stdlib.h>
35 #ifdef __QNX__
36 # include <malloc.h> /* for malloc/free on QNX */
37 #endif
39 extern "C"
42 void CCONV *cmGetClientData(void *info)
44 return ((cmLoadedCommandInfo *)info)->ClientData;
47 void CCONV cmSetClientData(void *info, void *cd)
49 ((cmLoadedCommandInfo *)info)->ClientData = cd;
52 void CCONV cmSetError(void *info, const char *err)
54 if (((cmLoadedCommandInfo *)info)->Error)
56 free(((cmLoadedCommandInfo *)info)->Error);
58 ((cmLoadedCommandInfo *)info)->Error = strdup(err);
61 unsigned int CCONV cmGetCacheMajorVersion(void *arg)
63 cmMakefile *mf = static_cast<cmMakefile *>(arg);
64 return mf->GetCacheMajorVersion();
66 unsigned int CCONV cmGetCacheMinorVersion(void *arg)
68 cmMakefile *mf = static_cast<cmMakefile *>(arg);
69 return mf->GetCacheMinorVersion();
72 unsigned int CCONV cmGetMajorVersion(void *)
74 return cmVersion::GetMajorVersion();
77 unsigned int CCONV cmGetMinorVersion(void *)
79 return cmVersion::GetMinorVersion();
82 void CCONV cmAddDefinition(void *arg, const char* name, const char* value)
84 cmMakefile *mf = static_cast<cmMakefile *>(arg);
85 mf->AddDefinition(name,value);
88 /* Add a definition to this makefile and the global cmake cache. */
89 void CCONV cmAddCacheDefinition(void *arg, const char* name,
90 const char* value, const char* doc, int type)
92 cmMakefile *mf = static_cast<cmMakefile *>(arg);
94 switch (type)
96 case CM_CACHE_BOOL:
97 mf->AddCacheDefinition(name,value,doc,
98 cmCacheManager::BOOL);
99 break;
100 case CM_CACHE_PATH:
101 mf->AddCacheDefinition(name,value,doc,
102 cmCacheManager::PATH);
103 break;
104 case CM_CACHE_FILEPATH:
105 mf->AddCacheDefinition(name,value,doc,
106 cmCacheManager::FILEPATH);
107 break;
108 case CM_CACHE_STRING:
109 mf->AddCacheDefinition(name,value,doc,
110 cmCacheManager::STRING);
111 break;
112 case CM_CACHE_INTERNAL:
113 mf->AddCacheDefinition(name,value,doc,
114 cmCacheManager::INTERNAL);
115 break;
116 case CM_CACHE_STATIC:
117 mf->AddCacheDefinition(name,value,doc,
118 cmCacheManager::STATIC);
119 break;
123 const char* CCONV cmGetProjectName(void *arg)
125 cmMakefile *mf = static_cast<cmMakefile *>(arg);
126 return mf->GetProjectName();
129 const char* CCONV cmGetHomeDirectory(void *arg)
131 cmMakefile *mf = static_cast<cmMakefile *>(arg);
132 return mf->GetHomeDirectory();
134 const char* CCONV cmGetHomeOutputDirectory(void *arg)
136 cmMakefile *mf = static_cast<cmMakefile *>(arg);
137 return mf->GetHomeOutputDirectory();
139 const char* CCONV cmGetStartDirectory(void *arg)
141 cmMakefile *mf = static_cast<cmMakefile *>(arg);
142 return mf->GetStartDirectory();
144 const char* CCONV cmGetStartOutputDirectory(void *arg)
146 cmMakefile *mf = static_cast<cmMakefile *>(arg);
147 return mf->GetStartOutputDirectory();
149 const char* CCONV cmGetCurrentDirectory(void *arg)
151 cmMakefile *mf = static_cast<cmMakefile *>(arg);
152 return mf->GetCurrentDirectory();
154 const char* CCONV cmGetCurrentOutputDirectory(void *arg)
156 cmMakefile *mf = static_cast<cmMakefile *>(arg);
157 return mf->GetCurrentOutputDirectory();
159 const char* CCONV cmGetDefinition(void *arg,const char*def)
161 cmMakefile *mf = static_cast<cmMakefile *>(arg);
162 return mf->GetDefinition(def);
165 int CCONV cmIsOn(void *arg, const char* name)
167 cmMakefile *mf = static_cast<cmMakefile *>(arg);
168 return static_cast<int>(mf->IsOn(name));
171 /** Check if a command exists. */
172 int CCONV cmCommandExists(void *arg, const char* name)
174 cmMakefile *mf = static_cast<cmMakefile *>(arg);
175 return static_cast<int>(mf->CommandExists(name));
178 void CCONV cmAddDefineFlag(void *arg, const char* definition)
180 cmMakefile *mf = static_cast<cmMakefile *>(arg);
181 mf->AddDefineFlag(definition);
184 void CCONV cmAddLinkDirectoryForTarget(void *arg, const char *tgt,
185 const char* d)
187 cmMakefile *mf = static_cast<cmMakefile *>(arg);
188 mf->AddLinkDirectoryForTarget(tgt,d);
192 void CCONV cmAddExecutable(void *arg, const char *exename,
193 int numSrcs, const char **srcs, int win32)
195 cmMakefile *mf = static_cast<cmMakefile *>(arg);
196 std::vector<std::string> srcs2;
197 int i;
198 for (i = 0; i < numSrcs; ++i)
200 srcs2.push_back(srcs[i]);
202 cmTarget* tg = mf->AddExecutable(exename, srcs2);
203 if ( win32 )
205 tg->SetProperty("WIN32_EXECUTABLE", "ON");
209 void CCONV cmAddUtilityCommand(void *arg, const char* utilityName,
210 const char* command,
211 const char* arguments,
212 int all,
213 int numDepends,
214 const char **depends,
215 int,
216 const char **)
218 // Get the makefile instance. Perform an extra variable expansion
219 // now because the API caller expects it.
220 cmMakefile* mf = static_cast<cmMakefile*>(arg);
222 // Construct the command line for the command.
223 cmCustomCommandLine commandLine;
224 std::string expand = command;
225 commandLine.push_back(mf->ExpandVariablesInString(expand));
226 if(arguments && arguments[0])
228 // TODO: Parse arguments!
229 expand = arguments;
230 commandLine.push_back(mf->ExpandVariablesInString(expand));
232 cmCustomCommandLines commandLines;
233 commandLines.push_back(commandLine);
235 // Accumulate the list of dependencies.
236 std::vector<std::string> depends2;
237 for(int i = 0; i < numDepends; ++i)
239 expand = depends[i];
240 depends2.push_back(mf->ExpandVariablesInString(expand));
243 // Pass the call to the makefile instance.
244 mf->AddUtilityCommand(utilityName, (all ? false : true),
245 0, depends2, commandLines);
247 void CCONV cmAddCustomCommand(void *arg, const char* source,
248 const char* command,
249 int numArgs, const char **args,
250 int numDepends, const char **depends,
251 int numOutputs, const char **outputs,
252 const char *target)
254 // Get the makefile instance. Perform an extra variable expansion
255 // now because the API caller expects it.
256 cmMakefile* mf = static_cast<cmMakefile*>(arg);
258 // Construct the command line for the command.
259 cmCustomCommandLine commandLine;
260 std::string expand = command;
261 commandLine.push_back(mf->ExpandVariablesInString(expand));
262 for(int i=0; i < numArgs; ++i)
264 expand = args[i];
265 commandLine.push_back(mf->ExpandVariablesInString(expand));
267 cmCustomCommandLines commandLines;
268 commandLines.push_back(commandLine);
270 // Accumulate the list of dependencies.
271 std::vector<std::string> depends2;
272 for(int i = 0; i < numDepends; ++i)
274 expand = depends[i];
275 depends2.push_back(mf->ExpandVariablesInString(expand));
278 // Accumulate the list of outputs.
279 std::vector<std::string> outputs2;
280 for(int i = 0; i < numOutputs; ++i)
282 expand = outputs[i];
283 outputs2.push_back(mf->ExpandVariablesInString(expand));
286 // Pass the call to the makefile instance.
287 const char* no_comment = 0;
288 mf->AddCustomCommandOldStyle(target, outputs2, depends2, source,
289 commandLines, no_comment);
292 void CCONV cmAddCustomCommandToOutput(void *arg, const char* output,
293 const char* command,
294 int numArgs, const char **args,
295 const char* main_dependency,
296 int numDepends, const char **depends)
298 // Get the makefile instance. Perform an extra variable expansion
299 // now because the API caller expects it.
300 cmMakefile* mf = static_cast<cmMakefile*>(arg);
302 // Construct the command line for the command.
303 cmCustomCommandLine commandLine;
304 std::string expand = command;
305 commandLine.push_back(mf->ExpandVariablesInString(expand));
306 for(int i=0; i < numArgs; ++i)
308 expand = args[i];
309 commandLine.push_back(mf->ExpandVariablesInString(expand));
311 cmCustomCommandLines commandLines;
312 commandLines.push_back(commandLine);
314 // Accumulate the list of dependencies.
315 std::vector<std::string> depends2;
316 for(int i = 0; i < numDepends; ++i)
318 expand = depends[i];
319 depends2.push_back(mf->ExpandVariablesInString(expand));
322 // Pass the call to the makefile instance.
323 const char* no_comment = 0;
324 const char* no_working_dir = 0;
325 mf->AddCustomCommandToOutput(output, depends2, main_dependency,
326 commandLines, no_comment, no_working_dir);
329 void CCONV cmAddCustomCommandToTarget(void *arg, const char* target,
330 const char* command,
331 int numArgs, const char **args,
332 int commandType)
334 // Get the makefile instance.
335 cmMakefile* mf = static_cast<cmMakefile*>(arg);
337 // Construct the command line for the command. Perform an extra
338 // variable expansion now because the API caller expects it.
339 cmCustomCommandLine commandLine;
340 std::string expand = command;
341 commandLine.push_back(mf->ExpandVariablesInString(expand));
342 for(int i=0; i < numArgs; ++i)
344 expand = args[i];
345 commandLine.push_back(mf->ExpandVariablesInString(expand));
347 cmCustomCommandLines commandLines;
348 commandLines.push_back(commandLine);
350 // Select the command type.
351 cmTarget::CustomCommandType cctype = cmTarget::POST_BUILD;
352 switch (commandType)
354 case CM_PRE_BUILD:
355 cctype = cmTarget::PRE_BUILD;
356 break;
357 case CM_PRE_LINK:
358 cctype = cmTarget::PRE_LINK;
359 break;
360 case CM_POST_BUILD:
361 cctype = cmTarget::POST_BUILD;
362 break;
365 // Pass the call to the makefile instance.
366 std::vector<std::string> no_depends;
367 const char* no_comment = 0;
368 const char* no_working_dir = 0;
369 mf->AddCustomCommandToTarget(target, no_depends, commandLines,
370 cctype, no_comment, no_working_dir);
373 void CCONV cmAddLinkLibraryForTarget(void *arg, const char *tgt,
374 const char*value, int libtype)
376 cmMakefile *mf = static_cast<cmMakefile *>(arg);
378 switch (libtype)
380 case CM_LIBRARY_GENERAL:
381 mf->AddLinkLibraryForTarget(tgt,value, cmTarget::GENERAL);
382 break;
383 case CM_LIBRARY_DEBUG:
384 mf->AddLinkLibraryForTarget(tgt,value, cmTarget::DEBUG);
385 break;
386 case CM_LIBRARY_OPTIMIZED:
387 mf->AddLinkLibraryForTarget(tgt,value, cmTarget::OPTIMIZED);
388 break;
392 void CCONV cmAddLibrary(void *arg, const char *libname, int shared,
393 int numSrcs, const char **srcs)
395 cmMakefile *mf = static_cast<cmMakefile *>(arg);
396 std::vector<std::string> srcs2;
397 int i;
398 for (i = 0; i < numSrcs; ++i)
400 srcs2.push_back(srcs[i]);
402 mf->AddLibrary(libname,
403 (shared? cmTarget::SHARED_LIBRARY : cmTarget::STATIC_LIBRARY),
404 srcs2);
407 char CCONV *cmExpandVariablesInString(void *arg, const char *source,
408 int escapeQuotes, int atOnly)
410 cmMakefile *mf = static_cast<cmMakefile *>(arg);
411 std::string barf = source;
412 std::string result =
413 mf->ExpandVariablesInString(barf,
414 (escapeQuotes ? true : false),
415 (atOnly ? true : false));
416 char *res = static_cast<char *>(malloc(result.size() + 1));
417 if (result.size())
419 strcpy(res,result.c_str());
421 res[result.size()] = '\0';
422 return res;
426 int CCONV cmExecuteCommand(void *arg, const char *name,
427 int numArgs, const char **args)
429 cmMakefile *mf = static_cast<cmMakefile *>(arg);
430 cmListFileFunction lff;
431 lff.Name = name;
432 for(int i = 0; i < numArgs; ++i)
434 // Assume all arguments are quoted.
435 lff.Arguments.push_back(cmListFileArgument(args[i], true,
436 "[CMake-Plugin]", 0));
438 cmExecutionStatus status;
439 return mf->ExecuteCommand(lff,status);
442 void CCONV cmExpandSourceListArguments(void *arg,
443 int numArgs,
444 const char **args,
445 int *resArgc,
446 char ***resArgv,
447 unsigned int startArgumentIndex)
449 cmMakefile *mf = static_cast<cmMakefile *>(arg);
450 std::vector<std::string> result;
451 std::vector<std::string> args2;
452 int i;
453 for (i = 0; i < numArgs; ++i)
455 args2.push_back(args[i]);
457 mf->ExpandSourceListArguments(args2, result, startArgumentIndex);
458 int resargc = static_cast<int>(result.size());
459 char **resargv = 0;
460 if (resargc)
462 resargv = (char **)malloc(resargc*sizeof(char *));
464 for (i = 0; i < resargc; ++i)
466 resargv[i] = strdup(result[i].c_str());
468 *resArgc = resargc;
469 *resArgv = resargv;
472 void CCONV cmFreeArguments(int argc, char **argv)
474 int i;
475 for (i = 0; i < argc; ++i)
477 free(argv[i]);
479 if (argv)
481 free(argv);
485 int CCONV cmGetTotalArgumentSize(int argc, char **argv)
487 int i;
488 int result = 0;
489 for (i = 0; i < argc; ++i)
491 if (argv[i])
493 result = result + static_cast<int>(strlen(argv[i]));
496 return result;
499 // Source file proxy object to support the old cmSourceFile/cmMakefile
500 // API for source files.
501 struct cmCPluginAPISourceFile
503 cmCPluginAPISourceFile(): RealSourceFile(0) {}
504 cmSourceFile* RealSourceFile;
505 std::string SourceName;
506 std::string SourceExtension;
507 std::string FullPath;
508 std::vector<std::string> Depends;
509 cmPropertyMap Properties;
512 // Keep a map from real cmSourceFile instances stored in a makefile to
513 // the CPluginAPI proxy source file.
514 class cmCPluginAPISourceFileMap:
515 public std::map<cmSourceFile*, cmCPluginAPISourceFile*>
517 public:
518 typedef std::map<cmSourceFile*, cmCPluginAPISourceFile*> derived;
519 typedef derived::iterator iterator;
520 typedef derived::value_type value_type;
521 ~cmCPluginAPISourceFileMap()
523 for(iterator i=this->begin(); i != this->end(); ++i)
525 delete i->second;
529 cmCPluginAPISourceFileMap cmCPluginAPISourceFiles;
531 void * CCONV cmCreateSourceFile()
533 return (void*)new cmCPluginAPISourceFile;
536 void * CCONV cmCreateNewSourceFile(void *arg)
538 cmMakefile *mf = static_cast<cmMakefile *>(arg);
539 cmCPluginAPISourceFile *sf = new cmCPluginAPISourceFile;
540 sf->Properties.SetCMakeInstance(mf->GetCMakeInstance());
541 return (void*)sf;
544 void CCONV cmDestroySourceFile(void *arg)
546 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
547 // Only delete if it was created by cmCreateSourceFile or
548 // cmCreateNewSourceFile and is therefore not in the map.
549 if(!sf->RealSourceFile)
551 delete sf;
555 void CCONV *cmGetSource(void *arg, const char *name)
557 cmMakefile *mf = static_cast<cmMakefile *>(arg);
558 if(cmSourceFile* rsf = mf->GetSource(name))
560 // Lookup the proxy source file object for this source.
561 cmCPluginAPISourceFileMap::iterator i = cmCPluginAPISourceFiles.find(rsf);
562 if(i == cmCPluginAPISourceFiles.end())
564 // Create a proxy source file object for this source.
565 cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile;
566 sf->RealSourceFile = rsf;
567 sf->FullPath = rsf->GetFullPath();
568 sf->SourceName =
569 cmSystemTools::GetFilenameWithoutLastExtension(sf->FullPath.c_str());
570 sf->SourceExtension =
571 cmSystemTools::GetFilenameLastExtension(sf->FullPath.c_str());
573 // Store the proxy in the map so it can be re-used and deleted later.
574 cmCPluginAPISourceFileMap::value_type entry(rsf, sf);
575 i = cmCPluginAPISourceFiles.insert(entry).first;
577 return (void *)i->second;
579 else
581 return 0;
585 void * CCONV cmAddSource(void *arg, void *arg2)
587 cmMakefile *mf = static_cast<cmMakefile *>(arg);
588 cmCPluginAPISourceFile* osf = static_cast<cmCPluginAPISourceFile*>(arg2);
589 if(osf->FullPath.empty())
591 return 0;
594 // Create the real cmSourceFile instance and copy over saved information.
595 cmSourceFile* rsf = mf->GetOrCreateSource(osf->FullPath.c_str());
596 rsf->GetProperties() = osf->Properties;
597 for(std::vector<std::string>::iterator i = osf->Depends.begin();
598 i != osf->Depends.end(); ++i)
600 rsf->AddDepend(i->c_str());
603 // Create the proxy for the real source file.
604 cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile;
605 sf->RealSourceFile = rsf;
606 sf->FullPath = osf->FullPath;
607 sf->SourceName = osf->SourceName;
608 sf->SourceExtension = osf->SourceExtension;
610 // Store the proxy in the map so it can be re-used and deleted later.
611 cmCPluginAPISourceFiles[rsf] = sf;
612 return (void *)sf;
615 const char * CCONV cmSourceFileGetSourceName(void *arg)
617 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
618 return sf->SourceName.c_str();
621 const char * CCONV cmSourceFileGetFullPath(void *arg)
623 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
624 return sf->FullPath.c_str();
627 const char * CCONV cmSourceFileGetProperty(void *arg,const char *prop)
629 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
630 if(cmSourceFile* rsf = sf->RealSourceFile)
632 return rsf->GetProperty(prop);
634 else
636 if(!strcmp(prop,"LOCATION"))
638 return sf->FullPath.c_str();
640 bool chain = false;
641 // Ignore chain because old code will not expect it and it is a
642 // pain to implement here anyway.
643 return sf->Properties.GetPropertyValue(prop, cmProperty::SOURCE_FILE,
644 chain);
648 int CCONV cmSourceFileGetPropertyAsBool(void *arg,const char *prop)
650 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
651 if(cmSourceFile* rsf = sf->RealSourceFile)
653 return rsf->GetPropertyAsBool(prop) ? 1:0;
655 else
657 return cmSystemTools::IsOn(cmSourceFileGetProperty(arg, prop))? 1:0;
661 void CCONV cmSourceFileSetProperty(void *arg,const char *prop,
662 const char *value)
664 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
665 if(cmSourceFile* rsf = sf->RealSourceFile)
667 rsf->SetProperty(prop, value);
669 else if(prop)
671 if(!value) { value = "NOTFOUND"; }
672 sf->Properties.SetProperty(prop, value, cmProperty::SOURCE_FILE);
676 void CCONV cmSourceFileAddDepend(void *arg, const char *depend)
678 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
679 if(cmSourceFile* rsf = sf->RealSourceFile)
681 rsf->AddDepend(depend);
683 else
685 sf->Depends.push_back(depend);
689 void CCONV cmSourceFileSetName(void *arg, const char* name, const char* dir,
690 int numSourceExtensions,
691 const char **sourceExtensions,
692 int numHeaderExtensions,
693 const char **headerExtensions)
695 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
696 if(sf->RealSourceFile)
698 // SetName is allowed only on temporary source files created by
699 // the command for building and passing to AddSource.
700 return;
702 std::vector<std::string> sourceExts;
703 std::vector<std::string> headerExts;
704 int i;
705 for (i = 0; i < numSourceExtensions; ++i)
707 sourceExts.push_back(sourceExtensions[i]);
709 for (i = 0; i < numHeaderExtensions; ++i)
711 headerExts.push_back(headerExtensions[i]);
714 // Save the original name given.
715 sf->SourceName = name;
717 // Convert the name to a full path in case the given name is a
718 // relative path.
719 std::string pathname = cmSystemTools::CollapseFullPath(name, dir);
721 // First try and see whether the listed file can be found
722 // as is without extensions added on.
723 std::string hname = pathname;
724 if(cmSystemTools::FileExists(hname.c_str()))
726 sf->SourceName = cmSystemTools::GetFilenamePath(name);
727 if ( sf->SourceName.size() > 0 )
729 sf->SourceName += "/";
731 sf->SourceName += cmSystemTools::GetFilenameWithoutLastExtension(name);
732 std::string::size_type pos = hname.rfind('.');
733 if(pos != std::string::npos)
735 sf->SourceExtension = hname.substr(pos+1, hname.size()-pos);
736 if ( cmSystemTools::FileIsFullPath(name) )
738 std::string::size_type pos2 = hname.rfind('/');
739 if(pos2 != std::string::npos)
741 sf->SourceName = hname.substr(pos2+1, pos - pos2-1);
746 sf->FullPath = hname;
747 return;
750 // Next, try the various source extensions
751 for( std::vector<std::string>::const_iterator ext = sourceExts.begin();
752 ext != sourceExts.end(); ++ext )
754 hname = pathname;
755 hname += ".";
756 hname += *ext;
757 if(cmSystemTools::FileExists(hname.c_str()))
759 sf->SourceExtension = *ext;
760 sf->FullPath = hname;
761 return;
765 // Finally, try the various header extensions
766 for( std::vector<std::string>::const_iterator ext = headerExts.begin();
767 ext != headerExts.end(); ++ext )
769 hname = pathname;
770 hname += ".";
771 hname += *ext;
772 if(cmSystemTools::FileExists(hname.c_str()))
774 sf->SourceExtension = *ext;
775 sf->FullPath = hname;
776 return;
780 cmOStringStream e;
781 e << "Cannot find source file \"" << pathname << "\"";
782 e << "\n\nTried extensions";
783 for( std::vector<std::string>::const_iterator ext = sourceExts.begin();
784 ext != sourceExts.end(); ++ext )
786 e << " ." << *ext;
788 for( std::vector<std::string>::const_iterator ext = headerExts.begin();
789 ext != headerExts.end(); ++ext )
791 e << " ." << *ext;
793 cmSystemTools::Error(e.str().c_str());
794 return;
797 void CCONV cmSourceFileSetName2(void *arg, const char* name, const char* dir,
798 const char *ext, int headerFileOnly)
800 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
801 if(sf->RealSourceFile)
803 // SetName is allowed only on temporary source files created by
804 // the command for building and passing to AddSource.
805 return;
808 // Implement the old SetName method code here.
809 if(headerFileOnly)
811 sf->Properties.SetProperty("HEADER_FILE_ONLY", "1",
812 cmProperty::SOURCE_FILE);
814 sf->SourceName = name;
815 std::string fname = sf->SourceName;
816 if(ext && strlen(ext))
818 fname += ".";
819 fname += ext;
821 sf->FullPath = cmSystemTools::CollapseFullPath(fname.c_str(), dir);
822 cmSystemTools::ConvertToUnixSlashes(sf->FullPath);
823 sf->SourceExtension = ext;
826 char * CCONV cmGetFilenameWithoutExtension(const char *name)
828 std::string sres = cmSystemTools::GetFilenameWithoutExtension(name);
829 char *result = (char *)malloc(sres.size()+1);
830 strcpy(result,sres.c_str());
831 return result;
834 char * CCONV cmGetFilenamePath(const char *name)
836 std::string sres = cmSystemTools::GetFilenamePath(name);
837 char *result = (char *)malloc(sres.size()+1);
838 strcpy(result,sres.c_str());
839 return result;
842 char * CCONV cmCapitalized(const char *name)
844 std::string sres = cmSystemTools::Capitalized(name);
845 char *result = (char *)malloc(sres.size()+1);
846 strcpy(result,sres.c_str());
847 return result;
850 void CCONV cmCopyFileIfDifferent(const char *name1, const char *name2)
852 cmSystemTools::CopyFileIfDifferent(name1,name2);
855 void CCONV cmRemoveFile(const char *name)
857 cmSystemTools::RemoveFile(name);
860 void CCONV cmDisplayStatus(void *arg, const char* message)
862 cmMakefile *mf = static_cast<cmMakefile *>(arg);
863 mf->DisplayStatus(message, -1);
866 void CCONV cmFree(void *data)
868 free(data);
871 void CCONV DefineSourceFileProperty (void *arg, const char *name,
872 const char *briefDocs,
873 const char *longDocs,
874 int chained)
876 cmMakefile *mf = static_cast<cmMakefile *>(arg);
877 mf->GetCMakeInstance()->DefineProperty(name,cmProperty::SOURCE_FILE,
878 briefDocs, longDocs,
879 chained != 0);
882 } // close the extern "C" scope
884 cmCAPI cmStaticCAPI =
886 cmGetClientData,
887 cmGetTotalArgumentSize,
888 cmFreeArguments,
889 cmSetClientData,
890 cmSetError,
891 cmAddCacheDefinition,
892 cmAddCustomCommand,
893 cmAddDefineFlag,
894 cmAddDefinition,
895 cmAddExecutable,
896 cmAddLibrary,
897 cmAddLinkDirectoryForTarget,
898 cmAddLinkLibraryForTarget,
899 cmAddUtilityCommand,
900 cmCommandExists,
901 cmExecuteCommand,
902 cmExpandSourceListArguments,
903 cmExpandVariablesInString,
904 cmGetCacheMajorVersion,
905 cmGetCacheMinorVersion,
906 cmGetCurrentDirectory,
907 cmGetCurrentOutputDirectory,
908 cmGetDefinition,
909 cmGetHomeDirectory,
910 cmGetHomeOutputDirectory,
911 cmGetMajorVersion,
912 cmGetMinorVersion,
913 cmGetProjectName,
914 cmGetStartDirectory,
915 cmGetStartOutputDirectory,
916 cmIsOn,
918 cmAddSource,
919 cmCreateSourceFile,
920 cmDestroySourceFile,
921 cmGetSource,
922 cmSourceFileAddDepend,
923 cmSourceFileGetProperty,
924 cmSourceFileGetPropertyAsBool,
925 cmSourceFileGetSourceName,
926 cmSourceFileGetFullPath,
927 cmSourceFileSetName,
928 cmSourceFileSetName2,
929 cmSourceFileSetProperty,
931 cmCapitalized,
932 cmCopyFileIfDifferent,
933 cmGetFilenameWithoutExtension,
934 cmGetFilenamePath,
935 cmRemoveFile,
936 cmFree,
938 cmAddCustomCommandToOutput,
939 cmAddCustomCommandToTarget,
940 cmDisplayStatus,
941 cmCreateNewSourceFile,
942 DefineSourceFileProperty,