From 814b8856a0966a5d396583dcb36bbc8a225371af Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Thu, 6 Mar 2003 11:20:26 -0500 Subject: Add command for accessing cmake properties. At this point the only properties are VARIABLES and CACHE_VARIABLES. Also add test for this feature --- Source/cmCommands.cxx | 2 + Source/cmGetCMakePropertyCommand.cxx | 60 ++++++++++++++++++++++++++++++ Source/cmGetCMakePropertyCommand.h | 68 ++++++++++++++++++++++++++++++++++ Tests/SystemInformation/CMakeLists.txt | 5 +++ 4 files changed, 135 insertions(+) create mode 100644 Source/cmGetCMakePropertyCommand.cxx create mode 100644 Source/cmGetCMakePropertyCommand.h diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 1cb2994..8aa07d1 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -46,6 +46,7 @@ #include "cmFindProgramCommand.cxx" #include "cmForEachCommand.cxx" #include "cmFLTKWrapUICommand.cxx" +#include "cmGetCMakePropertyCommand.cxx" #include "cmGetFilenameComponentCommand.cxx" #include "cmGetSourceFilePropertyCommand.cxx" #include "cmGetTargetPropertyCommand.cxx" @@ -132,6 +133,7 @@ void GetPredefinedCommands(std::list& commands) commands.push_back(new cmFindProgramCommand); commands.push_back(new cmForEachCommand); commands.push_back(new cmFLTKWrapUICommand); + commands.push_back(new cmGetCMakePropertyCommand); commands.push_back(new cmGetFilenameComponentCommand); commands.push_back(new cmGetSourceFilePropertyCommand); commands.push_back(new cmGetTargetPropertyCommand); diff --git a/Source/cmGetCMakePropertyCommand.cxx b/Source/cmGetCMakePropertyCommand.cxx new file mode 100644 index 0000000..dc24d49 --- /dev/null +++ b/Source/cmGetCMakePropertyCommand.cxx @@ -0,0 +1,60 @@ +/*========================================================================= + + Program: CMake - Cross-Platform Makefile Generator + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved. + See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "cmGetCMakePropertyCommand.h" + +// cmGetCMakePropertyCommand +bool cmGetCMakePropertyCommand::InitialPass( + std::vector const& args) +{ + if(args.size() < 2 ) + { + this->SetError("called with incorrect number of arguments"); + return false; + } + + int cc; + std::string variable = args[0]; + std::string output = ""; + + if ( args[1] == "VARIABLES" || args[1] == "CACHE_VARIABLES" ) + { + int cacheonly = 0; + if ( args[1] == "CACHE_VARIABLES" ) + { + cacheonly = 1; + } + std::vector vars = m_Makefile->GetDefinitions(cacheonly); + for ( cc = 0; cc < vars.size(); cc ++ ) + { + if ( cc > 0 ) + { + output += ";"; + } + output += vars[cc]; + } + } + else + { + std::string emsg = "Unknown CMake property: " + args[1]; + this->SetError(emsg.c_str()); + return false; + } + m_Makefile->AddDefinition(variable.c_str(), output.c_str()); + + return true; +} + diff --git a/Source/cmGetCMakePropertyCommand.h b/Source/cmGetCMakePropertyCommand.h new file mode 100644 index 0000000..ffb7c0e --- /dev/null +++ b/Source/cmGetCMakePropertyCommand.h @@ -0,0 +1,68 @@ +/*========================================================================= + + Program: CMake - Cross-Platform Makefile Generator + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved. + See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef cmGetCMakePropertyCommand_h +#define cmGetCMakePropertyCommand_h + +#include "cmStandardIncludes.h" +#include "cmCommand.h" + +class cmGetCMakePropertyCommand : public cmCommand +{ +public: + virtual cmCommand* Clone() + { + return new cmGetCMakePropertyCommand; + } + + /** + * This is called when the command is first encountered in + * the input file. + */ + virtual bool InitialPass(std::vector const& args); + + /** + * The name of the command as specified in CMakeList.txt. + */ + virtual const char* GetName() { return "GET_CMAKE_PROPERTY";} + + /** + * Succinct documentation. + */ + virtual const char* GetTerseDocumentation() + { + return "Get a property of the CMake."; + } + + /** + * Longer documentation. + */ + virtual const char* GetFullDocumentation() + { + return + " GET_CMAKE_PROPERTY(VAR property)\n" + "Get a property from the CMake. The value of the property is" + "stored in the variable VAR. If the property is not found," + "CMake will report an error. The properties include: VARIABLES, " + "CACHE_VARIABLES."; + } + + cmTypeMacro(cmGetCMakePropertyCommand, cmCommand); +}; + + + +#endif diff --git a/Tests/SystemInformation/CMakeLists.txt b/Tests/SystemInformation/CMakeLists.txt index 54feeff..7e67f56 100644 --- a/Tests/SystemInformation/CMakeLists.txt +++ b/Tests/SystemInformation/CMakeLists.txt @@ -6,3 +6,8 @@ CONFIGURE_FILE(${DumpInformation_SOURCE_DIR}/DumpInformation.h.in ${DumpInformation_BINARY_DIR}/DumpInformation.h) ADD_EXECUTABLE(DumpInformation DumpInformation.cxx) +GET_CMAKE_PROPERTY(VARS VARIABLES) +FOREACH(var ${VARS}) + MESSAGE(STATUS "Variable ${var} \"${${var}}\"") +ENDFOREACH(var ${VARS}) + -- cgit v0.12