From e31dc3abe554cdae307d654df9a245d8e72f55d4 Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Thu, 12 Oct 2006 13:05:50 -0400 Subject: ENH: Several CPack fixes. First, allow user to set CMAKE_MODULE_PATH for CPack; make SetOptionIfNotSet more robust to handle empty options; do test TGZ, STGZ, and TZ, Add handling (and test) of Install Script; set environment variable CMAKE_INSTALL_PREFIX --- Modules/CPack.cmake | 2 ++ Source/CPack/cmCPackGenericGenerator.cxx | 54 +++++++++++++++++++++++++++++++- Source/CPack/cmCPackGenericGenerator.h | 2 ++ Source/CPack/cpack.cxx | 5 +++ Tests/SimpleInstall/CMakeLists.txt | 3 +- Tests/SimpleInstallS2/CMakeLists.txt | 3 +- 6 files changed, 66 insertions(+), 3 deletions(-) diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake index 4af1169..913d874 100644 --- a/Modules/CPack.cmake +++ b/Modules/CPack.cmake @@ -56,6 +56,8 @@ cpack_set_if_not_set(CPACK_RESOURCE_FILE_README cpack_set_if_not_set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_ROOT}/Templates/CPack.GenericWelcome.txt") +cpack_set_if_not_set(CPACK_MODULE_PATH "${CMAKE_MODULE_PATH}") + IF(CPACK_NSIS_MODIFY_PATH) SET(CPACK_NSIS_MODIFY_PATH ON) ENDIF(CPACK_NSIS_MODIFY_PATH) diff --git a/Source/CPack/cmCPackGenericGenerator.cxx b/Source/CPack/cmCPackGenericGenerator.cxx index b6979dd..b063933 100644 --- a/Source/CPack/cmCPackGenericGenerator.cxx +++ b/Source/CPack/cmCPackGenericGenerator.cxx @@ -184,6 +184,14 @@ int cmCPackGenericGenerator::InstallProject() return 0; } + // If the CPackConfig file sets CPACK_INSTALL_SCRIPT then run them + // as listed + if ( !this->InstallProjectViaInstallScript( + movable, tempInstallDirectory) ) + { + return 0; + } + // If the CPackConfig file sets CPACK_INSTALLED_DIRECTORIES // then glob it and copy it to CPACK_TEMPORARY_DIRECTORY // This is used in Source packageing @@ -258,6 +266,9 @@ int cmCPackGenericGenerator::InstallProjectViaInstallCommands( const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS"); if ( installCommands && *installCommands ) { + std::string tempInstallDirectoryEnv = "CMAKE_INSTALL_PREFIX="; + tempInstallDirectoryEnv += tempInstallDirectory; + cmSystemTools::PutEnv(tempInstallDirectoryEnv.c_str()); std::vector installCommandsVector; cmSystemTools::ExpandListArgument(installCommands,installCommandsVector); std::vector::iterator it; @@ -391,6 +402,46 @@ int cmCPackGenericGenerator::InstallProjectViaInstalledDirectories( } //---------------------------------------------------------------------- +int cmCPackGenericGenerator::InstallProjectViaInstallScript( + bool movable, const char* tempInstallDirectory) +{ + const char* cmakeScripts + = this->GetOption("CPACK_INSTALL_SCRIPT"); + std::string currentWorkingDirectory = + cmSystemTools::GetCurrentWorkingDirectory(); + cmCPackLogger(cmCPackLog::LOG_OUTPUT, + "- Install scripts: " << cmakeScripts << std::endl); + if ( cmakeScripts && *cmakeScripts ) + { + std::vector cmakeScriptsVector; + cmSystemTools::ExpandListArgument(cmakeScripts, + cmakeScriptsVector); + std::vector::iterator it; + for ( it = cmakeScriptsVector.begin(); + it != cmakeScriptsVector.end(); + ++it ) + { + std::string installScript = it->c_str(); + + cmCPackLogger(cmCPackLog::LOG_OUTPUT, + "- Install script: " << installScript << std::endl); + if ( movable ) + { + this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory); + } + this->SetOptionIfNotSet("CMAKE_CURRENT_BINARY_DIR", tempInstallDirectory); + this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR", tempInstallDirectory); + int res = this->MakefileMap->ReadListFile(0, installScript.c_str()); + if ( cmSystemTools::GetErrorOccuredFlag() || !res ) + { + return 0; + } + } + } + return 1; +} + +//---------------------------------------------------------------------- int cmCPackGenericGenerator::InstallProjectViaInstallCMakeProjects( bool movable, const char* tempInstallDirectory) { @@ -535,7 +586,8 @@ int cmCPackGenericGenerator::InstallProjectViaInstallCMakeProjects( void cmCPackGenericGenerator::SetOptionIfNotSet(const char* op, const char* value) { - if ( this->MakefileMap->GetDefinition(op) ) + const char* def = this->MakefileMap->GetDefinition(op); + if ( def && *def ) { return; } diff --git a/Source/CPack/cmCPackGenericGenerator.h b/Source/CPack/cmCPackGenericGenerator.h index a5a0ef7..afe79c0 100644 --- a/Source/CPack/cmCPackGenericGenerator.h +++ b/Source/CPack/cmCPackGenericGenerator.h @@ -110,6 +110,8 @@ protected: //! Run install commands if specified virtual int InstallProjectViaInstallCommands( bool movable, const char* tempInstallDirectory); + virtual int InstallProjectViaInstallScript( + bool movable, const char* tempInstallDirectory); virtual int InstallProjectViaInstalledDirectories( bool movable, const char* tempInstallDirectory); virtual int InstallProjectViaInstallCMakeProjects( diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 7c22d70..5a63a49 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -301,6 +301,11 @@ int main (int argc, char *argv[]) globalMF->AddDefinition(cdit->first.c_str(), cdit->second.c_str()); } + const char* cpackModulesPath = globalMF->GetDefinition("CPACK_MODULE_PATH"); + if ( cpackModulesPath ) + { + globalMF->AddDefinition("CMAKE_MODULE_PATH", cpackModulesPath); + } const char* genList = globalMF->GetDefinition("CPACK_GENERATOR"); if ( !genList ) { diff --git a/Tests/SimpleInstall/CMakeLists.txt b/Tests/SimpleInstall/CMakeLists.txt index 3d8cdb8..a762915 100644 --- a/Tests/SimpleInstall/CMakeLists.txt +++ b/Tests/SimpleInstall/CMakeLists.txt @@ -218,6 +218,7 @@ ENDIF(CMAKE_CONFIGURATION_TYPES) # Dummy test of CPack SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Test of packaging with cpack") SET(CPACK_PACKAGE_VENDOR "Kitware") +SET(CPACK_INSTALL_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/PackageScript.cmake") IF(WIN32 AND NOT UNIX) FIND_PROGRAM(NSIS_MAKENSIS NAMES makensis @@ -229,7 +230,7 @@ IF(WIN32 AND NOT UNIX) ENDIF(NOT NSIS_MAKENSIS) ENDIF(WIN32 AND NOT UNIX) IF(UNIX AND NOT APPLE) - # SET(CPACK_GENERATOR "TGZ;STGZ") + SET(CPACK_GENERATOR "TGZ;STGZ;TZ") # FIND_PROGRAM(found_compress # NAMES compress) # IF(found_compress) diff --git a/Tests/SimpleInstallS2/CMakeLists.txt b/Tests/SimpleInstallS2/CMakeLists.txt index 3d8cdb8..a762915 100644 --- a/Tests/SimpleInstallS2/CMakeLists.txt +++ b/Tests/SimpleInstallS2/CMakeLists.txt @@ -218,6 +218,7 @@ ENDIF(CMAKE_CONFIGURATION_TYPES) # Dummy test of CPack SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Test of packaging with cpack") SET(CPACK_PACKAGE_VENDOR "Kitware") +SET(CPACK_INSTALL_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/PackageScript.cmake") IF(WIN32 AND NOT UNIX) FIND_PROGRAM(NSIS_MAKENSIS NAMES makensis @@ -229,7 +230,7 @@ IF(WIN32 AND NOT UNIX) ENDIF(NOT NSIS_MAKENSIS) ENDIF(WIN32 AND NOT UNIX) IF(UNIX AND NOT APPLE) - # SET(CPACK_GENERATOR "TGZ;STGZ") + SET(CPACK_GENERATOR "TGZ;STGZ;TZ") # FIND_PROGRAM(found_compress # NAMES compress) # IF(found_compress) -- cgit v0.12