mirror of
https://github.com/reactos/CMake.git
synced 2024-11-23 19:49:51 +00:00
ENH: Add support for preinstall for cmake generated projects when packaging them
This commit is contained in:
parent
e4f3568099
commit
bad1215a85
@ -12,7 +12,7 @@ MACRO(cpack_set_if_not_set name value)
|
||||
ENDMACRO(cpack_set_if_not_set)
|
||||
|
||||
# Set the package name
|
||||
cpack_set_if_not_set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
|
||||
cpack_set_if_not_set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
|
||||
cpack_set_if_not_set(CPACK_PACKAGE_VERSION_MAJOR "0")
|
||||
cpack_set_if_not_set(CPACK_PACKAGE_VERSION_MINOR "1")
|
||||
cpack_set_if_not_set(CPACK_PACKAGE_VERSION_PATCH "1")
|
||||
@ -20,7 +20,7 @@ cpack_set_if_not_set(CPACK_PACKAGE_VERSION
|
||||
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
|
||||
cpack_set_if_not_set(CPACK_PACKAGE_VENDOR "Humanity")
|
||||
cpack_set_if_not_set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
|
||||
"${PROJECT_NAME} built using CMake")
|
||||
"${CMAKE_PROJECT_NAME} built using CMake")
|
||||
|
||||
cpack_set_if_not_set(CPACK_PACKAGE_DESCRIPTION_FILE
|
||||
"${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
|
||||
@ -70,6 +70,7 @@ ENDIF(NOT CPACK_GENERATOR)
|
||||
cpack_set_if_not_set(CPACK_BINARY_DIR "${CMAKE_BINARY_DIR}")
|
||||
cpack_set_if_not_set(CPACK_INSTALL_CMAKE_PROJECTS
|
||||
"${CMAKE_BINARY_DIR};${CMAKE_PROJECT_NAME}")
|
||||
cpack_set_if_not_set(CPACK_CMAKE_GENERATOR "${CMAKE_GENERATOR}")
|
||||
|
||||
SET(_CPACK_UNUSED_VARIABLES_)
|
||||
GET_CMAKE_PROPERTY(res VARIABLES)
|
||||
|
@ -225,14 +225,25 @@ int cmCPackGenericGenerator::InstallProject()
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying file: "
|
||||
<< inFile.c_str() << " -> " << filePath.c_str() << std::endl);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const char* cmakeProjects
|
||||
= this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
|
||||
const char* cmakeGenerator
|
||||
= this->GetOption("CPACK_CMAKE_GENERATOR");
|
||||
if ( cmakeProjects )
|
||||
{
|
||||
if ( !cmakeGenerator )
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||
"CPACK_INSTALL_CMAKE_PROJECTS is specified, but CPACK_CMAKE_GENERATOR "
|
||||
"is not. CPACK_CMAKE_GENERATOR is required to install the project."
|
||||
<< std::endl);
|
||||
return 0;
|
||||
}
|
||||
std::vector<std::string> cmakeProjectsVector;
|
||||
cmSystemTools::ExpandListArgument(cmakeProjects,
|
||||
cmakeProjectsVector);
|
||||
@ -244,9 +255,53 @@ int cmCPackGenericGenerator::InstallProject()
|
||||
std::string installDirectory = it->c_str();
|
||||
++it;
|
||||
std::string installProjectName = it->c_str();
|
||||
std::string installFile = installDirectory + "/cmake_install.cmake";
|
||||
|
||||
const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
|
||||
cmGlobalGenerator* globalGenerator
|
||||
= this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator(
|
||||
cmakeGenerator);
|
||||
|
||||
// Does this generator require pre-install?
|
||||
if ( globalGenerator->GetPreinstallTargetName() )
|
||||
{
|
||||
globalGenerator->FindMakeProgram(this->MakefileMap);
|
||||
const char* cmakeMakeProgram
|
||||
= this->MakefileMap->GetDefinition("CMAKE_MAKE_PROGRAM");
|
||||
std::string buildCommand
|
||||
= globalGenerator->GenerateBuildCommand(cmakeMakeProgram,
|
||||
installProjectName.c_str(), 0,
|
||||
globalGenerator->GetPreinstallTargetName(),
|
||||
buildConfig, false);
|
||||
cmCPackLogger(cmCPackLog::LOG_DEBUG,
|
||||
"- Install command: " << buildCommand << std::endl);
|
||||
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
|
||||
"- Run preinstall target for: " << installProjectName << std::endl);
|
||||
std::string output;
|
||||
int retVal = 1;
|
||||
bool resB = cmSystemTools::RunSingleCommand(buildCommand.c_str(), &output,
|
||||
&retVal, installDirectory.c_str(), this->GeneratorVerbose, 0);
|
||||
if ( !resB || retVal )
|
||||
{
|
||||
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
||||
tmpFile += "/PreinstallOutput.log";
|
||||
cmGeneratedFileStream ofs(tmpFile.c_str());
|
||||
ofs << "# Run command: " << buildCommand.c_str() << std::endl
|
||||
<< "# Directory: " << installDirectory.c_str() << std::endl
|
||||
<< "# Output:" << std::endl
|
||||
<< output.c_str() << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||
"Problem running install command: " << buildCommand.c_str()
|
||||
<< std::endl
|
||||
<< "Please check " << tmpFile.c_str() << " for errors"
|
||||
<< std::endl);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
delete globalGenerator;
|
||||
|
||||
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
|
||||
"- Install project: " << installProjectName << std::endl);
|
||||
std::string installFile = installDirectory + "/cmake_install.cmake";
|
||||
cmake cm;
|
||||
cmGlobalGenerator gg;
|
||||
gg.SetCMakeInstance(&cm);
|
||||
@ -257,7 +312,6 @@ int cmCPackGenericGenerator::InstallProject()
|
||||
{
|
||||
mf->AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
|
||||
}
|
||||
const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
|
||||
if ( buildConfig && *buildConfig )
|
||||
{
|
||||
mf->AddDefinition("BUILD_TYPE", buildConfig);
|
||||
|
@ -175,6 +175,14 @@ public:
|
||||
configuration. This is valid during generation only. */
|
||||
cmTargetManifest const& GetTargetManifest() { return this->TargetManifest; }
|
||||
|
||||
virtual const char* GetAllTargetName() { return "ALL_BUILD"; }
|
||||
virtual const char* GetInstallTargetName() { return "INSTALL"; }
|
||||
virtual const char* GetPreinstallTargetName() { return 0; }
|
||||
virtual const char* GetTestTargetName() { return "RUN_TESTS"; }
|
||||
virtual const char* GetPackageTargetName() { return "PACKAGE"; }
|
||||
virtual const char* GetEditCacheTargetName() { return 0; }
|
||||
virtual const char* GetRebuildCacheTargetName() { return 0; }
|
||||
|
||||
protected:
|
||||
// Fill the ProjectMap, this must be called after LocalGenerators
|
||||
// has been populated.
|
||||
@ -189,14 +197,6 @@ protected:
|
||||
const cmCustomCommandLines* commandLines,
|
||||
std::vector<std::string> depends, bool depends_on_all = false);
|
||||
|
||||
virtual const char* GetAllTargetName() { return "ALL_BUILD"; }
|
||||
virtual const char* GetInstallTargetName() { return "INSTALL"; }
|
||||
virtual const char* GetPreinstallTargetName() { return 0; }
|
||||
virtual const char* GetTestTargetName() { return "RUN_TESTS"; }
|
||||
virtual const char* GetPackageTargetName() { return "PACKAGE"; }
|
||||
virtual const char* GetEditCacheTargetName() { return 0; }
|
||||
virtual const char* GetRebuildCacheTargetName() { return 0; }
|
||||
|
||||
bool ForceUnixPaths;
|
||||
bool ToolSupportsColorVT100;
|
||||
cmStdString FindMakeProgramFile;
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "cmake.h"
|
||||
#include "cmDocumentation.h"
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static const cmDocumentationEntry cmDocumentationName[] =
|
||||
{
|
||||
@ -207,8 +208,6 @@ int main (int argc, char *argv[])
|
||||
nocwd = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// If there is a testing input file, check for documentation options
|
||||
// only if there are actually arguments. We want running without
|
||||
// arguments to run tests.
|
||||
|
Loading…
Reference in New Issue
Block a user