diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2006-04-10 17:44:39 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2006-04-10 17:44:39 (GMT) |
commit | bad1215a853a24f9e8145f6157be9e27c0b83cd0 (patch) | |
tree | 4164a0426efbe7967fcd865174c09bb243e530ac | |
parent | e4f3568099830233e0620c8824bb0a07376cd5a5 (diff) | |
download | CMake-bad1215a853a24f9e8145f6157be9e27c0b83cd0.zip CMake-bad1215a853a24f9e8145f6157be9e27c0b83cd0.tar.gz CMake-bad1215a853a24f9e8145f6157be9e27c0b83cd0.tar.bz2 |
ENH: Add support for preinstall for cmake generated projects when packaging them
-rw-r--r-- | Modules/CPack.cmake | 5 | ||||
-rw-r--r-- | Source/CPack/cmCPackGenericGenerator.cxx | 58 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 16 | ||||
-rw-r--r-- | Source/ctest.cxx | 3 |
4 files changed, 68 insertions, 14 deletions
diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake index c20da16..86eca58 100644 --- a/Modules/CPack.cmake +++ b/Modules/CPack.cmake @@ -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) diff --git a/Source/CPack/cmCPackGenericGenerator.cxx b/Source/CPack/cmCPackGenericGenerator.cxx index 14f9cda..7669c5f 100644 --- a/Source/CPack/cmCPackGenericGenerator.cxx +++ b/Source/CPack/cmCPackGenericGenerator.cxx @@ -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); diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 3911d9e..bd21de0 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -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; diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 6a8c90c..ce6235d 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -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. |