diff options
author | Ken Martin <ken.martin@kitware.com> | 2002-08-21 15:54:06 (GMT) |
---|---|---|
committer | Ken Martin <ken.martin@kitware.com> | 2002-08-21 15:54:06 (GMT) |
commit | 38dfd36fdaad9c7e3767189b23d74c4953614139 (patch) | |
tree | 05ce288ce1165e6add7459264e0b285ff0ea30e7 /Source | |
parent | 5be8fa451a07a51c39670ed59e8c25f7441cceda (diff) | |
download | CMake-38dfd36fdaad9c7e3767189b23d74c4953614139.zip CMake-38dfd36fdaad9c7e3767189b23d74c4953614139.tar.gz CMake-38dfd36fdaad9c7e3767189b23d74c4953614139.tar.bz2 |
added C Plugin API first cut
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCPluginAPI.cxx | 457 | ||||
-rw-r--r-- | Source/cmCPluginAPI.h | 218 |
2 files changed, 675 insertions, 0 deletions
diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx new file mode 100644 index 0000000..33acdea --- /dev/null +++ b/Source/cmCPluginAPI.cxx @@ -0,0 +1,457 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +/* + this file contains the implementation of the C API to CMake. Generally + these routines just manipulate arguments and then call the associated + methods on the CMake classes. */ + +#include "cmMakefile.h" +#include "cmCPluginAPI.h" + +void *cmGetClientData(void *info) +{ + return ((cmLoadedCommandInfo *)info)->ClientData; +} + +void cmSetClientData(void *info, void *cd) +{ + ((cmLoadedCommandInfo *)info)->ClientData = cd; +} + +unsigned int cmGetCacheMajorVersion(void *arg) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + return mf->GetCacheMajorVersion(); +} +unsigned int cmGetCacheMinorVersion(void *arg) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + return mf->GetCacheMinorVersion(); +} + +unsigned int cmGetMajorVersion(void *) +{ + return cmMakefile::GetMajorVersion(); +} + +unsigned int cmGetMinorVersion(void *) +{ + return cmMakefile::GetMinorVersion(); +} + +void cmAddDefinition(void *arg, const char* name, const char* value) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + mf->AddDefinition(name,value); +} + +/* Add a definition to this makefile and the global cmake cache. */ +void cmAddCacheDefinition(void *arg, const char* name, const char* value, + const char* doc, + int type) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + + switch (type) + { + case CM_CACHE_BOOL: + mf->AddCacheDefinition(name,value,doc, + cmCacheManager::CacheEntryType::BOOL); + break; + case CM_CACHE_PATH: + mf->AddCacheDefinition(name,value,doc, + cmCacheManager::CacheEntryType::PATH); + break; + case CM_CACHE_FILEPATH: + mf->AddCacheDefinition(name,value,doc, + cmCacheManager::CacheEntryType::FILEPATH); + break; + case CM_CACHE_STRING: + mf->AddCacheDefinition(name,value,doc, + cmCacheManager::CacheEntryType::STRING); + break; + case CM_CACHE_INTERNAL: + mf->AddCacheDefinition(name,value,doc, + cmCacheManager::CacheEntryType::INTERNAL); + break; + case CM_CACHE_STATIC: + mf->AddCacheDefinition(name,value,doc, + cmCacheManager::CacheEntryType::STATIC); + break; + } +} + +const char* cmGetProjectName(void *arg) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + return mf->GetProjectName(); +} + +const char* cmGetHomeDirectory(void *arg) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + return mf->GetHomeDirectory(); +} +const char* cmGetHomeOutputDirectory(void *arg) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + return mf->GetHomeOutputDirectory(); +} +const char* cmGetStartDirectory(void *arg) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + return mf->GetStartDirectory(); +} +const char* cmGetStartOutputDirectory(void *arg) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + return mf->GetStartOutputDirectory(); +} +const char* cmGetCurrentDirectory(void *arg) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + return mf->GetCurrentDirectory(); +} +const char* cmGetCurrentOutputDirectory(void *arg) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + return mf->GetCurrentOutputDirectory(); +} +const char* cmGetDefinition(void *arg,const char*def) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + return mf->GetDefinition(def); +} + +int cmIsOn(void *arg, const char* name) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + return static_cast<int>(mf->IsOn(name)); +} + +/** Check if a command exists. */ +int cmCommandExists(void *arg, const char* name) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + return static_cast<int>(mf->CommandExists(name)); +} + +void cmAddDefineFlag(void *arg, const char* definition) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + mf->AddDefineFlag(definition); +} + +void cmAddLinkDirectoryForTarget(void *arg, const char *tgt, const char* d) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + mf->AddLinkDirectoryForTarget(tgt,d); +} + + +void cmAddExecutable(void *arg, const char *exename, + int numSrcs, const char **srcs, int win32) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + std::vector<std::string> srcs2; + int i; + for (i = 0; i < numSrcs; ++i) + { + srcs2.push_back(srcs[i]); + } + mf->AddExecutable(exename, srcs2, (win32 ? true : false)); +} + +void cmAddUtilityCommand(void *arg, const char* utilityName, + const char* command, + const char* arguments, + int all, + int numDepends, + const char **depends, + int numOutputs, + const char **outputs) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + std::vector<std::string> depends2; + int i; + for (i = 0; i < numDepends; ++i) + { + depends2.push_back(depends[i]); + } + std::vector<std::string> outputs2; + for (i = 0; i < numOutputs; ++i) + { + outputs2.push_back(outputs[i]); + } + mf->AddUtilityCommand(utilityName,command,arguments, (all ? true : false), + depends2, outputs2); +} +void cmAddCustomCommand(void *arg, const char* source, + const char* command, + int numArgs, const char **args, + int numDepends, const char **depends, + int numOutputs, const char **outputs, + const char *target) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + int i; + std::vector<std::string> args2; + for (i = 0; i < numArgs; ++i) + { + args2.push_back(args[i]); + } + std::vector<std::string> depends2; + for (i = 0; i < numDepends; ++i) + { + depends2.push_back(depends[i]); + } + std::vector<std::string> outputs2; + for (i = 0; i < numOutputs; ++i) + { + outputs2.push_back(outputs[i]); + } + mf->AddCustomCommand(source, command, args2, depends2, outputs2, target); +} + + +void cmAddLinkLibraryForTarget(void *arg, const char *tgt, const char*value, + int libtype) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + + switch (libtype) + { + case CM_LIBRARY_GENERAL: + mf->AddLinkLibraryForTarget(tgt,value, + cmTarget::LinkLibraryType::GENERAL); + break; + case CM_LIBRARY_DEBUG: + mf->AddLinkLibraryForTarget(tgt,value, + cmTarget::LinkLibraryType::DEBUG); + break; + case CM_LIBRARY_OPTIMIZED: + mf->AddLinkLibraryForTarget(tgt,value, + cmTarget::LinkLibraryType::OPTIMIZED); + break; + } +} + +void cmAddLibrary(void *arg, const char *libname, int shared, + int numSrcs, const char **srcs) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + std::vector<std::string> srcs2; + int i; + for (i = 0; i < numSrcs; ++i) + { + srcs2.push_back(srcs[i]); + } + mf->AddLibrary(libname, (shared ? true : false), srcs2); +} + +char *cmExpandVariablesInString(void *arg, const char *source, + int escapeQuotes, int atOnly) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + std::string result = + mf->ExpandVariablesInString(std::string(source), + (escapeQuotes ? true : false), + (atOnly ? true : false)); + char *res = static_cast<char *>(malloc(result.size() + 1)); + if (result.size()) + { + strcpy(res,result.c_str()); + } + res[result.size()] = '\0'; + return res; +} + + +void cmExecuteCommand(void *arg, const char *name, + int numArgs, const char **args) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + std::vector<std::string> args2; + int i; + for (i = 0; i < numArgs; ++i) + { + args2.push_back(args[i]); + } + mf->ExecuteCommand(std::string(name), args2); +} + +void cmExpandSourceListArguments(void *arg, + int numArgs, + const char **args, + int *resArgc, + char ***resArgv, + unsigned int startArgumentIndex) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + std::vector<std::string> result; + std::vector<std::string> args2; + int i; + for (i = 0; i < numArgs; ++i) + { + args2.push_back(args[i]); + } + mf->ExpandSourceListArguments(args2, result, startArgumentIndex); + int resargc = result.size(); + char **resargv = NULL; + if (resargc) + { + resargv = (char **)malloc(resargc*sizeof(char *)); + } + for (i = 0; i < resargc; ++i) + { + resargv[i] = strdup(result[i].c_str()); + } + *resArgc = resargc; + *resArgv = resargv; +} + +void cmFreeArguments(int argc, char **argv) +{ + int i; + for (i = 0; i < argc; ++i) + { + free(argv[i]); + } + if (argv) + { + free(argv); + } +} + +int cmGetTotalArgumentSize(int argc, char **argv) +{ + int i; + int result = 0; + for (i = 0; i < argc; ++i) + { + if (argv[i]) + { + result = result + strlen(argv[i]); + } + } + return result; +} + +void *cmGetSource(void *arg, const char *name) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + return (void *)mf->GetSource(name); +} + +void * cmAddSource(void *arg, void *arg2) +{ + cmMakefile *mf = static_cast<cmMakefile *>(arg); + cmSourceFile *sf = static_cast<cmSourceFile *>(arg2); + return (void *)mf->AddSource(*sf); +} + + +void * cmCreateSourceFile() +{ + return (void *)(new cmSourceFile); +} + +const char *cmSourceFileGetSourceName(void *arg) +{ + cmSourceFile *sf = static_cast<cmSourceFile *>(arg); + return sf->GetSourceName().c_str(); +} + +const char *cmSourceFileGetProperty(void *arg,const char *prop) +{ + cmSourceFile *sf = static_cast<cmSourceFile *>(arg); + return sf->GetProperty(prop); +} + +int cmSourceFileGetPropertyAsBool(void *arg,const char *prop) +{ + cmSourceFile *sf = static_cast<cmSourceFile *>(arg); + return (sf->GetPropertyAsBool(prop) ? 1: 0); +} + +void cmSourceFileSetProperty(void *arg,const char *prop, const char *val) +{ + cmSourceFile *sf = static_cast<cmSourceFile *>(arg); + sf->SetProperty(prop,val); +} + +void cmSourceFileAddDepend(void *arg, const char *depend) +{ + cmSourceFile *sf = static_cast<cmSourceFile *>(arg); + sf->GetDepends().push_back(depend); +} + +void cmSourceFileSetName(void *arg, const char* name, const char* dir, + int numSourceExtensions, + const char **sourceExtensions, + int numHeaderExtensions, + const char **headerExtensions) +{ + cmSourceFile *sf = static_cast<cmSourceFile *>(arg); + std::vector<std::string> srcs; + std::vector<std::string> hdrs; + int i; + for (i = 0; i < numSourceExtensions; ++i) + { + srcs.push_back(sourceExtensions[i]); + } + for (i = 0; i < numHeaderExtensions; ++i) + { + hdrs.push_back(headerExtensions[i]); + } + sf->SetName(name,dir, srcs, hdrs); +} + +void cmSourceFileSetName2(void *arg, const char* name, const char* dir, + const char *ext, int headerFileOnly) +{ + cmSourceFile *sf = static_cast<cmSourceFile *>(arg); + sf->SetName(name,dir,ext,(headerFileOnly ? true : false)); +} + + +char *cmGetFilenameWithoutExtension(const char *name) +{ + std::string sres = cmSystemTools::GetFilenameWithoutExtension(name); + char *result = (char *)malloc(sres.size()+1); + strcpy(result,sres.c_str()); + return result; +} + +char *cmCapitalized(const char *name) +{ + std::string sres = cmSystemTools::Capitalized(name); + char *result = (char *)malloc(sres.size()+1); + strcpy(result,sres.c_str()); + return result; +} + +void cmCopyFileIfDifferent(const char *name1, const char *name2) +{ + cmSystemTools::CopyFileIfDifferent(name1,name2); +} + +void cmRemoveFile(const char *name) +{ + cmSystemTools::RemoveFile(name); +} + diff --git a/Source/cmCPluginAPI.h b/Source/cmCPluginAPI.h new file mode 100644 index 0000000..367535d --- /dev/null +++ b/Source/cmCPluginAPI.h @@ -0,0 +1,218 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +/* This header file defines the API that loadable commands can use. In many + of these commands C++ instances of cmMakefile of cmSourceFile are passed + in as arguments or returned. In these cases they are passed as a void * + argument. In the function prototypes mf is used to represent a makefile + and sf is used to represent a source file. The functions are grouped + loosely into four groups 1) Utility 2) cmMakefile 3) cmSourceFile 4) + cmSystemTools. Within each grouping functions are listed alphabetically */ +/*=========================================================================*/ + + + +/*=========================================================================*/ +/* CM_PLUGIN_EXPORT should be used by plugins */ +/*=========================================================================*/ +#ifdef _WIN32 +#define CM_PLUGIN_EXPORT __declspec( dllexport ) +#else +#define CM_PLUGIN_EXPORT +#endif + +/*=========================================================================*/ +/* CM_EXPORT is used by CMake and not by plugins */ +/*=========================================================================*/ +#ifndef CM_EXPORT +#ifdef _WIN32 +#ifdef CMakeLib_EXPORTS + #define CM_EXPORT __declspec( dllexport ) +#else + #define CM_EXPORT __declspec( dllimport ) +#endif +#else +#define CM_EXPORT +#endif +#endif + + +/*=========================================================================*/ +/* define the different types of cache entries, see cmCacheManager.h for more + information */ +/*=========================================================================*/#define CM_CACHE_BOOL 0 +#define CM_CACHE_PATH 1 +#define CM_CACHE_FILEPATH 2 +#define CM_CACHE_STRING 3 +#define CM_CACHE_INTERNAL 4 +#define CM_CACHE_STATIC 5 + +/*=========================================================================*/ +/* define the different types of compiles a library may be */ +/*=========================================================================*/ +#define CM_LIBRARY_GENERAL 0 +#define CM_LIBRARY_DEBUG 1 +#define CM_LIBRARY_OPTIMIZED 2 + +#ifdef __cplusplus +extern "C" { +#endif + +/*=========================================================================*/ +/* first we define the key data structures and function prototypes */ +/*=========================================================================*/ + typedef const char* (*CM_DOC_FUNCTION)(); + typedef const char* (*CM_NAME_FUNCTION)(); + typedef int (*CM_INITIAL_PASS_FUNCTION)(void *info, void *mf, + int argc, char *[]); + typedef void (*CM_FINAL_PASS_FUNCTION)(void *info, void *mf); + + typedef struct { + int m_Inherited; + CM_INITIAL_PASS_FUNCTION InitialPass; + CM_FINAL_PASS_FUNCTION FinalPass; + CM_DOC_FUNCTION GetTerseDocumentation; + CM_DOC_FUNCTION GetFullDocumentation; + void *ClientData; + } cmLoadedCommandInfo; + + typedef void (*CM_INIT_FUNCTION)(cmLoadedCommandInfo *); + + /*=========================================================================*/ + /* Finally we define the set of functions that a plugin may call. The first + goup of functions are utility functions that are specific to the plugin + API */ + /*=========================================================================*/ + /* set/Get the ClientData in the cmLoadedCommandInfo structure, this is how + information is passed from the InitialPass to FInalPass for commands + that need a FinalPass and need information from the InitialPass */ + extern CM_EXPORT void *cmGetClientData(void *info); + /* return the summed size in characters of all the arguments */ + extern CM_EXPORT int cmGetTotalArgumentSize(int argc, char **argv); + /* free all the memory associated with an argc, argv pair */ + extern CM_EXPORT void cmFreeArguments(int argc, char **argv); + /* set/Get the ClientData in the cmLoadedCommandInfo structure, this is how + information is passed from the InitialPass to FInalPass for commands + that need a FinalPass and need information from the InitialPass */ + extern CM_EXPORT void cmSetClientData(void *info, void *cd); + + /*=========================================================================*/ + /* The following functions all directly map to methods in the cmMakefile + class. See cmMakefile.h for descriptions of what each method does. All + of these methods take the void * makefile pointer as their first + argument. */ + /*=========================================================================*/ + extern CM_EXPORT void cmAddCacheDefinition(void *mf, const char* name, + const char* value, + const char* doc, + int cachetype); + extern CM_EXPORT void cmAddCustomCommand(void *mf, const char* source, + const char* command, + int numArgs, + const char **args, + int numDepends, + const char **depends, + int numOutputs, + const char **outputs, + const char *target); + extern CM_EXPORT void cmAddDefineFlag(void *mf, const char* definition); + extern CM_EXPORT void cmAddDefinition(void *mf, const char* name, + const char* value); + extern CM_EXPORT void cmAddExecutable(void *mf, const char *exename, + int numSrcs, const char **srcs, + int win32); + extern CM_EXPORT void cmAddLibrary(void *mf, const char *libname, + int shared, int numSrcs, + const char **srcs); + extern CM_EXPORT void cmAddLinkDirectoryForTarget(void *mf, + const char *tgt, + const char* d); + extern CM_EXPORT void cmAddLinkLibraryForTarget(void *mf, + const char *tgt, + const char *libname, + int libtype); + extern CM_EXPORT void cmAddUtilityCommand(void *mf, const char* utilityName, + const char *command, + const char *arguments, + int all, int numDepends, + const char **depends, + int numOutputs, + const char **outputs); + extern CM_EXPORT int cmCommandExists(void *mf, const char* name); + extern CM_EXPORT void cmExecuteCommand(void *mf, const char *name, + int numArgs, const char **args); + extern CM_EXPORT + void cmExpandSourceListArguments(void *mf,int argc, const char **argv, + int *resArgc, char ***resArgv, + unsigned int startArgumentIndex); + extern CM_EXPORT char *cmExpandVariablesInString(void *mf, + const char *source, + int escapeQuotes, + int atOnly); + extern CM_EXPORT unsigned int cmGetCacheMajorVersion(void *mf); + extern CM_EXPORT unsigned int cmGetCacheMinorVersion(void *mf); + extern CM_EXPORT const char* cmGetCurrentDirectory(void *mf); + extern CM_EXPORT const char* cmGetCurrentOutputDirectory(void *mf); + extern CM_EXPORT const char* cmGetDefinition(void *mf, const char *def); + extern CM_EXPORT const char* cmGetHomeDirectory(void *mf); + extern CM_EXPORT const char* cmGetHomeOutputDirectory(void *mf); + extern CM_EXPORT unsigned int cmGetMajorVersion(void *mf); + extern CM_EXPORT unsigned int cmGetMinorVersion(void *mf); + extern CM_EXPORT const char* cmGetProjectName(void *mf); + extern CM_EXPORT const char* cmGetStartDirectory(void *mf); + extern CM_EXPORT const char* cmGetStartOutputDirectory(void *mf); + extern CM_EXPORT int cmIsOn(void *mf, const char* name); + + + /*=========================================================================*/ + /* The following functions are designed to operate or manipulate + cmSourceFiles. Please see cmSourceFile.h for additional information on many + of these methods. Some of these methods are in cmMakefile.h. + /*=========================================================================*/ + extern CM_EXPORT void *cmAddSource(void *mf, void *sf); + extern CM_EXPORT void *cmCreateSourceFile(); + extern CM_EXPORT void *cmGetSource(void *mf, const char* sourceName); + extern CM_EXPORT void cmSourceFileAddDepend(void *sf, const char *depend); + extern CM_EXPORT const char *cmSourceFileGetProperty(void *sf, + const char *prop); + extern CM_EXPORT int cmSourceFileGetPropertyAsBool(void *sf, + const char *prop); + extern CM_EXPORT const char *cmSourceFileGetSourceName(void *sf); + extern CM_EXPORT + void cmSourceFileSetName(void *sf, const char* name, const char* dir, + int numSourceExtensions, + const char **sourceExtensions, + int numHeaderExtensions, + const char **headerExtensions); + extern CM_EXPORT + void cmSourceFileSetName2(void *sf, const char* name, const char* dir, + const char *ext, int headerFileOnly); + extern CM_EXPORT void cmSourceFileSetProperty(void *sf, const char *prop, + const char *value); + + + /*=========================================================================*/ + /* the following methods are from cmSystemTools.h see that file for + specific documentaiton on each method. */ + /*=========================================================================*/ + extern CM_EXPORT char *cmCapitalized(const char *); + extern CM_EXPORT void cmCopyFileIfDifferent(const char *f1, const char *f2); + extern CM_EXPORT char *cmGetFilenameWithoutExtension(const char *); + extern CM_EXPORT void cmRemoveFile(const char *f1); + +#ifdef __cplusplus +} +#endif |