Skip to content

Commit

Permalink
Add an "installed file" property scope
Browse files Browse the repository at this point in the history
Teach set_property and get_property an "INSTALL" property type to be
associated with install-tree file paths.  Make the properties available
to CPack for use during packaging.  Add a "prop_inst" Sphinx domain
object type for documentation of such properties.
  • Loading branch information
ngladitz authored and bradking committed May 28, 2014
1 parent 032961c commit 15a8af2
Show file tree
Hide file tree
Showing 42 changed files with 612 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Help/manual/cmake-developer.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ documentation:
See the :manual:`cmake-policies(7)` manual
and the :command:`cmake_policy` command.

``prop_cache, prop_dir, prop_gbl, prop_sf, prop_test, prop_tgt``
A CMake cache, directory, global, source file, test, or target
property, respectively. See the :manual:`cmake-properties(7)` manual
and the :command:`set_property` command.
``prop_cache, prop_dir, prop_gbl, prop_sf, prop_inst, prop_test, prop_tgt``
A CMake cache, directory, global, source file, installed file, test,
or target property, respectively. See the :manual:`cmake-properties(7)`
manual and the :command:`set_property` command.

``variable``
A CMake language variable.
Expand Down
6 changes: 6 additions & 0 deletions Help/manual/cmake-properties.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,9 @@ Properties on Cache Entries
/prop_cache/STRINGS
/prop_cache/TYPE
/prop_cache/VALUE

Properties on Installed Files
=============================

.. toctree::
:maxdepth: 1
4 changes: 4 additions & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ set(SRCS
cmComputeLinkInformation.h
cmComputeTargetDepends.h
cmComputeTargetDepends.cxx
cmCPackPropertiesGenerator.h
cmCPackPropertiesGenerator.cxx
cmCryptoHash.cxx
cmCryptoHash.h
cmCustomCommand.cxx
Expand Down Expand Up @@ -243,6 +245,8 @@ set(SRCS
cmInstallGenerator.h
cmInstallGenerator.cxx
cmInstallExportGenerator.cxx
cmInstalledFile.h
cmInstalledFile.cxx
cmInstallFilesGenerator.h
cmInstallFilesGenerator.cxx
cmInstallScriptGenerator.h
Expand Down
8 changes: 8 additions & 0 deletions Source/CPack/cmCPackGenerator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,14 @@ int cmCPackGenerator::CleanTemporaryDirectory()
return 1;
}

//----------------------------------------------------------------------
cmInstalledFile const* cmCPackGenerator::GetInstalledFile(
std::string const& name) const
{
cmake const* cm = this->MakefileMap->GetCMakeInstance();
return cm->GetInstalledFile(name);
}

//----------------------------------------------------------------------
int cmCPackGenerator::PrepareGroupingKind()
{
Expand Down
3 changes: 3 additions & 0 deletions Source/CPack/cmCPackGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

class cmMakefile;
class cmCPackLog;
class cmInstalledFile;

/** \class cmCPackGenerator
* \brief A superclass of all CPack Generators
Expand Down Expand Up @@ -129,6 +130,8 @@ class cmCPackGenerator : public cmObject

int CleanTemporaryDirectory();

cmInstalledFile const* GetInstalledFile(std::string const& name) const;

virtual const char* GetOutputExtension() { return ".cpack"; }
virtual const char* GetOutputPostfix() { return 0; }

Expand Down
9 changes: 5 additions & 4 deletions Source/CPack/cpack.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ int main (int argc, char const* const* argv)
return 1;
}

if ( !cpackBuildConfig.empty() )
{
globalMF->AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str());
}

if ( cmSystemTools::FileExists(cpackConfigFile.c_str()) )
{
cpackConfigFile =
Expand Down Expand Up @@ -317,10 +322,6 @@ int main (int argc, char const* const* argv)
cpackProjectDirectory.c_str());
}
}
if ( !cpackBuildConfig.empty() )
{
globalMF->AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str());
}
cpackDefinitions::MapType::iterator cdit;
for ( cdit = definitions.Map.begin();
cdit != definitions.Map.end();
Expand Down
45 changes: 45 additions & 0 deletions Source/cmCPackPropertiesGenerator.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "cmCPackPropertiesGenerator.h"

#include "cmLocalGenerator.h"

cmCPackPropertiesGenerator::cmCPackPropertiesGenerator(
cmMakefile* mf,
cmInstalledFile const& installedFile,
std::vector<std::string> const& configurations):
cmScriptGenerator("CPACK_BUILD_CONFIG", configurations),
Makefile(mf),
InstalledFile(installedFile)
{
this->ActionsPerConfig = true;
}

void cmCPackPropertiesGenerator::GenerateScriptForConfig(std::ostream& os,
const std::string& config, Indent const& indent)
{
std::string const& expandedFileName =
this->InstalledFile.GetNameExpression().Evaluate(this->Makefile, config);

cmInstalledFile::PropertyMapType const& properties =
this->InstalledFile.GetProperties();

for(cmInstalledFile::PropertyMapType::const_iterator i = properties.begin();
i != properties.end(); ++i)
{
std::string const& name = i->first;
cmInstalledFile::Property const& property = i->second;

os << indent << "set_property(INSTALL " <<
cmLocalGenerator::EscapeForCMake(expandedFileName) << " PROPERTY " <<
cmLocalGenerator::EscapeForCMake(name);

for(cmInstalledFile::ExpressionVectorType::const_iterator
j = property.ValueExpressions.begin();
j != property.ValueExpressions.end(); ++j)
{
std::string value = (*j)->Evaluate(this->Makefile, config);
os << " " << cmLocalGenerator::EscapeForCMake(value);
}

os << ")\n";
}
}
38 changes: 38 additions & 0 deletions Source/cmCPackPropertiesGenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2014 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.
============================================================================*/
#ifndef cmCPackPropertiesGenerator_h
#define cmCPackPropertiesGenerator_h

#include "cmScriptGenerator.h"
#include "cmInstalledFile.h"

/** \class cmCPackPropertiesGenerator
* \brief Support class for generating CPackProperties.cmake.
*
*/
class cmCPackPropertiesGenerator: public cmScriptGenerator
{
public:
cmCPackPropertiesGenerator(
cmMakefile* mf,
cmInstalledFile const& installedFile,
std::vector<std::string> const& configurations);

protected:
virtual void GenerateScriptForConfig(std::ostream& os,
const std::string& config, Indent const& indent);

cmMakefile* Makefile;
cmInstalledFile const& InstalledFile;
};

#endif
37 changes: 36 additions & 1 deletion Source/cmGetPropertyCommand.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
{
scope = cmProperty::CACHE;
}
else if(args[1] == "INSTALL")
{
scope = cmProperty::INSTALL;
}
else
{
cmOStringStream e;
e << "given invalid scope " << args[1] << ". "
<< "Valid scopes are "
<< "GLOBAL, DIRECTORY, TARGET, SOURCE, TEST, VARIABLE, CACHE.";
<< "GLOBAL, DIRECTORY, TARGET, SOURCE, TEST, VARIABLE, CACHE, INSTALL.";
this->SetError(e.str());
return false;
}
Expand Down Expand Up @@ -190,6 +194,7 @@ ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
case cmProperty::TEST: return this->HandleTestMode();
case cmProperty::VARIABLE: return this->HandleVariableMode();
case cmProperty::CACHE: return this->HandleCacheMode();
case cmProperty::INSTALL: return this->HandleInstallMode();

case cmProperty::CACHED_VARIABLE:
break; // should never happen
Expand Down Expand Up @@ -395,3 +400,33 @@ bool cmGetPropertyCommand::HandleCacheMode()
this->StoreResult(value);
return true;
}

//----------------------------------------------------------------------------
bool cmGetPropertyCommand::HandleInstallMode()
{
if(this->Name.empty())
{
this->SetError("not given name for INSTALL scope.");
return false;
}

// Get the installed file.
cmake* cm = this->Makefile->GetCMakeInstance();

if(cmInstalledFile* file = cm->GetOrCreateInstalledFile(
this->Makefile, this->Name))
{
std::string value;
bool isSet = file->GetProperty(this->PropertyName, value);

return this->StoreResult(isSet ? value.c_str() : 0);
}
else
{
cmOStringStream e;
e << "given INSTALL name that could not be found or created: "
<< this->Name;
this->SetError(e.str());
return false;
}
}
1 change: 1 addition & 0 deletions Source/cmGetPropertyCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class cmGetPropertyCommand : public cmCommand
bool HandleTestMode();
bool HandleVariableMode();
bool HandleCacheMode();
bool HandleInstallMode();
};

