Introduce "generator expressions" to add_test()
[cmake.git] / Source / cmCPluginAPI.cxx
blob195145f42ba46109dfe4631921d1279b26906d16
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCPluginAPI.cxx,v $
5 Language: C++
6 Date: $Date: 2009-03-16 18:30:24 $
7 Version: $Revision: 1.43 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
18 this file contains the implementation of the C API to CMake. Generally
19 these routines just manipulate arguments and then call the associated
20 methods on the CMake classes. */
22 #include "cmMakefile.h"
23 #include "cmCPluginAPI.h"
24 #include "cmVersion.h"
26 #include "cmSourceFile.h"
28 #include <stdlib.h>
30 #ifdef __QNX__
31 # include <malloc.h> /* for malloc/free on QNX */
32 #endif
34 extern "C"
37 void CCONV *cmGetClientData(void *info)
39 return ((cmLoadedCommandInfo *)info)->ClientData;
42 void CCONV cmSetClientData(void *info, void *cd)
44 ((cmLoadedCommandInfo *)info)->ClientData = cd;
47 void CCONV cmSetError(void *info, const char *err)
49 if (((cmLoadedCommandInfo *)info)->Error)
51 free(((cmLoadedCommandInfo *)info)->Error);
53 ((cmLoadedCommandInfo *)info)->Error = strdup(err);
56 unsigned int CCONV cmGetCacheMajorVersion(void *arg)
58 cmMakefile *mf = static_cast<cmMakefile *>(arg);
59 return mf->GetCacheMajorVersion();
61 unsigned int CCONV cmGetCacheMinorVersion(void *arg)
63 cmMakefile *mf = static_cast<cmMakefile *>(arg);
64 return mf->GetCacheMinorVersion();
67 unsigned int CCONV cmGetMajorVersion(void *)
69 return cmVersion::GetMajorVersion();
72 unsigned int CCONV cmGetMinorVersion(void *)
74 return cmVersion::GetMinorVersion();
77 void CCONV cmAddDefinition(void *arg, const char* name, const char* value)
79 cmMakefile *mf = static_cast<cmMakefile *>(arg);
80 mf->AddDefinition(name,value);
83 /* Add a definition to this makefile and the global cmake cache. */
84 void CCONV cmAddCacheDefinition(void *arg, const char* name,
85 const char* value, const char* doc, int type)
87 cmMakefile *mf = static_cast<cmMakefile *>(arg);
89 switch (type)
91 case CM_CACHE_BOOL:
92 mf->AddCacheDefinition(name,value,doc,
93 cmCacheManager::BOOL);
94 break;
95 case CM_CACHE_PATH:
96 mf->AddCacheDefinition(name,value,doc,
97 cmCacheManager::PATH);
98 break;
99 case CM_CACHE_FILEPATH:
100 mf->AddCacheDefinition(name,value,doc,
101 cmCacheManager::FILEPATH);
102 break;
103 case CM_CACHE_STRING:
104 mf->AddCacheDefinition(name,value,doc,
105 cmCacheManager::STRING);
106 break;
107 case CM_CACHE_INTERNAL:
108 mf->AddCacheDefinition(name,value,doc,
109 cmCacheManager::INTERNAL);
110 break;
111 case CM_CACHE_STATIC:
112 mf->AddCacheDefinition(name,value,doc,
113 cmCacheManager::STATIC);
114 break;
118 const char* CCONV cmGetProjectName(void *arg)
120 cmMakefile *mf = static_cast<cmMakefile *>(arg);
121 return mf->GetProjectName();
124 const char* CCONV cmGetHomeDirectory(void *arg)
126 cmMakefile *mf = static_cast<cmMakefile *>(arg);
127 return mf->GetHomeDirectory();
129 const char* CCONV cmGetHomeOutputDirectory(void *arg)
131 cmMakefile *mf = static_cast<cmMakefile *>(arg);
132 return mf->GetHomeOutputDirectory();
134 const char* CCONV cmGetStartDirectory(void *arg)
136 cmMakefile *mf = static_cast<cmMakefile *>(arg);
137 return mf->GetStartDirectory();
139 const char* CCONV cmGetStartOutputDirectory(void *arg)
141 cmMakefile *mf = static_cast<cmMakefile *>(arg);
142 return mf->GetStartOutputDirectory();
144 const char* CCONV cmGetCurrentDirectory(void *arg)
146 cmMakefile *mf = static_cast<cmMakefile *>(arg);
147 return mf->GetCurrentDirectory();
149 const char* CCONV cmGetCurrentOutputDirectory(void *arg)
151 cmMakefile *mf = static_cast<cmMakefile *>(arg);
152 return mf->GetCurrentOutputDirectory();
154 const char* CCONV cmGetDefinition(void *arg,const char*def)
156 cmMakefile *mf = static_cast<cmMakefile *>(arg);
157 return mf->GetDefinition(def);
160 int CCONV cmIsOn(void *arg, const char* name)
162 cmMakefile *mf = static_cast<cmMakefile *>(arg);
163 return static_cast<int>(mf->IsOn(name));
166 /** Check if a command exists. */
167 int CCONV cmCommandExists(void *arg, const char* name)
169 cmMakefile *mf = static_cast<cmMakefile *>(arg);
170 return static_cast<int>(mf->CommandExists(name));
173 void CCONV cmAddDefineFlag(void *arg, const char* definition)
175 cmMakefile *mf = static_cast<cmMakefile *>(arg);
176 mf->AddDefineFlag(definition);
179 void CCONV cmAddLinkDirectoryForTarget(void *arg, const char *tgt,
180 const char* d)
182 cmMakefile *mf = static_cast<cmMakefile *>(arg);
183 mf->AddLinkDirectoryForTarget(tgt,d);
187 void CCONV cmAddExecutable(void *arg, const char *exename,
188 int numSrcs, const char **srcs, int win32)
190 cmMakefile *mf = static_cast<cmMakefile *>(arg);
191 std::vector<std::string> srcs2;
192 int i;
193 for (i = 0; i < numSrcs; ++i)
195 srcs2.push_back(srcs[i]);
197 cmTarget* tg = mf->AddExecutable(exename, srcs2);
198 if ( win32 )
200 tg->SetProperty("WIN32_EXECUTABLE", "ON");
204 void CCONV cmAddUtilityCommand(void *arg, const char* utilityName,
205 const char* command,
206 const char* arguments,
207 int all,
208 int numDepends,
209 const char **depends,
210 int,
211 const char **)
213 // Get the makefile instance. Perform an extra variable expansion
214 // now because the API caller expects it.
215 cmMakefile* mf = static_cast<cmMakefile*>(arg);
217 // Construct the command line for the command.
218 cmCustomCommandLine commandLine;
219 std::string expand = command;
220 commandLine.push_back(mf->ExpandVariablesInString(expand));
221 if(arguments && arguments[0])
223 // TODO: Parse arguments!
224 expand = arguments;
225 commandLine.push_back(mf->ExpandVariablesInString(expand));
227 cmCustomCommandLines commandLines;
228 commandLines.push_back(commandLine);
230 // Accumulate the list of dependencies.
231 std::vector<std::string> depends2;
232 for(int i = 0; i < numDepends; ++i)
234 expand = depends[i];
235 depends2.push_back(mf->ExpandVariablesInString(expand));
238 // Pass the call to the makefile instance.
239 mf->AddUtilityCommand(utilityName, (all ? false : true),
240 0, depends2, commandLines);
242 void CCONV cmAddCustomCommand(void *arg, const char* source,
243 const char* command,
244 int numArgs, const char **args,
245 int numDepends, const char **depends,
246 int numOutputs, const char **outputs,
247 const char *target)
249 // Get the makefile instance. Perform an extra variable expansion
250 // now because the API caller expects it.
251 cmMakefile* mf = static_cast<cmMakefile*>(arg);
253 // Construct the command line for the command.
254 cmCustomCommandLine commandLine;
255 std::string expand = command;
256 commandLine.push_back(mf->ExpandVariablesInString(expand));
257 for(int i=0; i < numArgs; ++i)
259 expand = args[i];
260 commandLine.push_back(mf->ExpandVariablesInString(expand));
262 cmCustomCommandLines commandLines;
263 commandLines.push_back(commandLine);
265 // Accumulate the list of dependencies.
266 std::vector<std::string> depends2;
267 for(int i = 0; i < numDepends; ++i)
269 expand = depends[i];
270 depends2.push_back(mf->ExpandVariablesInString(expand));
273 // Accumulate the list of outputs.
274 std::vector<std::string> outputs2;
275 for(int i = 0; i < numOutputs; ++i)
277 expand = outputs[i];
278 outputs2.push_back(mf->ExpandVariablesInString(expand));
281 // Pass the call to the makefile instance.
282 const char* no_comment = 0;
283 mf->AddCustomCommandOldStyle(target, outputs2, depends2, source,
284 commandLines, no_comment);
287 void CCONV cmAddCustomCommandToOutput(void *arg, const char* output,
288 const char* command,
289 int numArgs, const char **args,
290 const char* main_dependency,
291 int numDepends, const char **depends)
293 // Get the makefile instance. Perform an extra variable expansion
294 // now because the API caller expects it.
295 cmMakefile* mf = static_cast<cmMakefile*>(arg);
297 // Construct the command line for the command.
298 cmCustomCommandLine commandLine;
299 std::string expand = command;
300 commandLine.push_back(mf->ExpandVariablesInString(expand));
301 for(int i=0; i < numArgs; ++i)
303 expand = args[i];
304 commandLine.push_back(mf->ExpandVariablesInString(expand));
306 cmCustomCommandLines commandLines;
307 commandLines.push_back(commandLine);
309 // Accumulate the list of dependencies.
310 std::vector<std::string> depends2;
311 for(int i = 0; i < numDepends; ++i)
313 expand = depends[i];
314 depends2.push_back(mf->ExpandVariablesInString(expand));
317 // Pass the call to the makefile instance.
318 const char* no_comment = 0;
319 const char* no_working_dir = 0;
320 mf->AddCustomCommandToOutput(output, depends2, main_dependency,
321 commandLines, no_comment, no_working_dir);
324 void CCONV cmAddCustomCommandToTarget(void *arg, const char* target,
325 const char* command,
326 int numArgs, const char **args,
327 int commandType)
329 // Get the makefile instance.
330 cmMakefile* mf = static_cast<cmMakefile*>(arg);
332 // Construct the command line for the command. Perform an extra
333 // variable expansion now because the API caller expects it.
334 cmCustomCommandLine commandLine;
335 std::string expand = command;
336 commandLine.push_back(mf->ExpandVariablesInString(expand));
337 for(int i=0; i < numArgs; ++i)
339 expand = args[i];
340 commandLine.push_back(mf->ExpandVariablesInString(expand));
342 cmCustomCommandLines commandLines;
343 commandLines.push_back(commandLine);
345 // Select the command type.
346 cmTarget::CustomCommandType cctype = cmTarget::POST_BUILD;
347 switch (commandType)
349 case CM_PRE_BUILD:
350 cctype = cmTarget::PRE_BUILD;
351 break;
352 case CM_PRE_LINK:
353 cctype = cmTarget::PRE_LINK;
354 break;
355 case CM_POST_BUILD:
356 cctype = cmTarget::POST_BUILD;
357 break;
360 // Pass the call to the makefile instance.
361 std::vector<std::string> no_depends;
362 const char* no_comment = 0;
363 const char* no_working_dir = 0;
364 mf->AddCustomCommandToTarget(target, no_depends, commandLines,
365 cctype, no_comment, no_working_dir);
368 void CCONV cmAddLinkLibraryForTarget(void *arg, const char *tgt,
369 const char*value, int libtype)
371 cmMakefile *mf = static_cast<cmMakefile *>(arg);
373 switch (libtype)
375 case CM_LIBRARY_GENERAL:
376 mf->AddLinkLibraryForTarget(tgt,value, cmTarget::GENERAL);
377 break;
378 case CM_LIBRARY_DEBUG:
379 mf->AddLinkLibraryForTarget(tgt,value, cmTarget::DEBUG);
380 break;
381 case CM_LIBRARY_OPTIMIZED:
382 mf->AddLinkLibraryForTarget(tgt,value, cmTarget::OPTIMIZED);
383 break;
387 void CCONV cmAddLibrary(void *arg, const char *libname, int shared,
388 int numSrcs, const char **srcs)
390 cmMakefile *mf = static_cast<cmMakefile *>(arg);
391 std::vector<std::string> srcs2;
392 int i;
393 for (i = 0; i < numSrcs; ++i)
395 srcs2.push_back(srcs[i]);
397 mf->AddLibrary(libname,
398 (shared? cmTarget::SHARED_LIBRARY : cmTarget::STATIC_LIBRARY),
399 srcs2);
402 char CCONV *cmExpandVariablesInString(void *arg, const char *source,
403 int escapeQuotes, int atOnly)
405 cmMakefile *mf = static_cast<cmMakefile *>(arg);
406 std::string barf = source;
407 std::string result =
408 mf->ExpandVariablesInString(barf,
409 (escapeQuotes ? true : false),
410 (atOnly ? true : false));
411 char *res = static_cast<char *>(malloc(result.size() + 1));
412 if (result.size())
414 strcpy(res,result.c_str());
416 res[result.size()] = '\0';
417 return res;
421 int CCONV cmExecuteCommand(void *arg, const char *name,
422 int numArgs, const char **args)
424 cmMakefile *mf = static_cast<cmMakefile *>(arg);
425 cmListFileFunction lff;
426 lff.Name = name;
427 for(int i = 0; i < numArgs; ++i)
429 // Assume all arguments are quoted.
430 lff.Arguments.push_back(cmListFileArgument(args[i], true,
431 "[CMake-Plugin]", 0));
433 cmExecutionStatus status;
434 return mf->ExecuteCommand(lff,status);
437 void CCONV cmExpandSourceListArguments(void *arg,
438 int numArgs,
439 const char **args,
440 int *resArgc,
441 char ***resArgv,
442 unsigned int startArgumentIndex)
444 cmMakefile *mf = static_cast<cmMakefile *>(arg);
445 std::vector<std::string> result;
446 std::vector<std::string> args2;
447 int i;
448 for (i = 0; i < numArgs; ++i)
450 args2.push_back(args[i]);
452 mf->ExpandSourceListArguments(args2, result, startArgumentIndex);
453 int resargc = static_cast<int>(result.size());
454 char **resargv = 0;
455 if (resargc)
457 resargv = (char **)malloc(resargc*sizeof(char *));
459 for (i = 0; i < resargc; ++i)
461 resargv[i] = strdup(result[i].c_str());
463 *resArgc = resargc;
464 *resArgv = resargv;
467 void CCONV cmFreeArguments(int argc, char **argv)
469 int i;
470 for (i = 0; i < argc; ++i)
472 free(argv[i]);
474 if (argv)
476 free(argv);
480 int CCONV cmGetTotalArgumentSize(int argc, char **argv)
482 int i;
483 int result = 0;
484 for (i = 0; i < argc; ++i)
486 if (argv[i])
488 result = result + static_cast<int>(strlen(argv[i]));
491 return result;
494 // Source file proxy object to support the old cmSourceFile/cmMakefile
495 // API for source files.
496 struct cmCPluginAPISourceFile
498 cmCPluginAPISourceFile(): RealSourceFile(0) {}
499 cmSourceFile* RealSourceFile;
500 std::string SourceName;
501 std::string SourceExtension;
502 std::string FullPath;
503 std::vector<std::string> Depends;
504 cmPropertyMap Properties;
507 // Keep a map from real cmSourceFile instances stored in a makefile to
508 // the CPluginAPI proxy source file.
509 class cmCPluginAPISourceFileMap:
510 public std::map<cmSourceFile*, cmCPluginAPISourceFile*>
512 public:
513 typedef std::map<cmSourceFile*, cmCPluginAPISourceFile*> derived;
514 typedef derived::iterator iterator;
515 typedef derived::value_type value_type;
516 ~cmCPluginAPISourceFileMap()
518 for(iterator i=this->begin(); i != this->end(); ++i)
520 delete i->second;
524 cmCPluginAPISourceFileMap cmCPluginAPISourceFiles;
526 void * CCONV cmCreateSourceFile()
528 return (void*)new cmCPluginAPISourceFile;
531 void * CCONV cmCreateNewSourceFile(void *arg)
533 cmMakefile *mf = static_cast<cmMakefile *>(arg);
534 cmCPluginAPISourceFile *sf = new cmCPluginAPISourceFile;
535 sf->Properties.SetCMakeInstance(mf->GetCMakeInstance());
536 return (void*)sf;
539 void CCONV cmDestroySourceFile(void *arg)
541 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
542 // Only delete if it was created by cmCreateSourceFile or
543 // cmCreateNewSourceFile and is therefore not in the map.
544 if(!sf->RealSourceFile)
546 delete sf;
550 void CCONV *cmGetSource(void *arg, const char *name)
552 cmMakefile *mf = static_cast<cmMakefile *>(arg);
553 if(cmSourceFile* rsf = mf->GetSource(name))
555 // Lookup the proxy source file object for this source.
556 cmCPluginAPISourceFileMap::iterator i = cmCPluginAPISourceFiles.find(rsf);
557 if(i == cmCPluginAPISourceFiles.end())
559 // Create a proxy source file object for this source.
560 cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile;
561 sf->RealSourceFile = rsf;
562 sf->FullPath = rsf->GetFullPath();
563 sf->SourceName =
564 cmSystemTools::GetFilenameWithoutLastExtension(sf->FullPath.c_str());
565 sf->SourceExtension =
566 cmSystemTools::GetFilenameLastExtension(sf->FullPath.c_str());
568 // Store the proxy in the map so it can be re-used and deleted later.
569 cmCPluginAPISourceFileMap::value_type entry(rsf, sf);
570 i = cmCPluginAPISourceFiles.insert(entry).first;
572 return (void *)i->second;
574 else
576 return 0;
580 void * CCONV cmAddSource(void *arg, void *arg2)
582 cmMakefile *mf = static_cast<cmMakefile *>(arg);
583 cmCPluginAPISourceFile* osf = static_cast<cmCPluginAPISourceFile*>(arg2);
584 if(osf->FullPath.empty())
586 return 0;
589 // Create the real cmSourceFile instance and copy over saved information.
590 cmSourceFile* rsf = mf->GetOrCreateSource(osf->FullPath.c_str());
591 rsf->GetProperties() = osf->Properties;
592 for(std::vector<std::string>::iterator i = osf->Depends.begin();
593 i != osf->Depends.end(); ++i)
595 rsf->AddDepend(i->c_str());
598 // Create the proxy for the real source file.
599 cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile;
600 sf->RealSourceFile = rsf;
601 sf->FullPath = osf->FullPath;
602 sf->SourceName = osf->SourceName;
603 sf->SourceExtension = osf->SourceExtension;
605 // Store the proxy in the map so it can be re-used and deleted later.
606 cmCPluginAPISourceFiles[rsf] = sf;
607 return (void *)sf;
610 const char * CCONV cmSourceFileGetSourceName(void *arg)
612 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
613 return sf->SourceName.c_str();
616 const char * CCONV cmSourceFileGetFullPath(void *arg)
618 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
619 return sf->FullPath.c_str();
622 const char * CCONV cmSourceFileGetProperty(void *arg,const char *prop)
624 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
625 if(cmSourceFile* rsf = sf->RealSourceFile)
627 return rsf->GetProperty(prop);
629 else
631 if(!strcmp(prop,"LOCATION"))
633 return sf->FullPath.c_str();
635 bool chain = false;
636 // Ignore chain because old code will not expect it and it is a
637 // pain to implement here anyway.
638 return sf->Properties.GetPropertyValue(prop, cmProperty::SOURCE_FILE,
639 chain);
643 int CCONV cmSourceFileGetPropertyAsBool(void *arg,const char *prop)
645 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
646 if(cmSourceFile* rsf = sf->RealSourceFile)
648 return rsf->GetPropertyAsBool(prop) ? 1:0;
650 else
652 return cmSystemTools::IsOn(cmSourceFileGetProperty(arg, prop))? 1:0;
656 void CCONV cmSourceFileSetProperty(void *arg,const char *prop,
657 const char *value)
659 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
660 if(cmSourceFile* rsf = sf->RealSourceFile)
662 rsf->SetProperty(prop, value);
664 else if(prop)
666 if(!value) { value = "NOTFOUND"; }
667 sf->Properties.SetProperty(prop, value, cmProperty::SOURCE_FILE);
671 void CCONV cmSourceFileAddDepend(void *arg, const char *depend)
673 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
674 if(cmSourceFile* rsf = sf->RealSourceFile)
676 rsf->AddDepend(depend);
678 else
680 sf->Depends.push_back(depend);
684 void CCONV cmSourceFileSetName(void *arg, const char* name, const char* dir,
685 int numSourceExtensions,
686 const char **sourceExtensions,
687 int numHeaderExtensions,
688 const char **headerExtensions)
690 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
691 if(sf->RealSourceFile)
693 // SetName is allowed only on temporary source files created by
694 // the command for building and passing to AddSource.
695 return;
697 std::vector<std::string> sourceExts;
698 std::vector<std::string> headerExts;
699 int i;
700 for (i = 0; i < numSourceExtensions; ++i)
702 sourceExts.push_back(sourceExtensions[i]);
704 for (i = 0; i < numHeaderExtensions; ++i)
706 headerExts.push_back(headerExtensions[i]);
709 // Save the original name given.
710 sf->SourceName = name;
712 // Convert the name to a full path in case the given name is a
713 // relative path.
714 std::string pathname = cmSystemTools::CollapseFullPath(name, dir);
716 // First try and see whether the listed file can be found
717 // as is without extensions added on.
718 std::string hname = pathname;
719 if(cmSystemTools::FileExists(hname.c_str()))
721 sf->SourceName = cmSystemTools::GetFilenamePath(name);
722 if ( sf->SourceName.size() > 0 )
724 sf->SourceName += "/";
726 sf->SourceName += cmSystemTools::GetFilenameWithoutLastExtension(name);
727 std::string::size_type pos = hname.rfind('.');
728 if(pos != std::string::npos)
730 sf->SourceExtension = hname.substr(pos+1, hname.size()-pos);
731 if ( cmSystemTools::FileIsFullPath(name) )
733 std::string::size_type pos2 = hname.rfind('/');
734 if(pos2 != std::string::npos)
736 sf->SourceName = hname.substr(pos2+1, pos - pos2-1);
741 sf->FullPath = hname;
742 return;
745 // Next, try the various source extensions
746 for( std::vector<std::string>::const_iterator ext = sourceExts.begin();
747 ext != sourceExts.end(); ++ext )
749 hname = pathname;
750 hname += ".";
751 hname += *ext;
752 if(cmSystemTools::FileExists(hname.c_str()))
754 sf->SourceExtension = *ext;
755 sf->FullPath = hname;
756 return;
760 // Finally, try the various header extensions
761 for( std::vector<std::string>::const_iterator ext = headerExts.begin();
762 ext != headerExts.end(); ++ext )
764 hname = pathname;
765 hname += ".";
766 hname += *ext;
767 if(cmSystemTools::FileExists(hname.c_str()))
769 sf->SourceExtension = *ext;
770 sf->FullPath = hname;
771 return;
775 cmOStringStream e;
776 e << "Cannot find source file \"" << pathname << "\"";
777 e << "\n\nTried extensions";
778 for( std::vector<std::string>::const_iterator ext = sourceExts.begin();
779 ext != sourceExts.end(); ++ext )
781 e << " ." << *ext;
783 for( std::vector<std::string>::const_iterator ext = headerExts.begin();
784 ext != headerExts.end(); ++ext )
786 e << " ." << *ext;
788 cmSystemTools::Error(e.str().c_str());
789 return;
792 void CCONV cmSourceFileSetName2(void *arg, const char* name, const char* dir,
793 const char *ext, int headerFileOnly)
795 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
796 if(sf->RealSourceFile)
798 // SetName is allowed only on temporary source files created by
799 // the command for building and passing to AddSource.
800 return;
803 // Implement the old SetName method code here.
804 if(headerFileOnly)
806 sf->Properties.SetProperty("HEADER_FILE_ONLY", "1",
807 cmProperty::SOURCE_FILE);
809 sf->SourceName = name;
810 std::string fname = sf->SourceName;
811 if(ext && strlen(ext))
813 fname += ".";
814 fname += ext;
816 sf->FullPath = cmSystemTools::CollapseFullPath(fname.c_str(), dir);
817 cmSystemTools::ConvertToUnixSlashes(sf->FullPath);
818 sf->SourceExtension = ext;
821 char * CCONV cmGetFilenameWithoutExtension(const char *name)
823 std::string sres = cmSystemTools::GetFilenameWithoutExtension(name);
824 char *result = (char *)malloc(sres.size()+1);
825 strcpy(result,sres.c_str());
826 return result;
829 char * CCONV cmGetFilenamePath(const char *name)
831 std::string sres = cmSystemTools::GetFilenamePath(name);
832 char *result = (char *)malloc(sres.size()+1);
833 strcpy(result,sres.c_str());
834 return result;
837 char * CCONV cmCapitalized(const char *name)
839 std::string sres = cmSystemTools::Capitalized(name);
840 char *result = (char *)malloc(sres.size()+1);
841 strcpy(result,sres.c_str());
842 return result;
845 void CCONV cmCopyFileIfDifferent(const char *name1, const char *name2)
847 cmSystemTools::CopyFileIfDifferent(name1,name2);
850 void CCONV cmRemoveFile(const char *name)
852 cmSystemTools::RemoveFile(name);
855 void CCONV cmDisplayStatus(void *arg, const char* message)
857 cmMakefile *mf = static_cast<cmMakefile *>(arg);
858 mf->DisplayStatus(message, -1);
861 void CCONV cmFree(void *data)
863 free(data);
866 void CCONV DefineSourceFileProperty (void *arg, const char *name,
867 const char *briefDocs,
868 const char *longDocs,
869 int chained)
871 cmMakefile *mf = static_cast<cmMakefile *>(arg);
872 mf->GetCMakeInstance()->DefineProperty(name,cmProperty::SOURCE_FILE,
873 briefDocs, longDocs,
874 chained != 0);
877 } // close the extern "C" scope
879 cmCAPI cmStaticCAPI =
881 cmGetClientData,
882 cmGetTotalArgumentSize,
883 cmFreeArguments,
884 cmSetClientData,
885 cmSetError,
886 cmAddCacheDefinition,
887 cmAddCustomCommand,
888 cmAddDefineFlag,
889 cmAddDefinition,
890 cmAddExecutable,
891 cmAddLibrary,
892 cmAddLinkDirectoryForTarget,
893 cmAddLinkLibraryForTarget,
894 cmAddUtilityCommand,
895 cmCommandExists,
896 cmExecuteCommand,
897 cmExpandSourceListArguments,
898 cmExpandVariablesInString,
899 cmGetCacheMajorVersion,
900 cmGetCacheMinorVersion,
901 cmGetCurrentDirectory,
902 cmGetCurrentOutputDirectory,
903 cmGetDefinition,
904 cmGetHomeDirectory,
905 cmGetHomeOutputDirectory,
906 cmGetMajorVersion,
907 cmGetMinorVersion,
908 cmGetProjectName,
909 cmGetStartDirectory,
910 cmGetStartOutputDirectory,
911 cmIsOn,
913 cmAddSource,
914 cmCreateSourceFile,
915 cmDestroySourceFile,
916 cmGetSource,
917 cmSourceFileAddDepend,
918 cmSourceFileGetProperty,
919 cmSourceFileGetPropertyAsBool,
920 cmSourceFileGetSourceName,
921 cmSourceFileGetFullPath,
922 cmSourceFileSetName,
923 cmSourceFileSetName2,
924 cmSourceFileSetProperty,
926 cmCapitalized,
927 cmCopyFileIfDifferent,
928 cmGetFilenameWithoutExtension,
929 cmGetFilenamePath,
930 cmRemoveFile,
931 cmFree,
933 cmAddCustomCommandToOutput,
934 cmAddCustomCommandToTarget,
935 cmDisplayStatus,
936 cmCreateNewSourceFile,
937 DefineSourceFileProperty,