summaryrefslogtreecommitdiffstats
path: root/Source/cmInstallTargetGenerator.cxx
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2007-06-15 17:00:54 (GMT)
committerAlexander Neundorf <neundorf@kde.org>2007-06-15 17:00:54 (GMT)
commit82375189948c5740d57415c305534500984fc14f (patch)
tree2ac4574b7cf7405d772513656f0b31304777c840 /Source/cmInstallTargetGenerator.cxx
parent69d362846161e14002377a66e7505219b2b6af27 (diff)
downloadCMake-82375189948c5740d57415c305534500984fc14f.zip
CMake-82375189948c5740d57415c305534500984fc14f.tar.gz
CMake-82375189948c5740d57415c305534500984fc14f.tar.bz2
BUG: don't strip static libraries, it removes their symbol table, dynamic
libs have an extra symbol table so they still work stripped Alex
Diffstat (limited to 'Source/cmInstallTargetGenerator.cxx')
-rw-r--r--Source/cmInstallTargetGenerator.cxx27
1 files changed, 16 insertions, 11 deletions
diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx
index c38bcc7..1205f5c 100644
--- a/Source/cmInstallTargetGenerator.cxx
+++ b/Source/cmInstallTargetGenerator.cxx
@@ -182,10 +182,10 @@ void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
quotedFullDestinationFilename += "/";
quotedFullDestinationFilename += cmSystemTools::GetFilenameName(fromFile);
quotedFullDestinationFilename += "\"";
-
+
this->AddRanlibRule(os, type, quotedFullDestinationFilename);
- this->AddStripRule(os, quotedFullDestinationFilename, optional);
+ this->AddStripRule(os, type, quotedFullDestinationFilename, optional);
}
//----------------------------------------------------------------------------
@@ -453,10 +453,18 @@ void cmInstallTargetGenerator
}
void cmInstallTargetGenerator::AddStripRule(std::ostream& os,
+ cmTarget::TargetType type,
const std::string& quotedFullDestinationFilename,
bool optional)
{
+ // don't strip static libraries, because it removes the only symbol table
+ // they have so you can't link to them anymore
+ if(type == cmTarget::STATIC_LIBRARY)
+ {
+ return;
+ }
+
// Don't handle OSX Bundles.
if(this->Target->GetMakefile()->IsOn("APPLE") &&
this->Target->GetPropertyAsBool("MACOSX_BUNDLE"))
@@ -469,21 +477,18 @@ void cmInstallTargetGenerator::AddStripRule(std::ostream& os,
return;
}
- os << "IF(CMAKE_INSTALL_DO_STRIP";
+ std::string optionalString;
if (optional)
{
- os << " AND EXISTS " << quotedFullDestinationFilename;
+ optionalString = " AND EXISTS ";
+ optionalString += quotedFullDestinationFilename;
}
- os << ")\n";
+
+ os << "IF(CMAKE_INSTALL_DO_STRIP" << optionalString << ")\n";
os << " EXECUTE_PROCESS(COMMAND \""
<< this->Target->GetMakefile()->GetDefinition("CMAKE_STRIP")
<< "\" " << quotedFullDestinationFilename << " )\n";
- os << "ENDIF(CMAKE_INSTALL_DO_STRIP";
- if (optional)
- {
- os << " AND EXISTS " << quotedFullDestinationFilename;
- }
- os << ")\n";
+ os << "ENDIF(CMAKE_INSTALL_DO_STRIP" << optionalString << ")\n";
}
void cmInstallTargetGenerator::AddRanlibRule(std::ostream& os,
n261' href='#n261'>261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium

  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
#include "cmGeneratorExpression.h"

#include "cmMakefile.h"
#include "cmTarget.h"
#include "assert.h"

#include <cmsys/String.h>

#include "cmGeneratorExpressionEvaluator.h"
#include "cmGeneratorExpressionLexer.h"
#include "cmGeneratorExpressionParser.h"
#include "cmGeneratorExpressionDAGChecker.h"

//----------------------------------------------------------------------------
cmGeneratorExpression::cmGeneratorExpression(
  cmListFileBacktrace const& backtrace):
  Backtrace(backtrace)
{
}

//----------------------------------------------------------------------------
cmsys::auto_ptr<cmCompiledGeneratorExpression>
cmGeneratorExpression::Parse(std::string const& input)
{
  return this->Parse(input.c_str());
}

//----------------------------------------------------------------------------
cmsys::auto_ptr<cmCompiledGeneratorExpression>
cmGeneratorExpression::Parse(const char* input)
{
  return cmsys::auto_ptr<cmCompiledGeneratorExpression>(
                                      new cmCompiledGeneratorExpression(
                                        this->Backtrace,
                                        input));
}

cmGeneratorExpression::~cmGeneratorExpression()
{
}

//----------------------------------------------------------------------------
const char *cmCompiledGeneratorExpression::Evaluate(
  cmMakefile* mf, const char* config, bool quiet,
  cmTarget *headTarget,
  cmGeneratorExpressionDAGChecker *dagChecker) const
{
  return this->Evaluate(mf,
                        config,
                        quiet,
                        headTarget,
                        headTarget,
                        dagChecker);
}

//----------------------------------------------------------------------------
const char *cmCompiledGeneratorExpression::Evaluate(
  cmMakefile* mf, const char* config, bool quiet,
  cmTarget *headTarget,
  cmTarget *currentTarget,
  cmGeneratorExpressionDAGChecker *dagChecker) const
{
  if (!this->NeedsParsing)
    {
    return this->Input.c_str();
    }

  this->Output = "";

  std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
                                                  = this->Evaluators.begin();
  const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
                                                  = this->Evaluators.end();

  cmGeneratorExpressionContext context;
  context.Makefile = mf;
  context.Config = config;
  context.Quiet = quiet;
  context.HadError = false;
  context.HadContextSensitiveCondition = false;
  context.HeadTarget = headTarget;
  context.CurrentTarget = currentTarget ? currentTarget : headTarget;
  context.Backtrace = this->Backtrace;

  for ( ; it != end; ++it)
    {
    this->Output += (*it)->Evaluate(&context, dagChecker);

    for(std::set<cmStdString>::const_iterator
          p = context.SeenTargetProperties.begin();
          p != context.SeenTargetProperties.end(); ++p)
      {
      this->SeenTargetProperties.insert(*p);
      }
    if (context.HadError)
      {
      this->Output = "";
      break;
      }
    }
  if (!context.HadError)
    {
    this->HadContextSensitiveCondition = context.HadContextSensitiveCondition;
    }

  this->DependTargets = context.DependTargets;
  this->AllTargetsSeen = context.AllTargets;
  // TODO: Return a std::string from here instead?
  return this->Output.c_str();
}

cmCompiledGeneratorExpression::cmCompiledGeneratorExpression(
              cmListFileBacktrace const& backtrace,
              const char *input)
  : Backtrace(backtrace), Input(input ? input : ""),
    HadContextSensitiveCondition(false)
{
  cmGeneratorExpressionLexer l;
  std::vector<cmGeneratorExpressionToken> tokens =
                                              l.Tokenize(this->Input.c_str());
  this->NeedsParsing = l.GetSawGeneratorExpression();

  if (this->NeedsParsing)
    {
    cmGeneratorExpressionParser p(tokens);
    p.Parse(this->Evaluators);
    }
}


//----------------------------------------------------------------------------
cmCompiledGeneratorExpression::~cmCompiledGeneratorExpression()
{
  std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
                                                  = this->Evaluators.begin();
  const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
                                                  = this->Evaluators.end();

  for ( ; it != end; ++it)
    {
    delete *it;
    }
}

//----------------------------------------------------------------------------
std::string cmGeneratorExpression::StripEmptyListElements(
                                                    const std::string &input)
{
  std::string result;

  const char *c = input.c_str();
  bool skipSemiColons = true;
  for ( ; *c; ++c)
    {
    if(c[0] == ';')
      {
      if(skipSemiColons)
        {
        continue;
        }
      skipSemiColons = true;
      }
    else
      {
      skipSemiColons = false;
      }
    result += *c;
    }

  if (!result.empty() && *(result.end() - 1) == ';')
    {
    result.resize(result.size() - 1);
    }

  return result;
}

//----------------------------------------------------------------------------
static std::string stripAllGeneratorExpressions(const std::string &input)
{
  std::string result;
  std::string::size_type pos = 0;
  std::string::size_type lastPos = pos;
  int nestingLevel = 0;
  while((pos = input.find("$<", lastPos)) != input.npos)
    {
    result += input.substr(lastPos, pos - lastPos);
    pos += 2;
    nestingLevel = 1;
    const char *c = input.c_str() + pos;
    const char * const cStart = c;
    for ( ; *c; ++c)
      {
      if(c[0] == '$' && c[1] == '<')
        {
        ++nestingLevel;
        ++c;
        continue;
        }
      if(c[0] == '>')
        {
        --nestingLevel;
        if (nestingLevel == 0)
          {
          break;
          }
        }
      }
    const std::string::size_type traversed = (c - cStart) + 1;
    if (!*c)
      {
      result += "$<" + input.substr(pos, traversed);
      }
    pos += traversed;
    lastPos = pos;
    }
  if (nestingLevel == 0)
    {
    result += input.substr(lastPos);
    }
  return cmGeneratorExpression::StripEmptyListElements(result);
}

//----------------------------------------------------------------------------
static void prefixItems(const std::string &content, std::string &result,
                        const std::string &prefix)
{
  std::vector<std::string> entries;
  cmGeneratorExpression::Split(content, entries);
  for(std::vector<std::string>::const_iterator ei = entries.begin();
      ei != entries.end(); ++ei)
    {
    if (!cmSystemTools::FileIsFullPath(ei->c_str())
        && cmGeneratorExpression::Find(*ei) == std::string::npos)
      {
      result += prefix;
      }
    result += *ei;
    }
}

//----------------------------------------------------------------------------
static std::string stripExportInterface(const std::string &input,
                          cmGeneratorExpression::PreprocessContext context,
                          bool resolveRelative)
{
  std::string result;

  int nestingLevel = 0;
  std::string::size_type pos = 0;
  std::string::size_type lastPos = pos;
  while (true)
    {
    std::string::size_type bPos = input.find("$<BUILD_INTERFACE:", lastPos);
    std::string::size_type iPos = input.find("$<INSTALL_INTERFACE:", lastPos);

    if (bPos == std::string::npos && iPos == std::string::npos)
      {
      break;
      }

    if (bPos == std::string::npos)
      {
      pos = iPos;
      }
    else if (iPos == std::string::npos)
      {
      pos = bPos;
      }
    else
      {
      pos = (bPos < iPos) ? bPos : iPos;
      }

    result += input.substr(lastPos, pos - lastPos);
    const bool gotInstallInterface = input[pos + 2] == 'I';
    pos += gotInstallInterface ? sizeof("$<INSTALL_INTERFACE:") - 1
                               : sizeof("$<BUILD_INTERFACE:") - 1;
    nestingLevel = 1;
    const char *c = input.c_str() + pos;
    const char * const cStart = c;
    for ( ; *c; ++c)
      {
      if(c[0] == '$' && c[1] == '<')
        {
        ++nestingLevel;
        ++c;
        continue;
        }
      if(c[0] == '>')
        {
        --nestingLevel;
        if (nestingLevel != 0)
          {
          continue;
          }
        if(context == cmGeneratorExpression::BuildInterface
            && !gotInstallInterface)
          {
          result += input.substr(pos, c - cStart);
          }
        else if(context == cmGeneratorExpression::InstallInterface
            && gotInstallInterface)
          {
          const std::string content = input.substr(pos, c - cStart);
          if (resolveRelative)
            {
            prefixItems(content, result, "${_IMPORT_PREFIX}/");
            }
          else
            {
            result += content;
            }
          }
        break;
        }
      }
    const std::string::size_type traversed = (c - cStart) + 1;
    if (!*c)
      {
      result += std::string(gotInstallInterface ? "$<INSTALL_INTERFACE:"
                                                : "$<BUILD_INTERFACE:")
             + input.substr(pos, traversed);
      }
    pos += traversed;
    lastPos = pos;
    }
  if (nestingLevel == 0)
    {
    result += input.substr(lastPos);
    }

  return cmGeneratorExpression::StripEmptyListElements(result);
}

//----------------------------------------------------------------------------
void cmGeneratorExpression::Split(const std::string &input,
                                  std::vector<std::string> &output)
{
  std::string::size_type pos = 0;
  std::string::size_type lastPos = pos;
  while((pos = input.find("$<", lastPos)) != input.npos)
    {
    std::string part = input.substr(lastPos, pos - lastPos);
    std::string preGenex;
    if (!part.empty())
      {
      std::string::size_type startPos = input.rfind(";", pos);
      if (startPos == std::string::npos)
        {
        preGenex = part;
        part = "";
        }
      else if (startPos != pos - 1 && startPos >= lastPos)
        {
        part = input.substr(lastPos, startPos - lastPos);
        preGenex = input.substr(startPos + 1, pos - startPos - 1);
        }
      if(!part.empty())
        {
        cmSystemTools::ExpandListArgument(part.c_str(), output);
        }
      }
    pos += 2;
    int nestingLevel = 1;
    const char *c = input.c_str() + pos;
    const char * const cStart = c;
    for ( ; *c; ++c)
      {
      if(c[0] == '$' && c[1] == '<')
        {
        ++nestingLevel;
        ++c;
        continue;
        }
      if(c[0] == '>')
        {
        --nestingLevel;
        if (nestingLevel == 0)
          {
          break;
          }
        }
      }
    for ( ; *c; ++c)
      {
      // Capture the part after the genex and before the next ';'
      if(c[0] == ';')
        {
        --c;
        break;
        }
      }
    const std::string::size_type traversed = (c - cStart) + 1;
    output.push_back(preGenex + "$<" + input.substr(pos, traversed));
    pos += traversed;
    lastPos = pos;
    }
  if (lastPos < input.size())
    {
    cmSystemTools::ExpandListArgument(input.substr(lastPos), output);
    }
}

//----------------------------------------------------------------------------
std::string cmGeneratorExpression::Preprocess(const std::string &input,
                                              PreprocessContext context,
                                              bool resolveRelative)
{
  if (context == StripAllGeneratorExpressions)
    {
    return stripAllGeneratorExpressions(input);
    }
  else if (context == BuildInterface || context == InstallInterface)
    {
    return stripExportInterface(input, context, resolveRelative);
    }

  assert(!"cmGeneratorExpression::Preprocess called with invalid args");
  return std::string();
}

//----------------------------------------------------------------------------
std::string::size_type cmGeneratorExpression::Find(const std::string &input)
{
  const std::string::size_type openpos = input.find("$<");
  if (openpos != std::string::npos
      && input.find(">", openpos) != std::string::npos)
    {
    return openpos;
    }
  return std::string::npos;
}

//----------------------------------------------------------------------------
bool cmGeneratorExpression::IsValidTargetName(const std::string &input)
{
  cmsys::RegularExpression targetNameValidator;
  // The ':' is supported to allow use with IMPORTED targets. At least
  // Qt 4 and 5 IMPORTED targets use ':' as the namespace delimiter.
  targetNameValidator.compile("^[A-Za-z0-9_.:+-]+$");

  return targetNameValidator.find(input.c_str());
}