BUG: Fix find_* search order with path suffixes
[cmake.git] / Source / cmCPluginAPI.cxx
blobe213549806d53b697b3319989175a90bc41462fa
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCPluginAPI.cxx,v $
5 Language: C++
6 Date: $Date: 2008-01-23 15:27:59 $
7 Version: $Revision: 1.42 $
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 // Implement the old SetName method code here.
710 sf->Properties.SetProperty("HEADER_FILE_ONLY", "1",
711 cmProperty::SOURCE_FILE);
713 // Save the original name given.
714 sf->SourceName = name;
716 // Convert the name to a full path in case the given name is a
717 // relative path.
718 std::string pathname = cmSystemTools::CollapseFullPath(name, dir);
720 // First try and see whether the listed file can be found
721 // as is without extensions added on.
722 std::string hname = pathname;
723 if(cmSystemTools::FileExists(hname.c_str()))
725 sf->SourceName = cmSystemTools::GetFilenamePath(name);
726 if ( sf->SourceName.size() > 0 )
728 sf->SourceName += "/";
730 sf->SourceName += cmSystemTools::GetFilenameWithoutLastExtension(name);
731 std::string::size_type pos = hname.rfind('.');
732 if(pos != std::string::npos)
734 sf->SourceExtension = hname.substr(pos+1, hname.size()-pos);
735 if ( cmSystemTools::FileIsFullPath(name) )
737 std::string::size_type pos2 = hname.rfind('/');
738 if(pos2 != std::string::npos)
740 sf->SourceName = hname.substr(pos2+1, pos - pos2-1);
745 // See if the file is a header file
746 if(std::find( headerExts.begin(), headerExts.end(),
747 sf->SourceExtension ) == headerExts.end())
749 sf->Properties.SetProperty("HEADER_FILE_ONLY", "0",
750 cmProperty::SOURCE_FILE);
752 sf->FullPath = hname;
753 return;
756 // Next, try the various source extensions
757 for( std::vector<std::string>::const_iterator ext = sourceExts.begin();
758 ext != sourceExts.end(); ++ext )
760 hname = pathname;
761 hname += ".";
762 hname += *ext;
763 if(cmSystemTools::FileExists(hname.c_str()))
765 sf->SourceExtension = *ext;
766 sf->Properties.SetProperty("HEADER_FILE_ONLY", "0",
767 cmProperty::SOURCE_FILE);
768 sf->FullPath = hname;
769 return;
773 // Finally, try the various header extensions
774 for( std::vector<std::string>::const_iterator ext = headerExts.begin();
775 ext != headerExts.end(); ++ext )
777 hname = pathname;
778 hname += ".";
779 hname += *ext;
780 if(cmSystemTools::FileExists(hname.c_str()))
782 sf->SourceExtension = *ext;
783 sf->FullPath = hname;
784 return;
788 cmOStringStream e;
789 e << "Cannot find source file \"" << pathname << "\"";
790 e << "\n\nTried extensions";
791 for( std::vector<std::string>::const_iterator ext = sourceExts.begin();
792 ext != sourceExts.end(); ++ext )
794 e << " ." << *ext;
796 for( std::vector<std::string>::const_iterator ext = headerExts.begin();
797 ext != headerExts.end(); ++ext )
799 e << " ." << *ext;
801 cmSystemTools::Error(e.str().c_str());
802 return;
805 void CCONV cmSourceFileSetName2(void *arg, const char* name, const char* dir,
806 const char *ext, int headerFileOnly)
808 cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
809 if(sf->RealSourceFile)
811 // SetName is allowed only on temporary source files created by
812 // the command for building and passing to AddSource.
813 return;
816 // Implement the old SetName method code here.
817 sf->Properties.SetProperty("HEADER_FILE_ONLY",
818 headerFileOnly? "1" : "0",
819 cmProperty::SOURCE_FILE);
820 sf->SourceName = name;
821 std::string fname = sf->SourceName;
822 if(ext && strlen(ext))
824 fname += ".";
825 fname += ext;
827 sf->FullPath = cmSystemTools::CollapseFullPath(fname.c_str(), dir);
828 cmSystemTools::ConvertToUnixSlashes(sf->FullPath);
829 sf->SourceExtension = ext;
832 char * CCONV cmGetFilenameWithoutExtension(const char *name)
834 std::string sres = cmSystemTools::GetFilenameWithoutExtension(name);
835 char *result = (char *)malloc(sres.size()+1);
836 strcpy(result,sres.c_str());
837 return result;
840 char * CCONV cmGetFilenamePath(const char *name)
842 std::string sres = cmSystemTools::GetFilenamePath(name);
843 char *result = (char *)malloc(sres.size()+1);
844 strcpy(result,sres.c_str());
845 return result;
848 char * CCONV cmCapitalized(const char *name)
850 std::string sres = cmSystemTools::Capitalized(name);
851 char *result = (char *)malloc(sres.size()+1);
852 strcpy(result,sres.c_str());
853 return result;
856 void CCONV cmCopyFileIfDifferent(const char *name1, const char *name2)
858 cmSystemTools::CopyFileIfDifferent(name1,name2);
861 void CCONV cmRemoveFile(const char *name)
863 cmSystemTools::RemoveFile(name);
866 void CCONV cmDisplayStatus(void *arg, const char* message)
868 cmMakefile *mf = static_cast<cmMakefile *>(arg);
869 mf->DisplayStatus(message, -1);
872 void CCONV cmFree(void *data)
874 free(data);
877 void CCONV DefineSourceFileProperty (void *arg, const char *name,
878 const char *briefDocs,
879 const char *longDocs,
880 int chained)
882 cmMakefile *mf = static_cast<cmMakefile *>(arg);
883 mf->GetCMakeInstance()->DefineProperty(name,cmProperty::SOURCE_FILE,
884 briefDocs, longDocs,
885 chained != 0);
888 } // close the extern "C" scope
890 cmCAPI cmStaticCAPI =
892 cmGetClientData,
893 cmGetTotalArgumentSize,
894 cmFreeArguments,
895 cmSetClientData,
896 cmSetError,
897 cmAddCacheDefinition,
898 cmAddCustomCommand,
899 cmAddDefineFlag,
900 cmAddDefinition,
901 cmAddExecutable,
902 cmAddLibrary,
903 cmAddLinkDirectoryForTarget,
904 cmAddLinkLibraryForTarget,
905 cmAddUtilityCommand,
906 cmCommandExists,
907 cmExecuteCommand,
908 cmExpandSourceListArguments,
909 cmExpandVariablesInString,
910 cmGetCacheMajorVersion,
911 cmGetCacheMinorVersion,
912 cmGetCurrentDirectory,
913 cmGetCurrentOutputDirectory,
914 cmGetDefinition,
915 cmGetHomeDirectory,
916 cmGetHomeOutputDirectory,
917 cmGetMajorVersion,
918 cmGetMinorVersion,
919 cmGetProjectName,
920 cmGetStartDirectory,
921 cmGetStartOutputDirectory,
922 cmIsOn,
924 cmAddSource,
925 cmCreateSourceFile,
926 cmDestroySourceFile,
927 cmGetSource,
928 cmSourceFileAddDepend,
929 cmSourceFileGetProperty,
930 cmSourceFileGetPropertyAsBool,
931 cmSourceFileGetSourceName,
932 cmSourceFileGetFullPath,
933 cmSourceFileSetName,
934 cmSourceFileSetName2,
935 cmSourceFileSetProperty,
937 cmCapitalized,
938 cmCopyFileIfDifferent,
939 cmGetFilenameWithoutExtension,
940 cmGetFilenamePath,
941 cmRemoveFile,
942 cmFree,
944 cmAddCustomCommandToOutput,
945 cmAddCustomCommandToTarget,
946 cmDisplayStatus,
947 cmCreateNewSourceFile,
948 DefineSourceFileProperty,