ENH: Added INSTALL(CODE) mode to allow inline specification of install script code. This reduces the need for configuring an install script that needs some variable settings because the install code can set thing up first.

This commit is contained in:
Brad King 2006-04-12 22:04:50 -04:00
parent 58641b2ceb
commit d4c5fe840b
10 changed files with 61 additions and 7 deletions

View File

@ -35,6 +35,10 @@ bool cmInstallCommand::InitialPass(std::vector<std::string> const& args)
{ {
return this->HandleScriptMode(args); return this->HandleScriptMode(args);
} }
else if(args[0] == "CODE")
{
return this->HandleScriptMode(args);
}
else if(args[0] == "TARGETS") else if(args[0] == "TARGETS")
{ {
return this->HandleTargetsMode(args); return this->HandleTargetsMode(args);
@ -59,11 +63,18 @@ bool cmInstallCommand::InitialPass(std::vector<std::string> const& args)
bool cmInstallCommand::HandleScriptMode(std::vector<std::string> const& args) bool cmInstallCommand::HandleScriptMode(std::vector<std::string> const& args)
{ {
bool doing_script = false; bool doing_script = false;
bool doing_code = false;
for(size_t i=0; i < args.size(); ++i) for(size_t i=0; i < args.size(); ++i)
{ {
if(args[i] == "SCRIPT") if(args[i] == "SCRIPT")
{ {
doing_script = true; doing_script = true;
doing_code = false;
}
else if(args[i] == "CODE")
{
doing_script = false;
doing_code = true;
} }
else if(doing_script) else if(doing_script)
{ {
@ -83,12 +94,24 @@ bool cmInstallCommand::HandleScriptMode(std::vector<std::string> const& args)
this->Makefile->AddInstallGenerator( this->Makefile->AddInstallGenerator(
new cmInstallScriptGenerator(script.c_str())); new cmInstallScriptGenerator(script.c_str()));
} }
else if(doing_code)
{
doing_code = false;
std::string code = args[i];
this->Makefile->AddInstallGenerator(
new cmInstallScriptGenerator(code.c_str(), true));
}
} }
if(doing_script) if(doing_script)
{ {
this->SetError("given no value for SCRIPT argument."); this->SetError("given no value for SCRIPT argument.");
return false; return false;
} }
if(doing_code)
{
this->SetError("given no value for CODE argument.");
return false;
}
return true; return true;
} }

View File

@ -156,12 +156,16 @@ public:
"such as shell scripts. Use the TARGETS form to install targets " "such as shell scripts. Use the TARGETS form to install targets "
"built within the project." "built within the project."
"\n" "\n"
"The SCRIPT signature:\n" "The SCRIPT and CODE signature:\n"
" INSTALL(SCRIPT <file1> [SCRIPT <file2> [...]])\n" " INSTALL([[SCRIPT <file>] [CODE <code>]] [...])\n"
"The SCRIPT form will invoke the given CMake script files during " "The SCRIPT form will invoke the given CMake script files during "
"installation. If the script file name is a relative path " "installation. If the script file name is a relative path "
"it will be interpreted with respect to the current source directory. " "it will be interpreted with respect to the current source directory. "
"\n" "The CODE form will invoke the given CMake code during installation. "
"Code is specified as a single argument inside a double-quoted string. "
"For example, the code\n"
" INSTALL(CODE \"MESSAGE(\\\"Sample install message.\\\")\")\n"
"will print a message during installation.\n"
"NOTE: This command supercedes the INSTALL_TARGETS command and the " "NOTE: This command supercedes the INSTALL_TARGETS command and the "
"target properties PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT. " "target properties PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT. "
"It also replaces the FILES forms of the INSTALL_FILES and " "It also replaces the FILES forms of the INSTALL_FILES and "

View File

@ -18,7 +18,8 @@
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmInstallScriptGenerator cmInstallScriptGenerator
::cmInstallScriptGenerator(const char* script): Script(script) ::cmInstallScriptGenerator(const char* script, bool code):
Script(script), Code(code)
{ {
} }
@ -30,6 +31,13 @@ cmInstallScriptGenerator
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmInstallScriptGenerator::GenerateScript(std::ostream& os) void cmInstallScriptGenerator::GenerateScript(std::ostream& os)
{
if(this->Code)
{
os << this->Script << "\n";
}
else
{ {
os << "INCLUDE(\"" << this->Script << "\")\n"; os << "INCLUDE(\"" << this->Script << "\")\n";
} }
}

View File

@ -25,12 +25,13 @@
class cmInstallScriptGenerator: public cmInstallGenerator class cmInstallScriptGenerator: public cmInstallGenerator
{ {
public: public:
cmInstallScriptGenerator(const char* script); cmInstallScriptGenerator(const char* script, bool code = false);
virtual ~cmInstallScriptGenerator(); virtual ~cmInstallScriptGenerator();
protected: protected:
virtual void GenerateScript(std::ostream& os); virtual void GenerateScript(std::ostream& os);
std::string Script; std::string Script;
bool Code;
}; };
#endif #endif

View File

@ -122,6 +122,7 @@ ELSE(STAGE2)
# Test user-specified install scripts. # Test user-specified install scripts.
INSTALL( INSTALL(
SCRIPT InstallScript1.cmake SCRIPT InstallScript1.cmake
CODE "SET(INSTALL_CODE_DID_RUN 1)"
SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript2.cmake SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript2.cmake
) )
SET_DIRECTORY_PROPERTIES(PROPERTIES SET_DIRECTORY_PROPERTIES(PROPERTIES

View File

@ -1,2 +1,5 @@
MESSAGE("This is install script 1.") MESSAGE("This is install script 1.")
SET(INSTALL_SCRIPT_1_DID_RUN 1) SET(INSTALL_SCRIPT_1_DID_RUN 1)
IF(INSTALL_CODE_DID_RUN)
MESSAGE(FATAL_ERROR "Install script 1 did not run before install code.")
ENDIF(INSTALL_CODE_DID_RUN)

View File

@ -4,6 +4,11 @@ IF(INSTALL_SCRIPT_1_DID_RUN)
ELSE(INSTALL_SCRIPT_1_DID_RUN) ELSE(INSTALL_SCRIPT_1_DID_RUN)
MESSAGE(FATAL_ERROR "Install script 1 did not run before install script 2.") MESSAGE(FATAL_ERROR "Install script 1 did not run before install script 2.")
ENDIF(INSTALL_SCRIPT_1_DID_RUN) ENDIF(INSTALL_SCRIPT_1_DID_RUN)
IF(INSTALL_CODE_DID_RUN)
MESSAGE("Install code ordering works.")
ELSE(INSTALL_CODE_DID_RUN)
MESSAGE(FATAL_ERROR "Install script 2 did not run after install code.")
ENDIF(INSTALL_CODE_DID_RUN)
FILE(WRITE "${CMAKE_INSTALL_PREFIX}/MyTest/InstallScriptOut.cmake" FILE(WRITE "${CMAKE_INSTALL_PREFIX}/MyTest/InstallScriptOut.cmake"
"SET(CMAKE_INSTALL_SCRIPT_DID_RUN 1)\n" "SET(CMAKE_INSTALL_SCRIPT_DID_RUN 1)\n"
) )

View File

@ -122,6 +122,7 @@ ELSE(STAGE2)
# Test user-specified install scripts. # Test user-specified install scripts.
INSTALL( INSTALL(
SCRIPT InstallScript1.cmake SCRIPT InstallScript1.cmake
CODE "SET(INSTALL_CODE_DID_RUN 1)"
SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript2.cmake SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript2.cmake
) )
SET_DIRECTORY_PROPERTIES(PROPERTIES SET_DIRECTORY_PROPERTIES(PROPERTIES

View File

@ -1,2 +1,5 @@
MESSAGE("This is install script 1.") MESSAGE("This is install script 1.")
SET(INSTALL_SCRIPT_1_DID_RUN 1) SET(INSTALL_SCRIPT_1_DID_RUN 1)
IF(INSTALL_CODE_DID_RUN)
MESSAGE(FATAL_ERROR "Install script 1 did not run before install code.")
ENDIF(INSTALL_CODE_DID_RUN)

View File

@ -4,6 +4,11 @@ IF(INSTALL_SCRIPT_1_DID_RUN)
ELSE(INSTALL_SCRIPT_1_DID_RUN) ELSE(INSTALL_SCRIPT_1_DID_RUN)
MESSAGE(FATAL_ERROR "Install script 1 did not run before install script 2.") MESSAGE(FATAL_ERROR "Install script 1 did not run before install script 2.")
ENDIF(INSTALL_SCRIPT_1_DID_RUN) ENDIF(INSTALL_SCRIPT_1_DID_RUN)
IF(INSTALL_CODE_DID_RUN)
MESSAGE("Install code ordering works.")
ELSE(INSTALL_CODE_DID_RUN)
MESSAGE(FATAL_ERROR "Install script 2 did not run after install code.")
ENDIF(INSTALL_CODE_DID_RUN)
FILE(WRITE "${CMAKE_INSTALL_PREFIX}/MyTest/InstallScriptOut.cmake" FILE(WRITE "${CMAKE_INSTALL_PREFIX}/MyTest/InstallScriptOut.cmake"
"SET(CMAKE_INSTALL_SCRIPT_DID_RUN 1)\n" "SET(CMAKE_INSTALL_SCRIPT_DID_RUN 1)\n"
) )