2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2006-03-10 18:06:26 +00:00
|
|
|
/*
|
2002-08-21 15:54:06 +00:00
|
|
|
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 "cmCPluginAPI.h"
|
2016-04-29 13:40:20 +00:00
|
|
|
|
2016-10-19 06:54:18 +00:00
|
|
|
#include "cmExecutionStatus.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
2016-04-29 13:40:20 +00:00
|
|
|
#include "cmMakefile.h"
|
2004-02-22 18:14:59 +00:00
|
|
|
#include "cmSourceFile.h"
|
2016-10-19 06:54:18 +00:00
|
|
|
#include "cmState.h"
|
|
|
|
#include "cmVersion.h"
|
2004-02-22 18:14:59 +00:00
|
|
|
|
2006-08-01 18:31:24 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#ifdef __QNX__
|
2016-05-16 14:34:04 +00:00
|
|
|
#include <malloc.h> /* for malloc/free on QNX */
|
2006-08-01 18:31:24 +00:00
|
|
|
#endif
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
extern "C" {
|
2006-03-10 18:06:26 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV* cmGetClientData(void* info)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
return ((cmLoadedCommandInfo*)info)->ClientData;
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmSetClientData(void* info, void* cd)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
((cmLoadedCommandInfo*)info)->ClientData = cd;
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmSetError(void* info, const char* err)
|
2002-10-08 19:55:04 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (((cmLoadedCommandInfo*)info)->Error) {
|
|
|
|
free(((cmLoadedCommandInfo*)info)->Error);
|
|
|
|
}
|
|
|
|
((cmLoadedCommandInfo*)info)->Error = strdup(err);
|
2002-10-08 19:55:04 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
unsigned int CCONV cmGetCacheMajorVersion(void* arg)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
|
|
|
cmState* state = mf->GetState();
|
2015-10-10 12:34:26 +00:00
|
|
|
return state->GetCacheMajorVersion();
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
unsigned int CCONV cmGetCacheMinorVersion(void* arg)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
|
|
|
cmState* state = mf->GetState();
|
2015-10-10 12:34:26 +00:00
|
|
|
return state->GetCacheMinorVersion();
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
unsigned int CCONV cmGetMajorVersion(void*)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2006-11-29 20:59:16 +00:00
|
|
|
return cmVersion::GetMajorVersion();
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
unsigned int CCONV cmGetMinorVersion(void*)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2006-11-29 20:59:16 +00:00
|
|
|
return cmVersion::GetMinorVersion();
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmAddDefinition(void* arg, const char* name, const char* value)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
|
|
|
mf->AddDefinition(name, value);
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a definition to this makefile and the global cmake cache. */
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmAddCacheDefinition(void* arg, const char* name, const char* value,
|
|
|
|
const char* doc, int type)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2006-03-10 18:06:26 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
switch (type) {
|
2002-08-21 15:54:06 +00:00
|
|
|
case CM_CACHE_BOOL:
|
2016-10-18 19:28:47 +00:00
|
|
|
mf->AddCacheDefinition(name, value, doc, cmStateEnums::BOOL);
|
2002-08-21 15:54:06 +00:00
|
|
|
break;
|
|
|
|
case CM_CACHE_PATH:
|
2016-10-18 19:28:47 +00:00
|
|
|
mf->AddCacheDefinition(name, value, doc, cmStateEnums::PATH);
|
2002-08-21 15:54:06 +00:00
|
|
|
break;
|
|
|
|
case CM_CACHE_FILEPATH:
|
2016-10-18 19:28:47 +00:00
|
|
|
mf->AddCacheDefinition(name, value, doc, cmStateEnums::FILEPATH);
|
2002-08-21 15:54:06 +00:00
|
|
|
break;
|
|
|
|
case CM_CACHE_STRING:
|
2016-10-18 19:28:47 +00:00
|
|
|
mf->AddCacheDefinition(name, value, doc, cmStateEnums::STRING);
|
2002-08-21 15:54:06 +00:00
|
|
|
break;
|
|
|
|
case CM_CACHE_INTERNAL:
|
2016-10-18 19:28:47 +00:00
|
|
|
mf->AddCacheDefinition(name, value, doc, cmStateEnums::INTERNAL);
|
2002-08-21 15:54:06 +00:00
|
|
|
break;
|
|
|
|
case CM_CACHE_STATIC:
|
2016-10-18 19:28:47 +00:00
|
|
|
mf->AddCacheDefinition(name, value, doc, cmStateEnums::STATIC);
|
2002-08-21 15:54:06 +00:00
|
|
|
break;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* CCONV cmGetProjectName(void* arg)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2015-08-02 08:57:31 +00:00
|
|
|
static std::string name;
|
2015-10-06 22:19:02 +00:00
|
|
|
name = mf->GetStateSnapshot().GetProjectName();
|
2015-08-02 08:57:31 +00:00
|
|
|
return name.c_str();
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* CCONV cmGetHomeDirectory(void* arg)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2002-08-21 15:54:06 +00:00
|
|
|
return mf->GetHomeDirectory();
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* CCONV cmGetHomeOutputDirectory(void* arg)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2002-08-21 15:54:06 +00:00
|
|
|
return mf->GetHomeOutputDirectory();
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* CCONV cmGetStartDirectory(void* arg)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2015-04-16 18:06:54 +00:00
|
|
|
return mf->GetCurrentSourceDirectory();
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* CCONV cmGetStartOutputDirectory(void* arg)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2015-04-16 18:06:54 +00:00
|
|
|
return mf->GetCurrentBinaryDirectory();
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* CCONV cmGetCurrentDirectory(void* arg)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2015-04-16 19:17:41 +00:00
|
|
|
return mf->GetCurrentSourceDirectory();
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* CCONV cmGetCurrentOutputDirectory(void* arg)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2015-04-16 19:33:09 +00:00
|
|
|
return mf->GetCurrentBinaryDirectory();
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* CCONV cmGetDefinition(void* arg, const char* def)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2002-08-21 15:54:06 +00:00
|
|
|
return mf->GetDefinition(def);
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
int CCONV cmIsOn(void* arg, const char* name)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2002-08-21 15:54:06 +00:00
|
|
|
return static_cast<int>(mf->IsOn(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Check if a command exists. */
|
2016-05-16 14:34:04 +00:00
|
|
|
int CCONV cmCommandExists(void* arg, const char* name)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2015-04-11 10:52:14 +00:00
|
|
|
return static_cast<int>(mf->GetState()->GetCommand(name) ? 1 : 0);
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmAddDefineFlag(void* arg, const char* definition)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2002-08-21 15:54:06 +00:00
|
|
|
mf->AddDefineFlag(definition);
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmAddLinkDirectoryForTarget(void* arg, const char* tgt,
|
|
|
|
const char* d)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2016-10-07 18:13:35 +00:00
|
|
|
cmTarget* t = mf->FindLocalNonAliasTarget(tgt);
|
|
|
|
if (!t) {
|
|
|
|
cmSystemTools::Error(
|
|
|
|
"Attempt to add link directories to non-existent target: ", tgt,
|
|
|
|
" for directory ", d);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
t->AddLinkDirectory(d);
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmAddExecutable(void* arg, const char* exename, int numSrcs,
|
|
|
|
const char** srcs, int win32)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2002-08-21 15:54:06 +00:00
|
|
|
std::vector<std::string> srcs2;
|
|
|
|
int i;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (i = 0; i < numSrcs; ++i) {
|
2002-08-21 15:54:06 +00:00
|
|
|
srcs2.push_back(srcs[i]);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
cmTarget* tg = mf->AddExecutable(exename, srcs2);
|
|
|
|
if (win32) {
|
|
|
|
tg->SetProperty("WIN32_EXECUTABLE", "ON");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCONV cmAddUtilityCommand(void* arg, const char* utilityName,
|
|
|
|
const char* command, const char* arguments,
|
|
|
|
int all, int numDepends, const char** depends,
|
|
|
|
int, const char**)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2005-02-22 15:32:44 +00:00
|
|
|
// Get the makefile instance. Perform an extra variable expansion
|
|
|
|
// now because the API caller expects it.
|
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
|
|
|
|
|
|
|
// Construct the command line for the command.
|
|
|
|
cmCustomCommandLine commandLine;
|
|
|
|
std::string expand = command;
|
|
|
|
commandLine.push_back(mf->ExpandVariablesInString(expand));
|
2016-05-16 14:34:04 +00:00
|
|
|
if (arguments && arguments[0]) {
|
2005-02-22 15:32:44 +00:00
|
|
|
// TODO: Parse arguments!
|
|
|
|
expand = arguments;
|
|
|
|
commandLine.push_back(mf->ExpandVariablesInString(expand));
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-02-22 15:32:44 +00:00
|
|
|
cmCustomCommandLines commandLines;
|
|
|
|
commandLines.push_back(commandLine);
|
|
|
|
|
|
|
|
// Accumulate the list of dependencies.
|
2002-08-21 15:54:06 +00:00
|
|
|
std::vector<std::string> depends2;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (int i = 0; i < numDepends; ++i) {
|
2005-02-22 15:32:44 +00:00
|
|
|
expand = depends[i];
|
|
|
|
depends2.push_back(mf->ExpandVariablesInString(expand));
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-02-22 15:32:44 +00:00
|
|
|
|
|
|
|
// Pass the call to the makefile instance.
|
2016-06-27 20:44:16 +00:00
|
|
|
mf->AddUtilityCommand(utilityName, (all ? false : true), CM_NULLPTR,
|
|
|
|
depends2, commandLines);
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV 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)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2005-02-22 15:32:44 +00:00
|
|
|
// Get the makefile instance. Perform an extra variable expansion
|
|
|
|
// now because the API caller expects it.
|
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
|
|
|
|
|
|
|
// Construct the command line for the command.
|
|
|
|
cmCustomCommandLine commandLine;
|
|
|
|
std::string expand = command;
|
|
|
|
commandLine.push_back(mf->ExpandVariablesInString(expand));
|
2016-05-16 14:34:04 +00:00
|
|
|
for (int i = 0; i < numArgs; ++i) {
|
2005-02-22 15:32:44 +00:00
|
|
|
expand = args[i];
|
|
|
|
commandLine.push_back(mf->ExpandVariablesInString(expand));
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-02-22 15:32:44 +00:00
|
|
|
cmCustomCommandLines commandLines;
|
|
|
|
commandLines.push_back(commandLine);
|
|
|
|
|
|
|
|
// Accumulate the list of dependencies.
|
2002-08-21 15:54:06 +00:00
|
|
|
std::vector<std::string> depends2;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (int i = 0; i < numDepends; ++i) {
|
2005-02-22 15:32:44 +00:00
|
|
|
expand = depends[i];
|
|
|
|
depends2.push_back(mf->ExpandVariablesInString(expand));
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-02-22 15:32:44 +00:00
|
|
|
|
|
|
|
// Accumulate the list of outputs.
|
2002-08-21 15:54:06 +00:00
|
|
|
std::vector<std::string> outputs2;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (int i = 0; i < numOutputs; ++i) {
|
2005-02-22 15:32:44 +00:00
|
|
|
expand = outputs[i];
|
|
|
|
outputs2.push_back(mf->ExpandVariablesInString(expand));
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-02-22 15:32:44 +00:00
|
|
|
|
|
|
|
// Pass the call to the makefile instance.
|
2016-06-27 20:44:16 +00:00
|
|
|
const char* no_comment = CM_NULLPTR;
|
2005-02-22 15:32:44 +00:00
|
|
|
mf->AddCustomCommandOldStyle(target, outputs2, depends2, source,
|
|
|
|
commandLines, no_comment);
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmAddCustomCommandToOutput(void* arg, const char* output,
|
|
|
|
const char* command, int numArgs,
|
|
|
|
const char** args,
|
|
|
|
const char* main_dependency,
|
|
|
|
int numDepends, const char** depends)
|
2003-06-03 14:30:23 +00:00
|
|
|
{
|
2005-02-22 15:32:44 +00:00
|
|
|
// Get the makefile instance. Perform an extra variable expansion
|
|
|
|
// now because the API caller expects it.
|
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
|
|
|
|
|
|
|
// Construct the command line for the command.
|
|
|
|
cmCustomCommandLine commandLine;
|
|
|
|
std::string expand = command;
|
|
|
|
commandLine.push_back(mf->ExpandVariablesInString(expand));
|
2016-05-16 14:34:04 +00:00
|
|
|
for (int i = 0; i < numArgs; ++i) {
|
2005-02-22 15:32:44 +00:00
|
|
|
expand = args[i];
|
|
|
|
commandLine.push_back(mf->ExpandVariablesInString(expand));
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-02-22 15:32:44 +00:00
|
|
|
cmCustomCommandLines commandLines;
|
|
|
|
commandLines.push_back(commandLine);
|
|
|
|
|
|
|
|
// Accumulate the list of dependencies.
|
2003-06-03 14:30:23 +00:00
|
|
|
std::vector<std::string> depends2;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (int i = 0; i < numDepends; ++i) {
|
2005-02-22 15:32:44 +00:00
|
|
|
expand = depends[i];
|
|
|
|
depends2.push_back(mf->ExpandVariablesInString(expand));
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-02-22 15:32:44 +00:00
|
|
|
|
|
|
|
// Pass the call to the makefile instance.
|
2016-06-27 20:44:16 +00:00
|
|
|
const char* no_comment = CM_NULLPTR;
|
|
|
|
const char* no_working_dir = CM_NULLPTR;
|
2016-05-16 14:34:04 +00:00
|
|
|
mf->AddCustomCommandToOutput(output, depends2, main_dependency, commandLines,
|
|
|
|
no_comment, no_working_dir);
|
2003-06-03 14:30:23 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmAddCustomCommandToTarget(void* arg, const char* target,
|
|
|
|
const char* command, int numArgs,
|
|
|
|
const char** args, int commandType)
|
2003-06-03 14:30:23 +00:00
|
|
|
{
|
2005-02-22 15:32:44 +00:00
|
|
|
// Get the makefile instance.
|
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
|
|
|
|
|
|
|
// Construct the command line for the command. Perform an extra
|
|
|
|
// variable expansion now because the API caller expects it.
|
|
|
|
cmCustomCommandLine commandLine;
|
|
|
|
std::string expand = command;
|
|
|
|
commandLine.push_back(mf->ExpandVariablesInString(expand));
|
2016-05-16 14:34:04 +00:00
|
|
|
for (int i = 0; i < numArgs; ++i) {
|
2005-02-22 15:32:44 +00:00
|
|
|
expand = args[i];
|
|
|
|
commandLine.push_back(mf->ExpandVariablesInString(expand));
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-02-22 15:32:44 +00:00
|
|
|
cmCustomCommandLines commandLines;
|
|
|
|
commandLines.push_back(commandLine);
|
|
|
|
|
|
|
|
// Select the command type.
|
|
|
|
cmTarget::CustomCommandType cctype = cmTarget::POST_BUILD;
|
2016-05-16 14:34:04 +00:00
|
|
|
switch (commandType) {
|
2003-06-03 14:30:23 +00:00
|
|
|
case CM_PRE_BUILD:
|
2005-02-22 15:32:44 +00:00
|
|
|
cctype = cmTarget::PRE_BUILD;
|
2003-06-03 14:30:23 +00:00
|
|
|
break;
|
|
|
|
case CM_PRE_LINK:
|
2005-02-22 15:32:44 +00:00
|
|
|
cctype = cmTarget::PRE_LINK;
|
2003-06-03 14:30:23 +00:00
|
|
|
break;
|
|
|
|
case CM_POST_BUILD:
|
2005-02-22 15:32:44 +00:00
|
|
|
cctype = cmTarget::POST_BUILD;
|
2003-06-03 14:30:23 +00:00
|
|
|
break;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2005-02-22 15:32:44 +00:00
|
|
|
|
|
|
|
// Pass the call to the makefile instance.
|
2014-11-13 23:54:52 +00:00
|
|
|
std::vector<std::string> no_byproducts;
|
2005-02-22 15:32:44 +00:00
|
|
|
std::vector<std::string> no_depends;
|
2016-06-27 20:44:16 +00:00
|
|
|
const char* no_comment = CM_NULLPTR;
|
|
|
|
const char* no_working_dir = CM_NULLPTR;
|
2014-11-13 23:54:52 +00:00
|
|
|
mf->AddCustomCommandToTarget(target, no_byproducts, no_depends, commandLines,
|
2006-02-08 15:58:36 +00:00
|
|
|
cctype, no_comment, no_working_dir);
|
2003-06-03 14:30:23 +00:00
|
|
|
}
|
2002-08-21 15:54:06 +00:00
|
|
|
|
2016-10-07 18:13:36 +00:00
|
|
|
static void addLinkLibrary(cmMakefile* mf, std::string const& target,
|
|
|
|
std::string const& lib, cmTargetLinkLibraryType llt)
|
|
|
|
{
|
|
|
|
cmTarget* t = mf->FindLocalNonAliasTarget(target);
|
|
|
|
if (!t) {
|
|
|
|
std::ostringstream e;
|
|
|
|
e << "Attempt to add link library \"" << lib << "\" to target \"" << target
|
|
|
|
<< "\" which is not built in this directory.";
|
|
|
|
mf->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmTarget* tgt = mf->GetGlobalGenerator()->FindTarget(lib);
|
2016-10-18 19:28:46 +00:00
|
|
|
if (tgt && (tgt->GetType() != cmStateEnums::STATIC_LIBRARY) &&
|
|
|
|
(tgt->GetType() != cmStateEnums::SHARED_LIBRARY) &&
|
|
|
|
(tgt->GetType() != cmStateEnums::INTERFACE_LIBRARY) &&
|
2016-10-07 18:13:36 +00:00
|
|
|
!tgt->IsExecutableWithExports()) {
|
|
|
|
std::ostringstream e;
|
|
|
|
e << "Target \"" << lib << "\" of type "
|
|
|
|
<< cmState::GetTargetTypeName(tgt->GetType())
|
|
|
|
<< " may not be linked into another target. "
|
|
|
|
<< "One may link only to STATIC or SHARED libraries, or "
|
|
|
|
<< "to executables with the ENABLE_EXPORTS property set.";
|
|
|
|
mf->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
t->AddLinkLibrary(*mf, lib, llt);
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmAddLinkLibraryForTarget(void* arg, const char* tgt,
|
|
|
|
const char* value, int libtype)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2006-03-10 18:06:26 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
switch (libtype) {
|
2002-08-21 15:54:06 +00:00
|
|
|
case CM_LIBRARY_GENERAL:
|
2016-10-07 18:13:36 +00:00
|
|
|
addLinkLibrary(mf, tgt, value, GENERAL_LibraryType);
|
2002-08-21 15:54:06 +00:00
|
|
|
break;
|
|
|
|
case CM_LIBRARY_DEBUG:
|
2016-10-07 18:13:36 +00:00
|
|
|
addLinkLibrary(mf, tgt, value, DEBUG_LibraryType);
|
2002-08-21 15:54:06 +00:00
|
|
|
break;
|
|
|
|
case CM_LIBRARY_OPTIMIZED:
|
2016-10-07 18:13:36 +00:00
|
|
|
addLinkLibrary(mf, tgt, value, OPTIMIZED_LibraryType);
|
2002-08-21 15:54:06 +00:00
|
|
|
break;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmAddLibrary(void* arg, const char* libname, int shared,
|
|
|
|
int numSrcs, const char** srcs)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2002-08-21 15:54:06 +00:00
|
|
|
std::vector<std::string> srcs2;
|
|
|
|
int i;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (i = 0; i < numSrcs; ++i) {
|
2002-08-21 15:54:06 +00:00
|
|
|
srcs2.push_back(srcs[i]);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2016-10-18 19:28:46 +00:00
|
|
|
mf->AddLibrary(libname, (shared ? cmStateEnums::SHARED_LIBRARY
|
|
|
|
: cmStateEnums::STATIC_LIBRARY),
|
2016-05-16 14:34:04 +00:00
|
|
|
srcs2);
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
char CCONV* cmExpandVariablesInString(void* arg, const char* source,
|
|
|
|
int escapeQuotes, int atOnly)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2002-08-21 17:16:07 +00:00
|
|
|
std::string barf = source;
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string result = mf->ExpandVariablesInString(
|
|
|
|
barf, (escapeQuotes ? true : false), (atOnly ? true : false));
|
|
|
|
char* res = static_cast<char*>(malloc(result.size() + 1));
|
2016-11-05 22:44:29 +00:00
|
|
|
if (!result.empty()) {
|
2016-05-16 14:34:04 +00:00
|
|
|
strcpy(res, result.c_str());
|
|
|
|
}
|
2002-08-21 15:54:06 +00:00
|
|
|
res[result.size()] = '\0';
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
int CCONV cmExecuteCommand(void* arg, const char* name, int numArgs,
|
|
|
|
const char** args)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2002-12-11 23:13:33 +00:00
|
|
|
cmListFileFunction lff;
|
2006-03-15 16:02:08 +00:00
|
|
|
lff.Name = name;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (int i = 0; i < numArgs; ++i) {
|
2002-12-11 23:13:33 +00:00
|
|
|
// Assume all arguments are quoted.
|
2012-08-06 14:07:58 +00:00
|
|
|
lff.Arguments.push_back(
|
2015-05-23 21:43:37 +00:00
|
|
|
cmListFileArgument(args[i], cmListFileArgument::Quoted, 0));
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-01-23 15:28:26 +00:00
|
|
|
cmExecutionStatus status;
|
2016-05-16 14:34:04 +00:00
|
|
|
return mf->ExecuteCommand(lff, status);
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmExpandSourceListArguments(void* arg, int numArgs,
|
|
|
|
const char** args, int* resArgc,
|
|
|
|
char*** resArgv,
|
|
|
|
unsigned int startArgumentIndex)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2015-01-18 16:10:03 +00:00
|
|
|
(void)arg;
|
|
|
|
(void)startArgumentIndex;
|
2002-08-21 15:54:06 +00:00
|
|
|
std::vector<std::string> result;
|
|
|
|
int i;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (i = 0; i < numArgs; ++i) {
|
2015-01-18 16:10:03 +00:00
|
|
|
result.push_back(args[i]);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2002-08-23 19:13:49 +00:00
|
|
|
int resargc = static_cast<int>(result.size());
|
2016-06-27 20:44:16 +00:00
|
|
|
char** resargv = CM_NULLPTR;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (resargc) {
|
|
|
|
resargv = (char**)malloc(resargc * sizeof(char*));
|
|
|
|
}
|
|
|
|
for (i = 0; i < resargc; ++i) {
|
2002-08-21 15:54:06 +00:00
|
|
|
resargv[i] = strdup(result[i].c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2002-08-21 15:54:06 +00:00
|
|
|
*resArgc = resargc;
|
|
|
|
*resArgv = resargv;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmFreeArguments(int argc, char** argv)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
|
|
|
int i;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (i = 0; i < argc; ++i) {
|
2002-08-21 15:54:06 +00:00
|
|
|
free(argv[i]);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (argv) {
|
2002-08-21 15:54:06 +00:00
|
|
|
free(argv);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
int CCONV cmGetTotalArgumentSize(int argc, char** argv)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int result = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (i = 0; i < argc; ++i) {
|
|
|
|
if (argv[i]) {
|
2002-08-23 19:13:49 +00:00
|
|
|
result = result + static_cast<int>(strlen(argv[i]));
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2002-08-21 15:54:06 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-06-18 15:59:23 +00:00
|
|
|
// Source file proxy object to support the old cmSourceFile/cmMakefile
|
|
|
|
// API for source files.
|
|
|
|
struct cmCPluginAPISourceFile
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCPluginAPISourceFile()
|
2016-06-27 20:44:16 +00:00
|
|
|
: RealSourceFile(CM_NULLPTR)
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
|
|
|
}
|
2007-06-18 15:59:23 +00:00
|
|
|
cmSourceFile* RealSourceFile;
|
|
|
|
std::string SourceName;
|
|
|
|
std::string SourceExtension;
|
|
|
|
std::string FullPath;
|
|
|
|
std::vector<std::string> Depends;
|
|
|
|
cmPropertyMap Properties;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Keep a map from real cmSourceFile instances stored in a makefile to
|
|
|
|
// the CPluginAPI proxy source file.
|
2016-05-16 14:34:04 +00:00
|
|
|
class cmCPluginAPISourceFileMap
|
|
|
|
: public std::map<cmSourceFile*, cmCPluginAPISourceFile*>
|
2007-06-18 15:59:23 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef std::map<cmSourceFile*, cmCPluginAPISourceFile*> derived;
|
|
|
|
typedef derived::iterator iterator;
|
|
|
|
typedef derived::value_type value_type;
|
|
|
|
~cmCPluginAPISourceFileMap()
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
|
|
|
for (iterator i = this->begin(); i != this->end(); ++i) {
|
2007-06-18 15:59:23 +00:00
|
|
|
delete i->second;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-18 15:59:23 +00:00
|
|
|
};
|
2007-06-19 13:18:22 +00:00
|
|
|
cmCPluginAPISourceFileMap cmCPluginAPISourceFiles;
|
2007-06-18 15:59:23 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void* CCONV cmCreateSourceFile(void)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2007-06-18 15:59:23 +00:00
|
|
|
return (void*)new cmCPluginAPISourceFile;
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void* CCONV cmCreateNewSourceFile(void*)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile;
|
2007-11-12 17:04:36 +00:00
|
|
|
return (void*)sf;
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmDestroySourceFile(void* arg)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2007-06-18 15:59:23 +00:00
|
|
|
cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
|
|
|
|
// Only delete if it was created by cmCreateSourceFile or
|
|
|
|
// cmCreateNewSourceFile and is therefore not in the map.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!sf->RealSourceFile) {
|
2007-06-18 15:59:23 +00:00
|
|
|
delete sf;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV* cmGetSource(void* arg, const char* name)
|
2006-12-07 14:45:32 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
|
|
|
if (cmSourceFile* rsf = mf->GetSource(name)) {
|
2007-06-18 15:59:23 +00:00
|
|
|
// Lookup the proxy source file object for this source.
|
|
|
|
cmCPluginAPISourceFileMap::iterator i = cmCPluginAPISourceFiles.find(rsf);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (i == cmCPluginAPISourceFiles.end()) {
|
2007-06-18 15:59:23 +00:00
|
|
|
// Create a proxy source file object for this source.
|
|
|
|
cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile;
|
|
|
|
sf->RealSourceFile = rsf;
|
|
|
|
sf->FullPath = rsf->GetFullPath();
|
|
|
|
sf->SourceName =
|
2014-03-10 23:04:11 +00:00
|
|
|
cmSystemTools::GetFilenameWithoutLastExtension(sf->FullPath);
|
2007-06-18 15:59:23 +00:00
|
|
|
sf->SourceExtension =
|
2014-03-10 23:04:11 +00:00
|
|
|
cmSystemTools::GetFilenameLastExtension(sf->FullPath);
|
2007-06-18 15:59:23 +00:00
|
|
|
|
|
|
|
// Store the proxy in the map so it can be re-used and deleted later.
|
|
|
|
cmCPluginAPISourceFileMap::value_type entry(rsf, sf);
|
|
|
|
i = cmCPluginAPISourceFiles.insert(entry).first;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
return (void*)i->second;
|
|
|
|
}
|
2016-09-16 20:45:24 +00:00
|
|
|
return CM_NULLPTR;
|
2006-12-07 14:45:32 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void* CCONV cmAddSource(void* arg, void* arg2)
|
2002-12-11 19:16:55 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2007-06-18 15:59:23 +00:00
|
|
|
cmCPluginAPISourceFile* osf = static_cast<cmCPluginAPISourceFile*>(arg2);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (osf->FullPath.empty()) {
|
2016-06-27 20:44:16 +00:00
|
|
|
return CM_NULLPTR;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-18 15:59:23 +00:00
|
|
|
|
|
|
|
// Create the real cmSourceFile instance and copy over saved information.
|
2014-03-10 23:04:11 +00:00
|
|
|
cmSourceFile* rsf = mf->GetOrCreateSource(osf->FullPath);
|
2007-06-18 15:59:23 +00:00
|
|
|
rsf->GetProperties() = osf->Properties;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<std::string>::iterator i = osf->Depends.begin();
|
|
|
|
i != osf->Depends.end(); ++i) {
|
2016-11-05 22:44:29 +00:00
|
|
|
rsf->AddDepend(*i);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-18 15:59:23 +00:00
|
|
|
|
|
|
|
// Create the proxy for the real source file.
|
|
|
|
cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile;
|
|
|
|
sf->RealSourceFile = rsf;
|
|
|
|
sf->FullPath = osf->FullPath;
|
|
|
|
sf->SourceName = osf->SourceName;
|
|
|
|
sf->SourceExtension = osf->SourceExtension;
|
|
|
|
|
|
|
|
// Store the proxy in the map so it can be re-used and deleted later.
|
|
|
|
cmCPluginAPISourceFiles[rsf] = sf;
|
2016-05-16 14:34:04 +00:00
|
|
|
return (void*)sf;
|
2002-12-11 19:16:55 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* CCONV cmSourceFileGetSourceName(void* arg)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2007-06-18 15:59:23 +00:00
|
|
|
cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
|
|
|
|
return sf->SourceName.c_str();
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* CCONV cmSourceFileGetFullPath(void* arg)
|
2002-11-14 16:03:08 +00:00
|
|
|
{
|
2007-06-18 15:59:23 +00:00
|
|
|
cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
|
|
|
|
return sf->FullPath.c_str();
|
2002-11-14 16:03:08 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* CCONV cmSourceFileGetProperty(void* arg, const char* prop)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2007-06-18 15:59:23 +00:00
|
|
|
cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmSourceFile* rsf = sf->RealSourceFile) {
|
2007-06-18 15:59:23 +00:00
|
|
|
return rsf->GetProperty(prop);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2016-09-16 20:45:24 +00:00
|
|
|
if (!strcmp(prop, "LOCATION")) {
|
|
|
|
return sf->FullPath.c_str();
|
|
|
|
}
|
|
|
|
return sf->Properties.GetPropertyValue(prop);
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
int CCONV cmSourceFileGetPropertyAsBool(void* arg, const char* prop)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2007-06-18 15:59:23 +00:00
|
|
|
cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmSourceFile* rsf = sf->RealSourceFile) {
|
|
|
|
return rsf->GetPropertyAsBool(prop) ? 1 : 0;
|
|
|
|
}
|
2016-09-16 20:45:24 +00:00
|
|
|
return cmSystemTools::IsOn(cmSourceFileGetProperty(arg, prop)) ? 1 : 0;
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmSourceFileSetProperty(void* arg, const char* prop,
|
|
|
|
const char* value)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2007-06-18 15:59:23 +00:00
|
|
|
cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmSourceFile* rsf = sf->RealSourceFile) {
|
2007-06-18 15:59:23 +00:00
|
|
|
rsf->SetProperty(prop, value);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (prop) {
|
|
|
|
if (!value) {
|
|
|
|
value = "NOTFOUND";
|
2007-06-18 15:59:23 +00:00
|
|
|
}
|
2015-06-06 07:41:15 +00:00
|
|
|
sf->Properties.SetProperty(prop, value);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmSourceFileAddDepend(void* arg, const char* depend)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2007-06-18 15:59:23 +00:00
|
|
|
cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmSourceFile* rsf = sf->RealSourceFile) {
|
2007-06-18 15:59:23 +00:00
|
|
|
rsf->AddDepend(depend);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2007-06-18 15:59:23 +00:00
|
|
|
sf->Depends.push_back(depend);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmSourceFileSetName(void* arg, const char* name, const char* dir,
|
2007-06-18 15:59:23 +00:00
|
|
|
int numSourceExtensions,
|
2016-05-16 14:34:04 +00:00
|
|
|
const char** sourceExtensions,
|
2007-06-18 15:59:23 +00:00
|
|
|
int numHeaderExtensions,
|
2016-05-16 14:34:04 +00:00
|
|
|
const char** headerExtensions)
|
2007-06-18 15:59:23 +00:00
|
|
|
{
|
|
|
|
cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (sf->RealSourceFile) {
|
2007-06-18 15:59:23 +00:00
|
|
|
// SetName is allowed only on temporary source files created by
|
|
|
|
// the command for building and passing to AddSource.
|
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-18 15:59:23 +00:00
|
|
|
std::vector<std::string> sourceExts;
|
|
|
|
std::vector<std::string> headerExts;
|
2002-08-21 15:54:06 +00:00
|
|
|
int i;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (i = 0; i < numSourceExtensions; ++i) {
|
2007-06-18 15:59:23 +00:00
|
|
|
sourceExts.push_back(sourceExtensions[i]);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < numHeaderExtensions; ++i) {
|
2007-06-18 15:59:23 +00:00
|
|
|
headerExts.push_back(headerExtensions[i]);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-18 15:59:23 +00:00
|
|
|
|
|
|
|
// Save the original name given.
|
|
|
|
sf->SourceName = name;
|
|
|
|
|
|
|
|
// Convert the name to a full path in case the given name is a
|
|
|
|
// relative path.
|
|
|
|
std::string pathname = cmSystemTools::CollapseFullPath(name, dir);
|
|
|
|
|
|
|
|
// First try and see whether the listed file can be found
|
|
|
|
// as is without extensions added on.
|
|
|
|
std::string hname = pathname;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmSystemTools::FileExists(hname.c_str())) {
|
2007-06-18 15:59:23 +00:00
|
|
|
sf->SourceName = cmSystemTools::GetFilenamePath(name);
|
2016-11-05 22:44:29 +00:00
|
|
|
if (!sf->SourceName.empty()) {
|
2007-06-18 15:59:23 +00:00
|
|
|
sf->SourceName += "/";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-18 15:59:23 +00:00
|
|
|
sf->SourceName += cmSystemTools::GetFilenameWithoutLastExtension(name);
|
|
|
|
std::string::size_type pos = hname.rfind('.');
|
2016-05-16 14:34:04 +00:00
|
|
|
if (pos != std::string::npos) {
|
|
|
|
sf->SourceExtension = hname.substr(pos + 1, hname.size() - pos);
|
|
|
|
if (cmSystemTools::FileIsFullPath(name)) {
|
2007-06-18 15:59:23 +00:00
|
|
|
std::string::size_type pos2 = hname.rfind('/');
|
2016-05-16 14:34:04 +00:00
|
|
|
if (pos2 != std::string::npos) {
|
|
|
|
sf->SourceName = hname.substr(pos2 + 1, pos - pos2 - 1);
|
2007-06-18 15:59:23 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-18 15:59:23 +00:00
|
|
|
|
|
|
|
sf->FullPath = hname;
|
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-18 15:59:23 +00:00
|
|
|
|
|
|
|
// Next, try the various source extensions
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<std::string>::const_iterator ext = sourceExts.begin();
|
|
|
|
ext != sourceExts.end(); ++ext) {
|
2007-06-18 15:59:23 +00:00
|
|
|
hname = pathname;
|
|
|
|
hname += ".";
|
|
|
|
hname += *ext;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmSystemTools::FileExists(hname.c_str())) {
|
2007-06-18 15:59:23 +00:00
|
|
|
sf->SourceExtension = *ext;
|
|
|
|
sf->FullPath = hname;
|
|
|
|
return;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-18 15:59:23 +00:00
|
|
|
|
|
|
|
// Finally, try the various header extensions
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<std::string>::const_iterator ext = headerExts.begin();
|
|
|
|
ext != headerExts.end(); ++ext) {
|
2007-06-18 15:59:23 +00:00
|
|
|
hname = pathname;
|
|
|
|
hname += ".";
|
|
|
|
hname += *ext;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmSystemTools::FileExists(hname.c_str())) {
|
2007-06-18 15:59:23 +00:00
|
|
|
sf->SourceExtension = *ext;
|
|
|
|
sf->FullPath = hname;
|
|
|
|
return;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-18 15:59:23 +00:00
|
|
|
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream e;
|
2007-06-18 15:59:23 +00:00
|
|
|
e << "Cannot find source file \"" << pathname << "\"";
|
|
|
|
e << "\n\nTried extensions";
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<std::string>::const_iterator ext = sourceExts.begin();
|
|
|
|
ext != sourceExts.end(); ++ext) {
|
2007-06-18 15:59:23 +00:00
|
|
|
e << " ." << *ext;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
for (std::vector<std::string>::const_iterator ext = headerExts.begin();
|
|
|
|
ext != headerExts.end(); ++ext) {
|
2007-06-18 15:59:23 +00:00
|
|
|
e << " ." << *ext;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-18 15:59:23 +00:00
|
|
|
cmSystemTools::Error(e.str().c_str());
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmSourceFileSetName2(void* arg, const char* name, const char* dir,
|
|
|
|
const char* ext, int headerFileOnly)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2007-06-18 15:59:23 +00:00
|
|
|
cmCPluginAPISourceFile* sf = static_cast<cmCPluginAPISourceFile*>(arg);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (sf->RealSourceFile) {
|
2007-06-18 15:59:23 +00:00
|
|
|
// SetName is allowed only on temporary source files created by
|
|
|
|
// the command for building and passing to AddSource.
|
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2002-08-21 15:54:06 +00:00
|
|
|
|
2007-06-18 15:59:23 +00:00
|
|
|
// Implement the old SetName method code here.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (headerFileOnly) {
|
2015-06-06 07:41:15 +00:00
|
|
|
sf->Properties.SetProperty("HEADER_FILE_ONLY", "1");
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-06-18 15:59:23 +00:00
|
|
|
sf->SourceName = name;
|
|
|
|
std::string fname = sf->SourceName;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (ext && strlen(ext)) {
|
2007-06-18 15:59:23 +00:00
|
|
|
fname += ".";
|
|
|
|
fname += ext;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2016-11-05 22:44:29 +00:00
|
|
|
sf->FullPath = cmSystemTools::CollapseFullPath(fname, dir);
|
2007-06-18 15:59:23 +00:00
|
|
|
cmSystemTools::ConvertToUnixSlashes(sf->FullPath);
|
|
|
|
sf->SourceExtension = ext;
|
|
|
|
}
|
2002-08-21 15:54:06 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
char* CCONV cmGetFilenameWithoutExtension(const char* name)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
|
|
|
std::string sres = cmSystemTools::GetFilenameWithoutExtension(name);
|
2016-05-16 14:34:04 +00:00
|
|
|
char* result = (char*)malloc(sres.size() + 1);
|
|
|
|
strcpy(result, sres.c_str());
|
2002-08-21 15:54:06 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
char* CCONV cmGetFilenamePath(const char* name)
|
2002-11-14 16:16:58 +00:00
|
|
|
{
|
|
|
|
std::string sres = cmSystemTools::GetFilenamePath(name);
|
2016-05-16 14:34:04 +00:00
|
|
|
char* result = (char*)malloc(sres.size() + 1);
|
|
|
|
strcpy(result, sres.c_str());
|
2002-11-14 16:16:58 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
char* CCONV cmCapitalized(const char* name)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
|
|
|
std::string sres = cmSystemTools::Capitalized(name);
|
2016-05-16 14:34:04 +00:00
|
|
|
char* result = (char*)malloc(sres.size() + 1);
|
|
|
|
strcpy(result, sres.c_str());
|
2002-08-21 15:54:06 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmCopyFileIfDifferent(const char* name1, const char* name2)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmSystemTools::CopyFileIfDifferent(name1, name2);
|
2002-08-21 15:54:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmRemoveFile(const char* name)
|
2002-08-21 15:54:06 +00:00
|
|
|
{
|
|
|
|
cmSystemTools::RemoveFile(name);
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmDisplayStatus(void* arg, const char* message)
|
2003-07-22 17:14:55 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
2003-07-22 17:53:06 +00:00
|
|
|
mf->DisplayStatus(message, -1);
|
2003-07-22 17:14:55 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV cmFree(void* data)
|
2002-12-11 19:16:55 +00:00
|
|
|
{
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void CCONV DefineSourceFileProperty(void* arg, const char* name,
|
|
|
|
const char* briefDocs,
|
|
|
|
const char* longDocs, int chained)
|
2006-12-07 14:45:32 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmMakefile* mf = static_cast<cmMakefile*>(arg);
|
|
|
|
mf->GetState()->DefineProperty(name, cmProperty::SOURCE_FILE, briefDocs,
|
|
|
|
longDocs, chained != 0);
|
2006-12-07 14:45:32 +00:00
|
|
|
}
|
|
|
|
|
2002-08-29 13:45:34 +00:00
|
|
|
} // close the extern "C" scope
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCAPI cmStaticCAPI = {
|
2002-08-26 14:52:04 +00:00
|
|
|
cmGetClientData,
|
2002-10-08 19:55:04 +00:00
|
|
|
cmGetTotalArgumentSize,
|
|
|
|
cmFreeArguments,
|
|
|
|
cmSetClientData,
|
|
|
|
cmSetError,
|
|
|
|
cmAddCacheDefinition,
|
|
|
|
cmAddCustomCommand,
|
|
|
|
cmAddDefineFlag,
|
|
|
|
cmAddDefinition,
|
|
|
|
cmAddExecutable,
|
|
|
|
cmAddLibrary,
|
|
|
|
cmAddLinkDirectoryForTarget,
|
|
|
|
cmAddLinkLibraryForTarget,
|
|
|
|
cmAddUtilityCommand,
|
|
|
|
cmCommandExists,
|
|
|
|
cmExecuteCommand,
|
|
|
|
cmExpandSourceListArguments,
|
|
|
|
cmExpandVariablesInString,
|
|
|
|
cmGetCacheMajorVersion,
|
|
|
|
cmGetCacheMinorVersion,
|
|
|
|
cmGetCurrentDirectory,
|
|
|
|
cmGetCurrentOutputDirectory,
|
|
|
|
cmGetDefinition,
|
|
|
|
cmGetHomeDirectory,
|
|
|
|
cmGetHomeOutputDirectory,
|
|
|
|
cmGetMajorVersion,
|
|
|
|
cmGetMinorVersion,
|
|
|
|
cmGetProjectName,
|
|
|
|
cmGetStartDirectory,
|
|
|
|
cmGetStartOutputDirectory,
|
|
|
|
cmIsOn,
|
2006-03-10 18:06:26 +00:00
|
|
|
|
2002-10-08 19:55:04 +00:00
|
|
|
cmAddSource,
|
|
|
|
cmCreateSourceFile,
|
2002-12-11 19:16:55 +00:00
|
|
|
cmDestroySourceFile,
|
2002-10-08 19:55:04 +00:00
|
|
|
cmGetSource,
|
|
|
|
cmSourceFileAddDepend,
|
|
|
|
cmSourceFileGetProperty,
|
|
|
|
cmSourceFileGetPropertyAsBool,
|
|
|
|
cmSourceFileGetSourceName,
|
2002-11-14 16:03:08 +00:00
|
|
|
cmSourceFileGetFullPath,
|
2002-10-08 19:55:04 +00:00
|
|
|
cmSourceFileSetName,
|
|
|
|
cmSourceFileSetName2,
|
|
|
|
cmSourceFileSetProperty,
|
2006-03-10 18:06:26 +00:00
|
|
|
|
2002-10-08 19:55:04 +00:00
|
|
|
cmCapitalized,
|
|
|
|
cmCopyFileIfDifferent,
|
|
|
|
cmGetFilenameWithoutExtension,
|
2002-11-14 16:16:58 +00:00
|
|
|
cmGetFilenamePath,
|
2002-10-08 19:55:04 +00:00
|
|
|
cmRemoveFile,
|
2002-12-11 19:16:55 +00:00
|
|
|
cmFree,
|
2003-06-03 14:30:23 +00:00
|
|
|
|
|
|
|
cmAddCustomCommandToOutput,
|
|
|
|
cmAddCustomCommandToTarget,
|
2003-07-23 18:31:30 +00:00
|
|
|
cmDisplayStatus,
|
2006-12-07 14:45:32 +00:00
|
|
|
cmCreateNewSourceFile,
|
|
|
|
DefineSourceFileProperty,
|
2002-08-26 14:52:04 +00:00
|
|
|
};
|