#endif
44 changes: 44 additions & 0 deletions Source/cmGlobalGenerator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "cmGeneratorExpression.h"
#include "cmGeneratorExpressionEvaluationFile.h"
#include "cmExportBuildFileGenerator.h"
#include "cmCPackPropertiesGenerator.h"

#include <cmsys/Directory.hxx>
#include <cmsys/FStream.hxx>
Expand Down Expand Up @@ -1269,6 +1270,13 @@ void cmGlobalGenerator::Generate()
}
this->SetCurrentLocalGenerator(0);

if(!this->GenerateCPackPropertiesFile())
{
this->GetCMakeInstance()->IssueMessage(
cmake::FATAL_ERROR, "Could not write CPack properties file.",
cmListFileBacktrace());
}

for (std::map<std::string, cmExportBuildFileGenerator*>::iterator
it = this->BuildExportSets.begin(); it != this->BuildExportSets.end();
++it)
Expand Down Expand Up @@ -3014,3 +3022,39 @@ std::string cmGlobalGenerator::ExpandCFGIntDir(const std::string& str,
{
return str;
}

//----------------------------------------------------------------------------
bool cmGlobalGenerator::GenerateCPackPropertiesFile()
{
cmake::InstalledFilesMap const& installedFiles =
this->CMakeInstance->GetInstalledFiles();

cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();

std::vector<std::string> configs;
std::string config = mf->GetConfigurations(configs, false);

std::string path = this->CMakeInstance->GetStartOutputDirectory();
path += "/CPackProperties.cmake";

if(!cmSystemTools::FileExists(path.c_str()) && installedFiles.empty())
{
return true;
}

cmGeneratedFileStream file(path.c_str());
file << "# CPack properties\n";

for(cmake::InstalledFilesMap::const_iterator i = installedFiles.begin();
i != installedFiles.end(); ++i)
{
cmInstalledFile const& installedFile = i->second;

cmCPackPropertiesGenerator cpackPropertiesGenerator(
mf, installedFile, configs);

cpackPropertiesGenerator.Generate(file, config, configs);
}

return true;
}
2 changes: 2 additions & 0 deletions Source/cmGlobalGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ class cmGlobalGenerator

virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;

bool GenerateCPackPropertiesFile();

protected:
typedef std::vector<cmLocalGenerator*> GeneratorVector;
// for a project collect all its targets by following depend
Expand Down
Loading

0 comments on commit 15a8af2

Please sign in to comment.