1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmMakefile.cxx,v $
6 Date: $Date: 2008-03-31 17:33:09 $
7 Version: $Revision: 1.466 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmMakefile.h"
18 #include "cmVersion.h"
19 #include "cmCommand.h"
20 #include "cmSourceFile.h"
21 #include "cmSourceFileLocation.h"
22 #include "cmSystemTools.h"
23 #include "cmGlobalGenerator.h"
24 #include "cmLocalGenerator.h"
25 #include "cmCommands.h"
26 #include "cmCacheManager.h"
27 #include "cmFunctionBlocker.h"
28 #include "cmListFileCache.h"
29 #include "cmCommandArgumentParserHelper.h"
31 #ifdef CMAKE_BUILD_WITH_CMAKE
32 # include "cmVariableWatch.h"
34 #include "cmInstallGenerator.h"
36 #include <stdlib.h> // required for atoi
38 #include <cmsys/RegularExpression.hxx>
40 #include <cmsys/auto_ptr.hxx>
42 #include <ctype.h> // for isspace
44 // default is not to be building executables
45 cmMakefile::cmMakefile()
47 this->DefinitionStack
.push_back(DefinitionMap());
49 // Setup the default include file regular expression (match everything).
50 this->IncludeFileRegularExpression
= "^.*$";
51 // Setup the default include complaint regular expression (match nothing).
52 this->ComplainFileRegularExpression
= "^$";
53 // Source and header file extensions that we can handle
55 // Set up a list of source and header extensions
56 // these are used to find files when the extension
58 // The "c" extension MUST precede the "C" extension.
59 this->SourceFileExtensions
.push_back( "c" );
60 this->SourceFileExtensions
.push_back( "C" );
62 this->SourceFileExtensions
.push_back( "c++" );
63 this->SourceFileExtensions
.push_back( "cc" );
64 this->SourceFileExtensions
.push_back( "cpp" );
65 this->SourceFileExtensions
.push_back( "cxx" );
66 this->SourceFileExtensions
.push_back( "m" );
67 this->SourceFileExtensions
.push_back( "M" );
68 this->SourceFileExtensions
.push_back( "mm" );
70 this->HeaderFileExtensions
.push_back( "h" );
71 this->HeaderFileExtensions
.push_back( "hh" );
72 this->HeaderFileExtensions
.push_back( "h++" );
73 this->HeaderFileExtensions
.push_back( "hm" );
74 this->HeaderFileExtensions
.push_back( "hpp" );
75 this->HeaderFileExtensions
.push_back( "hxx" );
76 this->HeaderFileExtensions
.push_back( "in" );
77 this->HeaderFileExtensions
.push_back( "txx" );
79 this->DefineFlags
= " ";
80 this->LocalGenerator
= 0;
82 #if defined(CMAKE_BUILD_WITH_CMAKE)
83 this->AddSourceGroup("", "^.*$");
86 "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|m|mm|rc|def|r|odl|idl|hpj|bat)$");
87 this->AddSourceGroup("Header Files",
88 "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$");
89 this->AddSourceGroup("CMake Rules", "\\.rule$");
90 this->AddSourceGroup("Resources", "\\.plist$");
92 this->AddDefaultDefinitions();
94 this->PreOrder
= false;
97 cmMakefile::cmMakefile(const cmMakefile
& mf
)
99 this->Prefix
= mf
.Prefix
;
100 this->AuxSourceDirectories
= mf
.AuxSourceDirectories
;
101 this->cmStartDirectory
= mf
.cmStartDirectory
;
102 this->StartOutputDirectory
= mf
.StartOutputDirectory
;
103 this->cmHomeDirectory
= mf
.cmHomeDirectory
;
104 this->HomeOutputDirectory
= mf
.HomeOutputDirectory
;
105 this->cmCurrentListFile
= mf
.cmCurrentListFile
;
106 this->ProjectName
= mf
.ProjectName
;
107 this->Targets
= mf
.Targets
;
108 this->SourceFiles
= mf
.SourceFiles
;
109 this->Tests
= mf
.Tests
;
110 this->IncludeDirectories
= mf
.IncludeDirectories
;
111 this->LinkDirectories
= mf
.LinkDirectories
;
112 this->SystemIncludeDirectories
= mf
.SystemIncludeDirectories
;
113 this->ListFiles
= mf
.ListFiles
;
114 this->OutputFiles
= mf
.OutputFiles
;
115 this->LinkLibraries
= mf
.LinkLibraries
;
116 this->InstallGenerators
= mf
.InstallGenerators
;
117 this->IncludeFileRegularExpression
= mf
.IncludeFileRegularExpression
;
118 this->ComplainFileRegularExpression
= mf
.ComplainFileRegularExpression
;
119 this->SourceFileExtensions
= mf
.SourceFileExtensions
;
120 this->HeaderFileExtensions
= mf
.HeaderFileExtensions
;
121 this->DefineFlags
= mf
.DefineFlags
;
123 #if defined(CMAKE_BUILD_WITH_CMAKE)
124 this->SourceGroups
= mf
.SourceGroups
;
127 this->DefinitionStack
.push_back(mf
.DefinitionStack
.back());
128 this->LocalGenerator
= mf
.LocalGenerator
;
129 this->FunctionBlockers
= mf
.FunctionBlockers
;
130 this->DataMap
= mf
.DataMap
;
131 this->MacrosMap
= mf
.MacrosMap
;
132 this->SubDirectoryOrder
= mf
.SubDirectoryOrder
;
133 this->TemporaryDefinitionKey
= mf
.TemporaryDefinitionKey
;
134 this->Properties
= mf
.Properties
;
135 this->PreOrder
= mf
.PreOrder
;
136 this->ListFileStack
= mf
.ListFileStack
;
140 //----------------------------------------------------------------------------
141 void cmMakefile::Initialize()
143 this->cmDefineRegex
.compile("#cmakedefine[ \t]+([A-Za-z_0-9]*)");
144 this->cmDefine01Regex
.compile("#cmakedefine01[ \t]+([A-Za-z_0-9]*)");
145 this->cmAtVarRegex
.compile("(@[A-Za-z_0-9/.+-]+@)");
147 // Enter a policy level for this directory.
150 // By default the check is not done. It is enabled by
151 // cmListFileCache in the top level if necessary.
152 this->CheckCMP0000
= false;
155 unsigned int cmMakefile::GetCacheMajorVersion()
157 return this->GetCacheManager()->GetCacheMajorVersion();
160 unsigned int cmMakefile::GetCacheMinorVersion()
162 return this->GetCacheManager()->GetCacheMinorVersion();
165 bool cmMakefile::NeedCacheCompatibility(int major
, int minor
)
167 return this->GetCacheManager()->NeedCacheCompatibility(major
, minor
);
170 cmMakefile::~cmMakefile()
172 for(std::vector
<cmInstallGenerator
*>::iterator
173 i
= this->InstallGenerators
.begin();
174 i
!= this->InstallGenerators
.end(); ++i
)
178 for(std::vector
<cmSourceFile
*>::iterator i
= this->SourceFiles
.begin();
179 i
!= this->SourceFiles
.end(); ++i
)
183 for(std::vector
<cmTest
*>::iterator i
= this->Tests
.begin();
184 i
!= this->Tests
.end(); ++i
)
188 for(std::vector
<cmTarget
*>::iterator
189 i
= this->ImportedTargetsOwned
.begin();
190 i
!= this->ImportedTargetsOwned
.end(); ++i
)
194 for(unsigned int i
=0; i
< this->UsedCommands
.size(); i
++)
196 delete this->UsedCommands
[i
];
198 for(DataMapType::const_iterator d
= this->DataMap
.begin();
199 d
!= this->DataMap
.end(); ++d
)
206 std::list
<cmFunctionBlocker
*>::iterator pos
;
207 for (pos
= this->FunctionBlockers
.begin();
208 pos
!= this->FunctionBlockers
.end(); ++pos
)
210 cmFunctionBlocker
* b
= *pos
;
213 this->FunctionBlockers
.clear();
214 if (this->PolicyStack
.size() != 1)
216 cmSystemTools::Error("Internal CMake Error, Policy Stack has not been"
221 void cmMakefile::PrintStringVector(const char* s
,
222 const std::vector
<std::string
>& v
) const
224 std::cout
<< s
<< ": ( \n";
225 for(std::vector
<std::string
>::const_iterator i
= v
.begin();
228 std::cout
<< (*i
).c_str() << " ";
234 ::PrintStringVector(const char* s
,
235 const std::vector
<std::pair
<cmStdString
, bool> >& v
) const
237 std::cout
<< s
<< ": ( \n";
238 for(std::vector
<std::pair
<cmStdString
, bool> >::const_iterator i
239 = v
.begin(); i
!= v
.end(); ++i
)
241 std::cout
<< i
->first
.c_str() << " " << i
->second
;
247 // call print on all the classes in the makefile
248 void cmMakefile::Print()
250 // print the class lists
251 std::cout
<< "classes:\n";
253 std::cout
<< " this->Targets: ";
254 for (cmTargets::iterator l
= this->Targets
.begin();
255 l
!= this->Targets
.end(); l
++)
257 std::cout
<< l
->first
<< std::endl
;
260 std::cout
<< " this->StartOutputDirectory; " <<
261 this->StartOutputDirectory
.c_str() << std::endl
;
262 std::cout
<< " this->HomeOutputDirectory; " <<
263 this->HomeOutputDirectory
.c_str() << std::endl
;
264 std::cout
<< " this->cmStartDirectory; " <<
265 this->cmStartDirectory
.c_str() << std::endl
;
266 std::cout
<< " this->cmHomeDirectory; " <<
267 this->cmHomeDirectory
.c_str() << std::endl
;
268 std::cout
<< " this->ProjectName; "
269 << this->ProjectName
.c_str() << std::endl
;
270 this->PrintStringVector("this->IncludeDirectories;",
271 this->IncludeDirectories
);
272 this->PrintStringVector("this->LinkDirectories", this->LinkDirectories
);
273 #if defined(CMAKE_BUILD_WITH_CMAKE)
274 for( std::vector
<cmSourceGroup
>::const_iterator i
=
275 this->SourceGroups
.begin(); i
!= this->SourceGroups
.end(); ++i
)
277 std::cout
<< "Source Group: " << i
->GetName() << std::endl
;
282 bool cmMakefile::CommandExists(const char* name
) const
284 return this->GetCMakeInstance()->CommandExists(name
);
288 //----------------------------------------------------------------------------
289 void cmMakefile::IssueMessage(cmake::MessageType t
,
290 std::string
const& text
) const
292 // Collect context information.
293 cmListFileBacktrace backtrace
;
294 if(!this->CallStack
.empty())
296 if((t
== cmake::FATAL_ERROR
) || (t
== cmake::INTERNAL_ERROR
))
298 this->CallStack
.back().Status
->SetNestedError(true);
300 this->GetBacktrace(backtrace
);
302 else if(!this->ListFileStack
.empty())
304 // We are processing the project but are not currently executing a
305 // command. Add whatever context information we have.
306 cmListFileContext lfc
;
307 lfc
.FilePath
= this->ListFileStack
.back();
309 if(!this->GetCMakeInstance()->GetIsInTryCompile())
311 lfc
.FilePath
= this->LocalGenerator
->Convert(lfc
.FilePath
.c_str(),
312 cmLocalGenerator::HOME
);
314 backtrace
.push_back(lfc
);
317 // Issue the message.
318 this->GetCMakeInstance()->IssueMessage(t
, text
, backtrace
);
321 //----------------------------------------------------------------------------
322 bool cmMakefile::GetBacktrace(cmListFileBacktrace
& backtrace
) const
324 if(this->CallStack
.empty())
328 for(CallStackType::const_reverse_iterator i
= this->CallStack
.rbegin();
329 i
!= this->CallStack
.rend(); ++i
)
331 cmListFileContext lfc
= *(*i
).Context
;
332 lfc
.FilePath
= this->LocalGenerator
->Convert(lfc
.FilePath
.c_str(),
333 cmLocalGenerator::HOME
);
334 backtrace
.push_back(lfc
);
339 //----------------------------------------------------------------------------
340 // Helper class to make sure the call stack is valid.
344 cmMakefileCall(cmMakefile
* mf
,
345 cmListFileContext
const& lfc
,
346 cmExecutionStatus
& status
): Makefile(mf
)
348 cmMakefile::CallStackEntry entry
= {&lfc
, &status
};
349 this->Makefile
->CallStack
.push_back(entry
);
353 this->Makefile
->CallStack
.pop_back();
356 cmMakefile
* Makefile
;
359 //----------------------------------------------------------------------------
360 bool cmMakefile::ExecuteCommand(const cmListFileFunction
& lff
,
361 cmExecutionStatus
&status
)
365 // quick return if blocked
366 if(this->IsFunctionBlocked(lff
,status
))
372 std::string name
= lff
.Name
;
374 // Place this call on the call stack.
375 cmMakefileCall
stack_manager(this, lff
, status
);
376 static_cast<void>(stack_manager
);
378 // Lookup the command prototype.
379 if(cmCommand
* proto
= this->GetCMakeInstance()->GetCommand(name
.c_str()))
381 // Clone the prototype.
382 cmsys::auto_ptr
<cmCommand
> pcmd(proto
->Clone());
383 pcmd
->SetMakefile(this);
385 // Decide whether to invoke the command.
386 if(pcmd
->GetEnabled() && !cmSystemTools::GetFatalErrorOccured() &&
387 (!this->GetCMakeInstance()->GetScriptMode() || pcmd
->IsScriptable()))
389 // Try invoking the command.
390 if(!pcmd
->InvokeInitialPass(lff
.Arguments
,status
) ||
391 status
.GetNestedError())
393 if(!status
.GetNestedError())
395 // The command invocation requested that we report an error.
396 this->IssueMessage(cmake::FATAL_ERROR
, pcmd
->GetError());
399 if ( this->GetCMakeInstance()->GetScriptMode() )
401 cmSystemTools::SetFatalErrorOccured();
407 this->UsedCommands
.push_back(pcmd
.release());
410 else if ( this->GetCMakeInstance()->GetScriptMode()
411 && !pcmd
->IsScriptable() )
413 std::string error
= "Command ";
414 error
+= pcmd
->GetName();
415 error
+= "() is not scriptable";
416 this->IssueMessage(cmake::FATAL_ERROR
, error
);
418 cmSystemTools::SetFatalErrorOccured();
423 if(!cmSystemTools::GetFatalErrorOccured())
425 std::string error
= "Unknown CMake command \"";
428 this->IssueMessage(cmake::FATAL_ERROR
, error
);
430 cmSystemTools::SetFatalErrorOccured();
437 // Parse the given CMakeLists.txt file executing all commands
439 bool cmMakefile::ReadListFile(const char* filename_in
,
440 const char *external_in
,
441 std::string
* fullPath
)
443 std::string currentParentFile
444 = this->GetSafeDefinition("CMAKE_PARENT_LIST_FILE");
445 std::string currentFile
446 = this->GetSafeDefinition("CMAKE_CURRENT_LIST_FILE");
447 this->AddDefinition("CMAKE_PARENT_LIST_FILE", filename_in
);
449 // used to watch for blockers going out of scope
450 // e.g. mismatched IF statement
451 std::set
<cmFunctionBlocker
*> originalBlockers
;
453 const char* external
= 0;
454 std::string external_abs
;
456 const char* filename
= filename_in
;
457 std::string filename_abs
;
462 cmSystemTools::CollapseFullPath(external_in
,
463 this->cmStartDirectory
.c_str());
464 external
= external_abs
.c_str();
468 cmSystemTools::CollapseFullPath(filename_in
,
469 this->cmStartDirectory
.c_str());
470 filename
= filename_abs
.c_str();
474 // keep track of the current file being read
477 if(this->cmCurrentListFile
!= filename
)
479 this->cmCurrentListFile
= filename
;
481 // loop over current function blockers and record them
482 std::list
<cmFunctionBlocker
*>::iterator pos
;
483 for (pos
= this->FunctionBlockers
.begin();
484 pos
!= this->FunctionBlockers
.end(); ++pos
)
486 originalBlockers
.insert(*pos
);
490 // Now read the input file
491 const char *filenametoread
= filename
;
495 filenametoread
= external
;
498 this->AddDefinition("CMAKE_CURRENT_LIST_FILE", filenametoread
);
500 // try to see if the list file is the top most
501 // list file for a project, and if it is, then it
502 // must have a project command. If there is not
503 // one, then cmake will provide one via the
504 // cmListFileCache class.
505 bool requireProjectCommand
= false;
506 if(!external
&& this->cmStartDirectory
== this->cmHomeDirectory
)
508 if(cmSystemTools::LowerCase(
509 cmSystemTools::GetFilenameName(filename
)) == "cmakelists.txt")
511 requireProjectCommand
= true;
515 // push the listfile onto the stack
516 this->ListFileStack
.push_back(filenametoread
);
519 *fullPath
=filenametoread
;
521 cmListFile cacheFile
;
522 if( !cacheFile
.ParseFile(filenametoread
, requireProjectCommand
, this) )
524 // pop the listfile off the stack
525 this->ListFileStack
.pop_back();
530 this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile
.c_str());
531 this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile
.c_str());
534 // add this list file to the list of dependencies
535 this->ListFiles
.push_back( filenametoread
);
536 bool endScopeNicely
= filename
? true: false;
537 const size_t numberFunctions
= cacheFile
.Functions
.size();
538 for(size_t i
=0; i
< numberFunctions
; ++i
)
540 cmExecutionStatus status
;
541 this->ExecuteCommand(cacheFile
.Functions
[i
],status
);
542 if (status
.GetReturnInvoked() ||
543 cmSystemTools::GetFatalErrorOccured() )
545 // Exit early from processing this file.
546 endScopeNicely
= false;
551 // send scope ended to and function blockers
554 // loop over all function blockers to see if any block this command
555 std::list
<cmFunctionBlocker
*>::iterator pos
;
556 for (pos
= this->FunctionBlockers
.begin();
557 pos
!= this->FunctionBlockers
.end(); ++pos
)
559 // if this blocker was not in the original then send a
560 // scope ended message
561 if (originalBlockers
.find(*pos
) == originalBlockers
.end())
563 (*pos
)->ScopeEnded(*this);
568 // If this is the directory-level CMakeLists.txt file then perform
569 // some extra checks.
570 if(this->ListFileStack
.size() == 1)
572 this->EnforceDirectoryLevelRules(endScopeNicely
);
575 this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile
.c_str());
576 this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile
.c_str());
578 // pop the listfile off the stack
579 this->ListFileStack
.pop_back();
584 //----------------------------------------------------------------------------
585 void cmMakefile::EnforceDirectoryLevelRules(bool endScopeNicely
)
587 // Enforce policy stack depth.
588 while(this->PolicyStack
.size() > 1)
592 this->IssueMessage(cmake::FATAL_ERROR
,
593 "cmake_policy PUSH without matching POP");
595 this->PopPolicy(false);
598 // Diagnose a violation of CMP0000 if necessary.
599 if(this->CheckCMP0000
)
602 msg
<< "No cmake_minimum_required command is present. "
603 << "A line of code such as\n"
604 << " cmake_minimum_required(VERSION "
605 << cmVersion::GetMajorVersion() << "."
606 << cmVersion::GetMinorVersion()
608 << "should be added at the top of the file. "
609 << "The version specified may be lower if you wish to "
610 << "support older CMake versions for this project. "
611 << "For more information run "
612 << "\"cmake --help-policy CMP0000\".";
613 switch (this->GetPolicyStatus(cmPolicies::CMP0000
))
615 case cmPolicies::WARN
:
616 // Warn because the user did not provide a mimimum required
618 this->IssueMessage(cmake::AUTHOR_WARNING
, msg
.str().c_str());
619 case cmPolicies::OLD
:
620 // OLD behavior is to use policy version 2.4 set in
623 case cmPolicies::REQUIRED_IF_USED
:
624 case cmPolicies::REQUIRED_ALWAYS
:
625 case cmPolicies::NEW
:
626 // NEW behavior is to issue an error.
627 this->IssueMessage(cmake::FATAL_ERROR
, msg
.str().c_str());
628 cmSystemTools::SetFatalErrorOccured();
634 void cmMakefile::AddCommand(cmCommand
* wg
)
636 this->GetCMakeInstance()->AddCommand(wg
);
640 void cmMakefile::SetLocalGenerator(cmLocalGenerator
* lg
)
642 this->LocalGenerator
= lg
;
645 bool cmMakefile::NeedBackwardsCompatibility(unsigned int major
,
649 if(this->LocalGenerator
)
652 this->LocalGenerator
->NeedBackwardsCompatibility(major
, minor
, patch
);
660 void cmMakefile::FinalPass()
662 // do all the variable expansions here
663 this->ExpandVariables();
665 // give all the commands a chance to do something
666 // after the file has been parsed before generation
667 for(std::vector
<cmCommand
*>::iterator i
= this->UsedCommands
.begin();
668 i
!= this->UsedCommands
.end(); ++i
)
675 // Generate the output file
676 void cmMakefile::ConfigureFinalPass()
680 = this->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
681 if (oldValue
&& atof(oldValue
) <= 1.2)
683 cmSystemTools::Error("You have requested backwards compatibility "
684 "with CMake version 1.2 or earlier. This version "
685 "of CMake only supports backwards compatibility "
686 "with CMake 1.4 or later. For compatibility with "
687 "1.2 or earlier please use CMake 2.0");
689 for (cmTargets::iterator l
= this->Targets
.begin();
690 l
!= this->Targets
.end(); l
++)
692 l
->second
.AnalyzeLibDependencies(*this);
696 //----------------------------------------------------------------------------
698 cmMakefile::AddCustomCommandToTarget(const char* target
,
699 const std::vector
<std::string
>& depends
,
700 const cmCustomCommandLines
& commandLines
,
701 cmTarget::CustomCommandType type
,
703 const char* workingDir
,
706 // Find the target to which to add the custom command.
707 cmTargets::iterator ti
= this->Targets
.find(target
);
708 if(ti
!= this->Targets
.end())
710 // Add the command to the appropriate build step for the target.
711 std::vector
<std::string
> no_output
;
712 cmCustomCommand
cc(no_output
, depends
, commandLines
, comment
, workingDir
);
713 cc
.SetEscapeOldStyle(escapeOldStyle
);
716 case cmTarget::PRE_BUILD
:
717 ti
->second
.GetPreBuildCommands().push_back(cc
);
719 case cmTarget::PRE_LINK
:
720 ti
->second
.GetPreLinkCommands().push_back(cc
);
722 case cmTarget::POST_BUILD
:
723 ti
->second
.GetPostBuildCommands().push_back(cc
);
729 //----------------------------------------------------------------------------
731 cmMakefile::AddCustomCommandToOutput(const std::vector
<std::string
>& outputs
,
732 const std::vector
<std::string
>& depends
,
733 const char* main_dependency
,
734 const cmCustomCommandLines
& commandLines
,
736 const char* workingDir
,
740 // Make sure there is at least one output.
743 cmSystemTools::Error("Attempt to add a custom rule with no output!");
747 // Choose a source file on which to store the custom command.
748 cmSourceFile
* file
= 0;
749 if(main_dependency
&& main_dependency
[0])
751 // The main dependency was specified. Use it unless a different
752 // custom command already used it.
753 file
= this->GetSource(main_dependency
);
754 if(file
&& file
->GetCustomCommand() && !replace
)
756 // The main dependency already has a custom command.
757 if(commandLines
== file
->GetCustomCommand()->GetCommandLines())
759 // The existing custom command is identical. Silently ignore
765 // The existing custom command is different. We need to
766 // generate a rule file for this new command.
772 // The main dependency does not have a custom command or we are
773 // allowed to replace it. Use it to store the command.
774 file
= this->GetOrCreateSource(main_dependency
);
778 // Generate a rule file if the main dependency is not available.
781 // Construct a rule file associated with the first output produced.
782 std::string outName
= outputs
[0];
785 // Check if the rule file already exists.
786 file
= this->GetSource(outName
.c_str());
787 if(file
&& file
->GetCustomCommand() && !replace
)
789 // The rule file already exists.
790 if(commandLines
!= file
->GetCustomCommand()->GetCommandLines())
792 cmSystemTools::Error("Attempt to add a custom rule to output \"",
794 "\" which already has a custom rule.");
799 // Create a cmSourceFile for the rule file.
800 file
= this->GetOrCreateSource(outName
.c_str(), true);
803 // Always create the output sources and mark them generated.
804 for(std::vector
<std::string
>::const_iterator o
= outputs
.begin();
805 o
!= outputs
.end(); ++o
)
807 if(cmSourceFile
* out
= this->GetOrCreateSource(o
->c_str(), true))
809 out
->SetProperty("GENERATED", "1");
813 // Construct a complete list of dependencies.
814 std::vector
<std::string
> depends2(depends
);
815 if(main_dependency
&& main_dependency
[0])
817 depends2
.push_back(main_dependency
);
820 // Attach the custom command to the file.
823 cmCustomCommand
* cc
=
824 new cmCustomCommand(outputs
, depends2
, commandLines
,
825 comment
, workingDir
);
826 cc
->SetEscapeOldStyle(escapeOldStyle
);
827 file
->SetCustomCommand(cc
);
831 //----------------------------------------------------------------------------
833 cmMakefile::AddCustomCommandToOutput(const char* output
,
834 const std::vector
<std::string
>& depends
,
835 const char* main_dependency
,
836 const cmCustomCommandLines
& commandLines
,
838 const char* workingDir
,
842 std::vector
<std::string
> outputs
;
843 outputs
.push_back(output
);
844 this->AddCustomCommandToOutput(outputs
, depends
, main_dependency
,
845 commandLines
, comment
, workingDir
,
846 replace
, escapeOldStyle
);
849 //----------------------------------------------------------------------------
851 cmMakefile::AddCustomCommandOldStyle(const char* target
,
852 const std::vector
<std::string
>& outputs
,
853 const std::vector
<std::string
>& depends
,
855 const cmCustomCommandLines
& commandLines
,
858 // Translate the old-style signature to one of the new-style
860 if(strcmp(source
, target
) == 0)
862 // In the old-style signature if the source and target were the
863 // same then it added a post-build rule to the target. Preserve
865 this->AddCustomCommandToTarget(target
, depends
, commandLines
,
866 cmTarget::POST_BUILD
, comment
, 0);
870 // Each output must get its own copy of this rule.
871 cmsys::RegularExpression
sourceFiles("\\.(C|M|c|c\\+\\+|cc|cpp|cxx|m|mm|"
872 "rc|def|r|odl|idl|hpj|bat|h|h\\+\\+|"
873 "hm|hpp|hxx|in|txx|inl)$");
874 for(std::vector
<std::string
>::const_iterator oi
= outputs
.begin();
875 oi
!= outputs
.end(); ++oi
)
877 // Get the name of this output.
878 const char* output
= oi
->c_str();
880 // Choose whether to use a main dependency.
881 if(sourceFiles
.find(source
))
883 // The source looks like a real file. Use it as the main dependency.
884 this->AddCustomCommandToOutput(output
, depends
, source
,
885 commandLines
, comment
, 0);
889 // The source may not be a real file. Do not use a main dependency.
890 const char* no_main_dependency
= 0;
891 std::vector
<std::string
> depends2
= depends
;
892 depends2
.push_back(source
);
893 this->AddCustomCommandToOutput(output
, depends2
, no_main_dependency
,
894 commandLines
, comment
, 0);
897 // If the rule was added to the source (and not a .rule file),
898 // then add the source to the target to make sure the rule is
900 std::string sname
= output
;
902 if(!this->GetSource(sname
.c_str()))
904 if (this->Targets
.find(target
) != this->Targets
.end())
906 this->Targets
[target
].AddSource(source
);
910 cmSystemTools::Error("Attempt to add a custom rule to a target "
911 "that does not exist yet for target ", target
);
918 //----------------------------------------------------------------------------
919 void cmMakefile::AddUtilityCommand(const char* utilityName
,
921 const std::vector
<std::string
>& depends
,
922 const char* workingDirectory
,
929 // Construct the command line for the custom command.
930 cmCustomCommandLine commandLine
;
931 commandLine
.push_back(command
);
934 commandLine
.push_back(arg1
);
938 commandLine
.push_back(arg2
);
942 commandLine
.push_back(arg3
);
946 commandLine
.push_back(arg4
);
948 cmCustomCommandLines commandLines
;
949 commandLines
.push_back(commandLine
);
951 // Call the real signature of this method.
952 this->AddUtilityCommand(utilityName
, excludeFromAll
, workingDirectory
,
953 depends
, commandLines
);
956 //----------------------------------------------------------------------------
957 void cmMakefile::AddUtilityCommand(const char* utilityName
,
959 const char* workingDirectory
,
960 const std::vector
<std::string
>& depends
,
961 const cmCustomCommandLines
& commandLines
,
962 bool escapeOldStyle
, const char* comment
)
964 // Create a target instance for this utility.
965 cmTarget
* target
= this->AddNewTarget(cmTarget::UTILITY
, utilityName
);
968 target
->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
972 // Use an empty comment to avoid generation of default comment.
976 // Store the custom command in the target.
977 std::string force
= this->GetStartOutputDirectory();
978 force
+= cmake::GetCMakeFilesDirectory();
980 force
+= utilityName
;
981 const char* no_main_dependency
= 0;
982 bool no_replace
= false;
983 this->AddCustomCommandToOutput(force
.c_str(), depends
,
985 commandLines
, comment
,
986 workingDirectory
, no_replace
,
988 cmSourceFile
* sf
= target
->AddSource(force
.c_str());
990 // The output is not actually created so mark it symbolic.
993 sf
->SetProperty("SYMBOLIC", "1");
997 cmSystemTools::Error("Could not get source file entry for ",
1002 void cmMakefile::AddDefineFlag(const char* flag
)
1009 // If this is really a definition, update COMPILE_DEFINITIONS.
1010 if(this->ParseDefineFlag(flag
, false))
1016 std::string ret
= flag
;
1017 std::string::size_type pos
= 0;
1018 while((pos
= ret
.find('\n', pos
)) != std::string::npos
)
1024 while((pos
= ret
.find('\r', pos
)) != std::string::npos
)
1030 this->DefineFlags
+= " ";
1031 this->DefineFlags
+= ret
;
1035 void cmMakefile::RemoveDefineFlag(const char* flag
)
1037 // Check the length of the flag to remove.
1038 std::string::size_type len
= strlen(flag
);
1044 // If this is really a definition, update COMPILE_DEFINITIONS.
1045 if(this->ParseDefineFlag(flag
, true))
1050 // Remove all instances of the flag that are surrounded by
1051 // whitespace or the beginning/end of the string.
1052 for(std::string::size_type lpos
= this->DefineFlags
.find(flag
, 0);
1053 lpos
!= std::string::npos
; lpos
= this->DefineFlags
.find(flag
, lpos
))
1055 std::string::size_type rpos
= lpos
+ len
;
1056 if((lpos
<= 0 || isspace(this->DefineFlags
[lpos
-1])) &&
1057 (rpos
>= this->DefineFlags
.size() || isspace(this->DefineFlags
[rpos
])))
1059 this->DefineFlags
.erase(lpos
, len
);
1068 bool cmMakefile::ParseDefineFlag(std::string
const& def
, bool remove
)
1070 // Create a regular expression to match valid definitions.
1071 static cmsys::RegularExpression
1072 valid("^[-/]D[A-Za-z_][A-Za-z0-9_]*(=.*)?$");
1074 // Make sure the definition matches.
1075 if(!valid
.find(def
.c_str()))
1080 // VS6 IDE does not support definitions with values.
1081 if((strcmp(this->LocalGenerator
->GetGlobalGenerator()->GetName(),
1082 "Visual Studio 6") == 0) &&
1083 (def
.find("=") != def
.npos
))
1088 // Definitions with non-trivial values require a policy check.
1089 static cmsys::RegularExpression
1090 trivial("^[-/]D[A-Za-z_][A-Za-z0-9_]*(=[A-Za-z0-9_.]+)?$");
1091 if(!trivial
.find(def
.c_str()))
1093 // This definition has a non-trivial value.
1094 switch(this->GetPolicyStatus(cmPolicies::CMP0005
))
1096 case cmPolicies::WARN
:
1098 cmake::AUTHOR_WARNING
,
1099 this->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0005
)
1101 case cmPolicies::OLD
:
1102 // OLD behavior is to not escape the value. We should not
1103 // convert the definition to use the property.
1105 case cmPolicies::REQUIRED_IF_USED
:
1106 case cmPolicies::REQUIRED_ALWAYS
:
1109 this->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0005
)
1112 case cmPolicies::NEW
:
1113 // NEW behavior is to escape the value. Proceed to convert it
1114 // to an entry in the property.
1119 // Get the definition part after the flag.
1120 const char* define
= def
.c_str() + 2;
1124 if(const char* cdefs
= this->GetProperty("COMPILE_DEFINITIONS"))
1127 std::vector
<std::string
> defs
;
1128 cmSystemTools::ExpandListArgument(cdefs
, defs
);
1130 // Recompose the list without the definition.
1132 const char* sep
= "";
1133 for(std::vector
<std::string
>::const_iterator di
= defs
.begin();
1134 di
!= defs
.end(); ++di
)
1144 // Store the new list.
1145 this->SetProperty("COMPILE_DEFINITIONS", ndefs
.c_str());
1150 // Append the definition to the directory property.
1151 this->AppendProperty("COMPILE_DEFINITIONS", define
);
1157 void cmMakefile::AddLinkLibrary(const char* lib
,
1158 cmTarget::LinkLibraryType llt
)
1160 cmTarget::LibraryID tmp
;
1163 this->LinkLibraries
.push_back(tmp
);
1166 void cmMakefile::AddLinkLibraryForTarget(const char *target
,
1168 cmTarget::LinkLibraryType llt
)
1170 cmTargets::iterator i
= this->Targets
.find(target
);
1171 if ( i
!= this->Targets
.end())
1174 this->GetCMakeInstance()->GetGlobalGenerator()->FindTarget(0,lib
);
1177 // CMake versions below 2.4 allowed linking to modules.
1178 bool allowModules
= this->NeedBackwardsCompatibility(2,3);
1179 // if it is not a static or shared library then you can not link to it
1180 if(!((tgt
->GetType() == cmTarget::STATIC_LIBRARY
) ||
1181 (tgt
->GetType() == cmTarget::SHARED_LIBRARY
) ||
1182 tgt
->IsExecutableWithExports()))
1185 e
<< "Attempt to add link target " << lib
<< " of type: "
1186 << cmTarget::TargetTypeNames
[static_cast<int>(tgt
->GetType())]
1187 << "\nto target " << target
1188 << ". One can only link to STATIC or SHARED libraries, or "
1189 << "to executables with the ENABLE_EXPORTS property set.";
1190 // in older versions of cmake linking to modules was allowed
1191 if( tgt
->GetType() == cmTarget::MODULE_LIBRARY
)
1194 "\nTo allow linking of modules set "
1195 "CMAKE_BACKWARDS_COMPATIBILITY to 2.2 or lower\n";
1197 // if no modules are allowed then this is always an error
1199 // if we allow modules but the type is not a module then it is
1201 (allowModules
&& tgt
->GetType() != cmTarget::MODULE_LIBRARY
))
1203 cmSystemTools::Error(e
.str().c_str());
1207 i
->second
.AddLinkLibrary( *this, target
, lib
, llt
);
1212 e
<< "Attempt to add link library \""
1213 << lib
<< "\" to target \""
1214 << target
<< "\" which is not built by this project.";
1215 cmSystemTools::Error(e
.str().c_str());
1219 void cmMakefile::AddLinkDirectoryForTarget(const char *target
,
1222 cmTargets::iterator i
= this->Targets
.find(target
);
1223 if ( i
!= this->Targets
.end())
1225 i
->second
.AddLinkDirectory( d
);
1229 cmSystemTools::Error
1230 ("Attempt to add link directories to non-existant target: ",
1231 target
, " for directory ", d
);
1235 void cmMakefile::AddLinkLibrary(const char* lib
)
1237 this->AddLinkLibrary(lib
,cmTarget::GENERAL
);
1240 void cmMakefile::AddLinkDirectory(const char* dir
)
1242 // Don't add a link directory that is already present. Yes, this
1243 // linear search results in n^2 behavior, but n won't be getting
1244 // much bigger than 20. We cannot use a set because of order
1245 // dependency of the link search path.
1251 // remove trailing slashes
1252 if(dir
[strlen(dir
)-1] == '/')
1254 std::string newdir
= dir
;
1255 newdir
= newdir
.substr(0, newdir
.size()-1);
1256 if(std::find(this->LinkDirectories
.begin(),
1257 this->LinkDirectories
.end(),
1258 newdir
.c_str()) == this->LinkDirectories
.end())
1260 this->LinkDirectories
.push_back(newdir
);
1265 if(std::find(this->LinkDirectories
.begin(),
1266 this->LinkDirectories
.end(), dir
)
1267 == this->LinkDirectories
.end())
1269 this->LinkDirectories
.push_back(dir
);
1274 void cmMakefile::InitializeFromParent()
1276 cmMakefile
*parent
= this->LocalGenerator
->GetParent()->GetMakefile();
1278 // copy the definitions
1279 this->DefinitionStack
.front() = parent
->DefinitionStack
.back();
1281 // copy include paths
1282 this->IncludeDirectories
= parent
->IncludeDirectories
;
1283 this->SystemIncludeDirectories
= parent
->SystemIncludeDirectories
;
1286 this->DefineFlags
= parent
->DefineFlags
;
1288 // compile definitions property and per-config versions
1290 this->SetProperty("COMPILE_DEFINITIONS",
1291 parent
->GetProperty("COMPILE_DEFINITIONS"));
1292 std::vector
<std::string
> configs
;
1293 if(const char* configTypes
=
1294 this->GetDefinition("CMAKE_CONFIGURATION_TYPES"))
1296 cmSystemTools::ExpandListArgument(configTypes
, configs
);
1298 else if(const char* buildType
=
1299 this->GetDefinition("CMAKE_BUILD_TYPE"))
1301 configs
.push_back(buildType
);
1303 for(std::vector
<std::string
>::const_iterator ci
= configs
.begin();
1304 ci
!= configs
.end(); ++ci
)
1306 std::string defPropName
= "COMPILE_DEFINITIONS_";
1307 defPropName
+= cmSystemTools::UpperCase(*ci
);
1308 this->SetProperty(defPropName
.c_str(),
1309 parent
->GetProperty(defPropName
.c_str()));
1314 this->LinkLibraries
= parent
->LinkLibraries
;
1317 this->LinkDirectories
= parent
->LinkDirectories
;
1319 // the initial project name
1320 this->ProjectName
= parent
->ProjectName
;
1322 // Copy include regular expressions.
1323 this->IncludeFileRegularExpression
= parent
->IncludeFileRegularExpression
;
1324 this->ComplainFileRegularExpression
= parent
->ComplainFileRegularExpression
;
1326 // Imported targets.
1327 this->ImportedTargets
= parent
->ImportedTargets
;
1330 void cmMakefile::ConfigureSubDirectory(cmLocalGenerator
*lg2
)
1332 // copy our variables from the child makefile
1333 lg2
->GetMakefile()->InitializeFromParent();
1334 lg2
->GetMakefile()->MakeStartDirectoriesCurrent();
1335 if (this->GetCMakeInstance()->GetDebugOutput())
1337 std::string msg
=" Entering ";
1338 msg
+= lg2
->GetMakefile()->GetCurrentDirectory();
1339 cmSystemTools::Message(msg
.c_str());
1341 // finally configure the subdir
1343 if (this->GetCMakeInstance()->GetDebugOutput())
1345 std::string msg
=" Returning to ";
1346 msg
+= this->GetCurrentDirectory();
1347 cmSystemTools::Message(msg
.c_str());
1351 void cmMakefile::AddSubDirectory(const char* sub
,
1352 bool excludeFromAll
, bool preorder
)
1354 // the source path must be made full if it isn't already
1355 std::string srcPath
= sub
;
1356 if (!cmSystemTools::FileIsFullPath(srcPath
.c_str()))
1358 srcPath
= this->GetCurrentDirectory();
1363 // binary path must be made full if it isn't already
1364 std::string binPath
= sub
;
1365 if (!cmSystemTools::FileIsFullPath(binPath
.c_str()))
1367 binPath
= this->GetCurrentOutputDirectory();
1373 this->AddSubDirectory(srcPath
.c_str(), binPath
.c_str(),
1374 excludeFromAll
, preorder
, false);
1378 void cmMakefile::AddSubDirectory(const char* srcPath
, const char *binPath
,
1379 bool excludeFromAll
, bool preorder
,
1382 std::vector
<cmLocalGenerator
*>& children
=
1383 this->LocalGenerator
->GetChildren();
1384 // has this directory already been added? If so error
1386 for (i
= 0; i
< children
.size(); ++i
)
1388 if (srcPath
== children
[i
]->GetMakefile()->GetStartDirectory())
1390 cmSystemTools::Error
1391 ("Attempt to add subdirectory multiple times for directory.\n",
1397 // create a new local generator and set its parent
1398 cmLocalGenerator
*lg2
=
1399 this->LocalGenerator
->GetGlobalGenerator()->CreateLocalGenerator();
1400 lg2
->SetParent(this->LocalGenerator
);
1401 this->LocalGenerator
->GetGlobalGenerator()->AddLocalGenerator(lg2
);
1403 // set the subdirs start dirs
1404 lg2
->GetMakefile()->SetStartDirectory(srcPath
);
1405 lg2
->GetMakefile()->SetStartOutputDirectory(binPath
);
1408 lg2
->GetMakefile()->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
1410 lg2
->GetMakefile()->SetPreOrder(preorder
);
1414 this->ConfigureSubDirectory(lg2
);
1418 void cmMakefile::AddIncludeDirectory(const char* inc
, bool before
)
1420 // if there is a newline then break it into multiple arguments
1426 // Don't add an include directory that is already present. Yes,
1427 // this linear search results in n^2 behavior, but n won't be
1428 // getting much bigger than 20. We cannot use a set because of
1429 // order dependency of the include path.
1430 std::vector
<std::string
>::iterator i
=
1431 std::find(this->IncludeDirectories
.begin(),
1432 this->IncludeDirectories
.end(), inc
);
1433 if(i
== this->IncludeDirectories
.end())
1437 // WARNING: this *is* expensive (linear time) since it's a vector
1438 this->IncludeDirectories
.insert(this->IncludeDirectories
.begin(), inc
);
1442 this->IncludeDirectories
.push_back(inc
);
1449 // if this before and already in the path then remove it
1450 this->IncludeDirectories
.erase(i
);
1451 // WARNING: this *is* expensive (linear time) since it's a vector
1452 this->IncludeDirectories
.insert(this->IncludeDirectories
.begin(), inc
);
1457 //----------------------------------------------------------------------------
1458 void cmMakefile::AddSystemIncludeDirectory(const char* dir
)
1460 this->SystemIncludeDirectories
.insert(dir
);
1463 //----------------------------------------------------------------------------
1464 bool cmMakefile::IsSystemIncludeDirectory(const char* dir
)
1466 return (this->SystemIncludeDirectories
.find(dir
) !=
1467 this->SystemIncludeDirectories
.end());
1470 void cmMakefile::AddDefinition(const char* name
, const char* value
)
1478 if (this->GetCMakeInstance())
1480 this->GetCMakeInstance()->
1481 RecordPropertyAccess(name
,cmProperty::VARIABLE
);
1485 this->TemporaryDefinitionKey
= name
;
1486 this->DefinitionStack
.back()[this->TemporaryDefinitionKey
] = value
;
1488 #ifdef CMAKE_BUILD_WITH_CMAKE
1489 cmVariableWatch
* vv
= this->GetVariableWatch();
1492 vv
->VariableAccessed(this->TemporaryDefinitionKey
,
1493 cmVariableWatch::VARIABLE_MODIFIED_ACCESS
,
1501 void cmMakefile::AddCacheDefinition(const char* name
, const char* value
,
1503 cmCacheManager::CacheEntryType type
)
1505 const char* val
= value
;
1506 cmCacheManager::CacheIterator it
=
1507 this->GetCacheManager()->GetCacheIterator(name
);
1508 if(!it
.IsAtEnd() && (it
.GetType() == cmCacheManager::UNINITIALIZED
) &&
1511 val
= it
.GetValue();
1512 if ( type
== cmCacheManager::PATH
|| type
== cmCacheManager::FILEPATH
)
1514 std::vector
<std::string
>::size_type cc
;
1515 std::vector
<std::string
> files
;
1516 std::string nvalue
= "";
1517 cmSystemTools::ExpandListArgument(val
, files
);
1518 for ( cc
= 0; cc
< files
.size(); cc
++ )
1520 files
[cc
] = cmSystemTools::CollapseFullPath(files
[cc
].c_str());
1525 nvalue
+= files
[cc
];
1528 this->GetCacheManager()->AddCacheEntry(name
, nvalue
.c_str(), doc
, type
);
1529 val
= it
.GetValue();
1533 this->GetCacheManager()->AddCacheEntry(name
, val
, doc
, type
);
1534 // if there was a definition then remove it
1535 this->DefinitionStack
.back().erase( DefinitionMap::key_type(name
));
1539 void cmMakefile::AddDefinition(const char* name
, bool value
)
1543 this->DefinitionStack
.back()
1544 .erase( DefinitionMap::key_type(name
));
1545 this->DefinitionStack
.back()
1546 .insert(DefinitionMap::value_type(name
, "ON"));
1550 this->DefinitionStack
.back()
1551 .erase( DefinitionMap::key_type(name
));
1552 this->DefinitionStack
.back()
1553 .insert(DefinitionMap::value_type(name
, "OFF"));
1555 #ifdef CMAKE_BUILD_WITH_CMAKE
1556 cmVariableWatch
* vv
= this->GetVariableWatch();
1559 vv
->VariableAccessed(name
, cmVariableWatch::VARIABLE_MODIFIED_ACCESS
,
1560 value
?"ON":"OFF", this);
1566 void cmMakefile::AddCacheDefinition(const char* name
,
1571 cmCacheManager::CacheIterator it
=
1572 this->GetCacheManager()->GetCacheIterator(name
);
1573 if(!it
.IsAtEnd() && (it
.GetType() == cmCacheManager::UNINITIALIZED
) &&
1576 val
= it
.GetValueAsBool();
1578 this->GetCacheManager()->AddCacheEntry(name
, val
, doc
);
1579 this->AddDefinition(name
, val
);
1582 void cmMakefile::RemoveDefinition(const char* name
)
1584 this->DefinitionStack
.back().erase(DefinitionMap::key_type(name
));
1585 #ifdef CMAKE_BUILD_WITH_CMAKE
1586 cmVariableWatch
* vv
= this->GetVariableWatch();
1589 vv
->VariableAccessed(name
, cmVariableWatch::VARIABLE_REMOVED_ACCESS
,
1595 void cmMakefile::SetProjectName(const char* p
)
1597 this->ProjectName
= p
;
1601 void cmMakefile::AddGlobalLinkInformation(const char* name
, cmTarget
& target
)
1603 // for these targets do not add anything
1604 switch(target
.GetType())
1606 case cmTarget::UTILITY
:
1607 case cmTarget::GLOBAL_TARGET
:
1611 std::vector
<std::string
>::iterator j
;
1612 for(j
= this->LinkDirectories
.begin();
1613 j
!= this->LinkDirectories
.end(); ++j
)
1615 target
.AddLinkDirectory(j
->c_str());
1617 target
.MergeLinkLibraries( *this, name
, this->LinkLibraries
);
1621 void cmMakefile::AddLibrary(const char* lname
, cmTarget::TargetType type
,
1622 const std::vector
<std::string
> &srcs
,
1623 bool excludeFromAll
)
1625 // wrong type ? default to STATIC
1626 if ( (type
!= cmTarget::STATIC_LIBRARY
)
1627 && (type
!= cmTarget::SHARED_LIBRARY
)
1628 && (type
!= cmTarget::MODULE_LIBRARY
))
1630 type
= cmTarget::STATIC_LIBRARY
;
1633 cmTarget
* target
= this->AddNewTarget(type
, lname
);
1634 // Clear its dependencies. Otherwise, dependencies might persist
1635 // over changes in CMakeLists.txt, making the information stale and
1637 target
->ClearDependencyInformation( *this, lname
);
1640 target
->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
1642 target
->AddSources(srcs
);
1643 this->AddGlobalLinkInformation(lname
, *target
);
1646 cmTarget
* cmMakefile::AddExecutable(const char *exeName
,
1647 const std::vector
<std::string
> &srcs
,
1648 bool excludeFromAll
)
1650 cmTarget
* target
= this->AddNewTarget(cmTarget::EXECUTABLE
, exeName
);
1653 target
->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
1655 target
->AddSources(srcs
);
1656 this->AddGlobalLinkInformation(exeName
, *target
);
1660 //----------------------------------------------------------------------------
1662 cmMakefile::AddNewTarget(cmTarget::TargetType type
, const char* name
)
1664 cmTargets::iterator it
=
1665 this->Targets
.insert(cmTargets::value_type(name
, cmTarget())).first
;
1666 cmTarget
& target
= it
->second
;
1667 target
.SetType(type
, name
);
1668 target
.SetMakefile(this);
1669 this->LocalGenerator
->GetGlobalGenerator()->AddTarget(*it
);
1673 cmSourceFile
*cmMakefile::GetSourceFileWithOutput(const char *cname
)
1675 std::string name
= cname
;
1678 // look through all the source files that have custom commands
1679 // and see if the custom command has the passed source file as an output
1680 // keep in mind the possible .rule extension that may be tacked on
1681 for(std::vector
<cmSourceFile
*>::const_iterator i
=
1682 this->SourceFiles
.begin(); i
!= this->SourceFiles
.end(); ++i
)
1684 // does this source file have a custom command?
1685 if ((*i
)->GetCustomCommand())
1687 // is the output of the custom command match the source files name
1688 const std::vector
<std::string
>& outputs
=
1689 (*i
)->GetCustomCommand()->GetOutputs();
1690 for(std::vector
<std::string
>::const_iterator o
= outputs
.begin();
1691 o
!= outputs
.end(); ++o
)
1694 std::string::size_type pos
= out
.rfind(name
);
1695 // If the output matches exactly
1696 if (pos
!= out
.npos
&&
1697 pos
== out
.size() - name
.size() &&
1698 (pos
==0 || out
[pos
-1] == '/'))
1706 // otherwise return NULL
1710 #if defined(CMAKE_BUILD_WITH_CMAKE)
1711 cmSourceGroup
* cmMakefile::GetSourceGroup(const std::vector
<std::string
>&name
)
1713 cmSourceGroup
* sg
= 0;
1715 // first look for source group starting with the same as the one we wants
1716 for (std::vector
<cmSourceGroup
>::iterator sgIt
= this->SourceGroups
.begin();
1717 sgIt
!= this->SourceGroups
.end(); ++sgIt
)
1720 std::string sgName
= sgIt
->GetName();
1721 if(sgName
== name
[0])
1730 // iterate through its children to find match source group
1731 for(unsigned int i
=1; i
<name
.size(); ++i
)
1733 sg
= sg
->lookupChild(name
[i
].c_str());
1743 void cmMakefile::AddSourceGroup(const char* name
,
1748 std::vector
<std::string
> nameVector
;
1749 nameVector
.push_back(name
);
1750 AddSourceGroup(nameVector
, regex
);
1754 void cmMakefile::AddSourceGroup(const std::vector
<std::string
>& name
,
1757 cmSourceGroup
* sg
= 0;
1758 std::vector
<std::string
> currentName
;
1760 const int lastElement
= static_cast<int>(name
.size()-1);
1761 for(i
=lastElement
; i
>=0; --i
)
1763 currentName
.assign(name
.begin(), name
.begin()+i
+1);
1764 sg
= this->GetSourceGroup(currentName
);
1771 // i now contains the index of the last found component
1774 // group already exists, replace its regular expression
1777 // We only want to set the regular expression. If there are already
1778 // source files in the group, we don't want to remove them.
1779 sg
->SetGroupRegex(regex
);
1785 // group does not exists nor belong to any existing group
1786 // add its first component
1787 this->SourceGroups
.push_back(cmSourceGroup(name
[0].c_str(), regex
));
1788 sg
= this->GetSourceGroup(currentName
);
1789 i
= 0; // last component found
1792 // build the whole source group path
1793 for(++i
; i
<=lastElement
; ++i
)
1795 sg
->AddChild(cmSourceGroup(name
[i
].c_str(), 0));
1796 sg
= sg
->lookupChild(name
[i
].c_str());
1799 sg
->SetGroupRegex(regex
);
1804 void cmMakefile::AddExtraDirectory(const char* dir
)
1806 this->AuxSourceDirectories
.push_back(dir
);
1810 // expance CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR in the
1811 // include and library directories.
1813 void cmMakefile::ExpandVariables()
1815 // Now expand variables in the include and link strings
1816 for(std::vector
<std::string
>::iterator d
= this->IncludeDirectories
.begin();
1817 d
!= this->IncludeDirectories
.end(); ++d
)
1819 this->ExpandVariablesInString(*d
, true, true);
1821 for(std::vector
<std::string
>::iterator d
= this->LinkDirectories
.begin();
1822 d
!= this->LinkDirectories
.end(); ++d
)
1824 this->ExpandVariablesInString(*d
, true, true);
1826 for(cmTarget::LinkLibraryVectorType::iterator l
=
1827 this->LinkLibraries
.begin();
1828 l
!= this->LinkLibraries
.end(); ++l
)
1830 this->ExpandVariablesInString(l
->first
, true, true);
1834 bool cmMakefile::IsOn(const char* name
) const
1836 const char* value
= this->GetDefinition(name
);
1837 return cmSystemTools::IsOn(value
);
1840 bool cmMakefile::IsSet(const char* name
) const
1842 const char* value
= this->GetDefinition(name
);
1853 if ( cmSystemTools::IsNOTFOUND(value
) )
1861 bool cmMakefile::CanIWriteThisFile(const char* fileName
)
1863 if ( !this->IsOn("CMAKE_DISABLE_SOURCE_CHANGES") )
1867 // If we are doing an in-source build, than the test will always fail
1868 if ( cmSystemTools::SameFile(this->GetHomeDirectory(),
1869 this->GetHomeOutputDirectory()) )
1871 if ( this->IsOn("CMAKE_DISABLE_IN_SOURCE_BUILD") )
1878 // Check if this is subdirectory of the source tree but not a
1879 // subdirectory of a build tree
1880 if ( cmSystemTools::IsSubDirectory(fileName
,
1881 this->GetHomeDirectory()) &&
1882 !cmSystemTools::IsSubDirectory(fileName
,
1883 this->GetHomeOutputDirectory()) )
1890 const char* cmMakefile::GetRequiredDefinition(const char* name
) const
1892 const char* ret
= this->GetDefinition(name
);
1895 cmSystemTools::Error("Error required internal CMake variable not "
1896 "set, cmake may be not be built correctly.\n",
1897 "Missing variable is:\n",
1904 bool cmMakefile::IsDefinitionSet(const char* name
) const
1906 const char* def
= 0;
1907 DefinitionMap::const_iterator pos
=
1908 this->DefinitionStack
.back().find(name
);
1909 if(pos
!= this->DefinitionStack
.back().end())
1911 def
= (*pos
).second
.c_str();
1915 def
= this->GetCacheManager()->GetCacheValue(name
);
1917 #ifdef CMAKE_BUILD_WITH_CMAKE
1918 if(cmVariableWatch
* vv
= this->GetVariableWatch())
1922 vv
->VariableAccessed
1923 (name
, cmVariableWatch::UNKNOWN_VARIABLE_DEFINED_ACCESS
,
1928 return def
?true:false;
1931 const char* cmMakefile::GetDefinition(const char* name
) const
1934 if (this->GetCMakeInstance())
1936 this->GetCMakeInstance()->
1937 RecordPropertyAccess(name
,cmProperty::VARIABLE
);
1940 const char* def
= 0;
1941 DefinitionMap::const_iterator pos
=
1942 this->DefinitionStack
.back().find(name
);
1943 if(pos
!= this->DefinitionStack
.back().end())
1945 def
= (*pos
).second
.c_str();
1949 def
= this->GetCacheManager()->GetCacheValue(name
);
1951 #ifdef CMAKE_BUILD_WITH_CMAKE
1952 cmVariableWatch
* vv
= this->GetVariableWatch();
1957 vv
->VariableAccessed(name
, cmVariableWatch::VARIABLE_READ_ACCESS
,
1962 // are unknown access allowed
1963 DefinitionMap::const_iterator pos2
=
1964 this->DefinitionStack
.back()
1965 .find("CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS");
1966 if (pos2
!= this->DefinitionStack
.back().end() &&
1967 cmSystemTools::IsOn((*pos2
).second
.c_str()))
1969 vv
->VariableAccessed(name
,
1970 cmVariableWatch::ALLOWED_UNKNOWN_VARIABLE_READ_ACCESS
, def
, this);
1974 vv
->VariableAccessed(name
,
1975 cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS
, def
, this);
1983 const char* cmMakefile::GetSafeDefinition(const char* def
) const
1985 const char* ret
= this->GetDefinition(def
);
1993 std::vector
<std::string
> cmMakefile
1994 ::GetDefinitions(int cacheonly
/* = 0 */) const
1996 std::map
<cmStdString
, int> definitions
;
1999 DefinitionMap::const_iterator it
;
2000 for ( it
= this->DefinitionStack
.back().begin();
2001 it
!= this->DefinitionStack
.back().end(); it
++ )
2003 definitions
[it
->first
] = 1;
2006 cmCacheManager::CacheIterator cit
=
2007 this->GetCacheManager()->GetCacheIterator();
2008 for ( cit
.Begin(); !cit
.IsAtEnd(); cit
.Next() )
2010 definitions
[cit
.GetName()] = 1;
2013 std::vector
<std::string
> res
;
2015 std::map
<cmStdString
, int>::iterator fit
;
2016 for ( fit
= definitions
.begin(); fit
!= definitions
.end(); fit
++ )
2018 res
.push_back(fit
->first
);
2024 const char *cmMakefile::ExpandVariablesInString(std::string
& source
)
2026 return this->ExpandVariablesInString(source
, false, false);
2029 const char *cmMakefile::ExpandVariablesInString(std::string
& source
,
2033 const char* filename
,
2038 if ( source
.empty() || source
.find_first_of("$@\\") == source
.npos
)
2040 return source
.c_str();
2043 // Special-case the @ONLY mode.
2046 if(!noEscapes
|| !removeEmpty
|| !replaceAt
)
2048 // This case should never be called. At-only is for
2049 // configure-file/string which always does no escapes.
2050 this->IssueMessage(cmake::INTERNAL_ERROR
,
2051 "ExpandVariablesInString @ONLY called "
2052 "on something with escapes.");
2055 // Store an original copy of the input.
2056 std::string input
= source
;
2058 // Start with empty output.
2061 // Look for one @VAR@ at a time.
2062 const char* in
= input
.c_str();
2063 while(this->cmAtVarRegex
.find(in
))
2065 // Get the range of the string to replace.
2066 const char* first
= in
+ this->cmAtVarRegex
.start();
2067 const char* last
= in
+ this->cmAtVarRegex
.end();
2069 // Store the unchanged part of the string now.
2070 source
.append(in
, first
-in
);
2072 // Lookup the definition of VAR.
2073 std::string
var(first
+1, last
-first
-2);
2074 if(const char* val
= this->GetDefinition(var
.c_str()))
2076 // Store the value in the output escaping as requested.
2079 source
.append(cmSystemTools::EscapeQuotes(val
));
2087 // Continue looking for @VAR@ further along the string.
2091 // Append the rest of the unchanged part of the string.
2094 return source
.c_str();
2097 // This method replaces ${VAR} and @VAR@ where VAR is looked up
2098 // with GetDefinition(), if not found in the map, nothing is expanded.
2099 // It also supports the $ENV{VAR} syntax where VAR is looked up in
2100 // the current environment variables.
2102 cmCommandArgumentParserHelper parser
;
2103 parser
.SetMakefile(this);
2104 parser
.SetLineFile(line
, filename
);
2105 parser
.SetEscapeQuotes(escapeQuotes
);
2106 parser
.SetNoEscapeMode(noEscapes
);
2107 parser
.SetReplaceAtSyntax(replaceAt
);
2108 parser
.SetRemoveEmpty(removeEmpty
);
2109 int res
= parser
.ParseString(source
.c_str(), 0);
2112 source
= parser
.GetResult();
2116 cmOStringStream error
;
2117 error
<< "Syntax error in cmake code at\n"
2118 << (filename
?filename
:"(no filename given)")
2119 << ":" << line
<< ":\n"
2120 << parser
.GetError() << ", when parsing string \""
2121 << source
.c_str() << "\"";
2122 if(this->NeedBackwardsCompatibility(2,0))
2124 cmSystemTools::Error(error
.str().c_str());
2125 cmSystemTools::SetFatalErrorOccured();
2126 return source
.c_str();
2130 cmSystemTools::Message(error
.str().c_str());
2133 return source
.c_str();
2136 void cmMakefile::RemoveVariablesInString(std::string
& source
,
2141 cmsys::RegularExpression
var("(\\${[A-Za-z_0-9]*})");
2142 while (var
.find(source
))
2144 source
.erase(var
.start(),var
.end() - var
.start());
2150 cmsys::RegularExpression
varb("(\\$ENV{[A-Za-z_0-9]*})");
2151 while (varb
.find(source
))
2153 source
.erase(varb
.start(),varb
.end() - varb
.start());
2156 cmsys::RegularExpression
var2("(@[A-Za-z_0-9]*@)");
2157 while (var2
.find(source
))
2159 source
.erase(var2
.start(),var2
.end() - var2
.start());
2164 * Add the default definitions to the makefile. These values must not
2165 * be dependent on anything that isn't known when this cmMakefile instance
2168 void cmMakefile::AddDefaultDefinitions()
2170 /* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set.
2171 With CMake must separate between target and host platform. In most cases
2172 the tests for WIN32, UNIX and APPLE will be for the target system, so an
2173 additional set of variables for the host system is required ->
2174 CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE.
2175 WIN32, UNIX and APPLE are now set in the platform files in
2177 To keep cmake scripts (-P) and custom language and compiler modules
2178 working, these variables are still also set here in this place, but they
2179 will be reset in CMakeSystemSpecificInformation.cmake before the platform
2180 files are executed. */
2181 #if defined(_WIN32) || defined(__CYGWIN__)
2182 this->AddDefinition("WIN32", "1");
2183 this->AddDefinition("CMAKE_HOST_WIN32", "1");
2185 this->AddDefinition("UNIX", "1");
2186 this->AddDefinition("CMAKE_HOST_UNIX", "1");
2188 // Cygwin is more like unix so enable the unix commands
2189 #if defined(__CYGWIN__)
2190 this->AddDefinition("UNIX", "1");
2191 this->AddDefinition("CMAKE_HOST_UNIX", "1");
2193 #if defined(__APPLE__)
2194 this->AddDefinition("APPLE", "1");
2195 this->AddDefinition("CMAKE_HOST_APPLE", "1");
2199 sprintf(temp
, "%d", cmVersion::GetMinorVersion());
2200 this->AddDefinition("CMAKE_MINOR_VERSION", temp
);
2201 sprintf(temp
, "%d", cmVersion::GetMajorVersion());
2202 this->AddDefinition("CMAKE_MAJOR_VERSION", temp
);
2203 sprintf(temp
, "%d", cmVersion::GetPatchVersion());
2204 this->AddDefinition("CMAKE_PATCH_VERSION", temp
);
2206 this->AddDefinition("CMAKE_FILES_DIRECTORY",
2207 cmake::GetCMakeFilesDirectory());
2210 #if defined(CMAKE_BUILD_WITH_CMAKE)
2212 * Find a source group whose regular expression matches the filename
2213 * part of the given source name. Search backward through the list of
2214 * source groups, and take the first matching group found. This way
2215 * non-inherited SOURCE_GROUP commands will have precedence over
2219 cmMakefile::FindSourceGroup(const char* source
,
2220 std::vector
<cmSourceGroup
> &groups
)
2222 // First search for a group that lists the file explicitly.
2223 for(std::vector
<cmSourceGroup
>::reverse_iterator sg
= groups
.rbegin();
2224 sg
!= groups
.rend(); ++sg
)
2226 cmSourceGroup
*result
= sg
->MatchChildrenFiles(source
);
2233 // Now search for a group whose regex matches the file.
2234 for(std::vector
<cmSourceGroup
>::reverse_iterator sg
= groups
.rbegin();
2235 sg
!= groups
.rend(); ++sg
)
2237 cmSourceGroup
*result
= sg
->MatchChildrenRegex(source
);
2245 // Shouldn't get here, but just in case, return the default group.
2246 return groups
.front();
2250 bool cmMakefile::IsFunctionBlocked(const cmListFileFunction
& lff
,
2251 cmExecutionStatus
&status
)
2253 // if there are no blockers get out of here
2254 if (this->FunctionBlockers
.begin() == this->FunctionBlockers
.end())
2259 // loop over all function blockers to see if any block this command
2260 // evaluate in reverse, this is critical for balanced IF statements etc
2261 std::list
<cmFunctionBlocker
*>::reverse_iterator pos
;
2262 for (pos
= this->FunctionBlockers
.rbegin();
2263 pos
!= this->FunctionBlockers
.rend(); ++pos
)
2265 if((*pos
)->IsFunctionBlocked(lff
, *this, status
))
2274 void cmMakefile::ExpandArguments(
2275 std::vector
<cmListFileArgument
> const& inArgs
,
2276 std::vector
<std::string
>& outArgs
)
2278 std::vector
<cmListFileArgument
>::const_iterator i
;
2280 outArgs
.reserve(inArgs
.size());
2281 for(i
= inArgs
.begin(); i
!= inArgs
.end(); ++i
)
2283 // Expand the variables in the argument.
2285 this->ExpandVariablesInString(value
, false, false, false,
2286 i
->FilePath
, i
->Line
,
2289 // If the argument is quoted, it should be one argument.
2290 // Otherwise, it may be a list of arguments.
2293 outArgs
.push_back(value
);
2297 cmSystemTools::ExpandListArgument(value
, outArgs
);
2302 void cmMakefile::RemoveFunctionBlocker(const cmListFileFunction
& lff
)
2304 // loop over all function blockers to see if any block this command
2305 std::list
<cmFunctionBlocker
*>::reverse_iterator pos
;
2306 for (pos
= this->FunctionBlockers
.rbegin();
2307 pos
!= this->FunctionBlockers
.rend(); ++pos
)
2309 if ((*pos
)->ShouldRemove(lff
, *this))
2311 cmFunctionBlocker
* b
= *pos
;
2312 this->FunctionBlockers
.remove(b
);
2321 void cmMakefile::SetHomeDirectory(const char* dir
)
2323 this->cmHomeDirectory
= dir
;
2324 cmSystemTools::ConvertToUnixSlashes(this->cmHomeDirectory
);
2325 this->AddDefinition("CMAKE_SOURCE_DIR", this->GetHomeDirectory());
2326 if ( !this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR") )
2328 this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR", this->GetHomeDirectory());
2332 void cmMakefile::SetHomeOutputDirectory(const char* lib
)
2334 this->HomeOutputDirectory
= lib
;
2335 cmSystemTools::ConvertToUnixSlashes(this->HomeOutputDirectory
);
2336 this->AddDefinition("CMAKE_BINARY_DIR", this->GetHomeOutputDirectory());
2337 if ( !this->GetDefinition("CMAKE_CURRENT_BINARY_DIR") )
2339 this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
2340 this->GetHomeOutputDirectory());
2346 * Register the given cmData instance with its own name.
2348 void cmMakefile::RegisterData(cmData
* data
)
2350 std::string name
= data
->GetName();
2351 DataMapType::const_iterator d
= this->DataMap
.find(name
);
2352 if((d
!= this->DataMap
.end()) && (d
->second
!= 0) && (d
->second
!= data
))
2356 this->DataMap
[name
] = data
;
2361 * Register the given cmData instance with the given name. This can be used
2362 * to register a NULL pointer.
2364 void cmMakefile::RegisterData(const char* name
, cmData
* data
)
2366 DataMapType::const_iterator d
= this->DataMap
.find(name
);
2367 if((d
!= this->DataMap
.end()) && (d
->second
!= 0) && (d
->second
!= data
))
2371 this->DataMap
[name
] = data
;
2376 * Lookup a cmData instance previously registered with the given name. If
2377 * the instance cannot be found, return NULL.
2379 cmData
* cmMakefile::LookupData(const char* name
) const
2381 DataMapType::const_iterator d
= this->DataMap
.find(name
);
2382 if(d
!= this->DataMap
.end())
2392 //----------------------------------------------------------------------------
2393 cmSourceFile
* cmMakefile::GetSource(const char* sourceName
)
2395 cmSourceFileLocation
sfl(this, sourceName
);
2396 for(std::vector
<cmSourceFile
*>::const_iterator
2397 sfi
= this->SourceFiles
.begin();
2398 sfi
!= this->SourceFiles
.end(); ++sfi
)
2400 cmSourceFile
* sf
= *sfi
;
2401 if(sf
->Matches(sfl
))
2409 //----------------------------------------------------------------------------
2410 cmSourceFile
* cmMakefile::GetOrCreateSource(const char* sourceName
,
2413 if(cmSourceFile
* esf
= this->GetSource(sourceName
))
2419 cmSourceFile
* sf
= new cmSourceFile(this, sourceName
);
2422 sf
->SetProperty("GENERATED", "1");
2424 this->SourceFiles
.push_back(sf
);
2429 void cmMakefile::EnableLanguage(std::vector
<std::string
> const & lang
,
2432 this->AddDefinition("CMAKE_CFG_INTDIR",
2433 this->LocalGenerator
->GetGlobalGenerator()->GetCMakeCFGInitDirectory());
2434 this->LocalGenerator
->GetGlobalGenerator()->EnableLanguage(lang
, this,
2438 void cmMakefile::ExpandSourceListArguments(
2439 std::vector
<std::string
> const& arguments
,
2440 std::vector
<std::string
>& newargs
, unsigned int /* start */)
2442 // now expand the args
2444 for(i
= 0; i
< arguments
.size(); ++i
)
2446 // List expansion will have been done already.
2447 newargs
.push_back(arguments
[i
]);
2451 int cmMakefile::TryCompile(const char *srcdir
, const char *bindir
,
2452 const char *projectName
, const char *targetName
,
2453 const std::vector
<std::string
> *cmakeArgs
,
2454 std::string
*output
)
2456 // does the binary directory exist ? If not create it...
2457 if (!cmSystemTools::FileIsDirectory(bindir
))
2459 cmSystemTools::MakeDirectory(bindir
);
2462 // change to the tests directory and run cmake
2463 // use the cmake object instead of calling cmake
2464 std::string cwd
= cmSystemTools::GetCurrentWorkingDirectory();
2465 cmSystemTools::ChangeDirectory(bindir
);
2467 // make sure the same generator is used
2468 // use this program as the cmake to be run, it should not
2469 // be run that way but the cmake object requires a vailid path
2470 std::string cmakeCommand
= this->GetDefinition("CMAKE_COMMAND");
2472 cm
.SetIsInTryCompile(true);
2473 cmGlobalGenerator
*gg
= cm
.CreateGlobalGenerator
2474 (this->LocalGenerator
->GetGlobalGenerator()->GetName());
2477 cmSystemTools::Error(
2478 "Internal CMake error, TryCompile bad GlobalGenerator");
2479 // return to the original directory
2480 cmSystemTools::ChangeDirectory(cwd
.c_str());
2483 cm
.SetGlobalGenerator(gg
);
2486 cm
.SetHomeDirectory(srcdir
);
2487 cm
.SetHomeOutputDirectory(bindir
);
2488 cm
.SetStartDirectory(srcdir
);
2489 cm
.SetStartOutputDirectory(bindir
);
2490 cm
.SetCMakeCommand(cmakeCommand
.c_str());
2492 // if cmake args were provided then pass them in
2495 cm
.SetCacheArgs(*cmakeArgs
);
2497 // to save time we pass the EnableLanguage info directly
2498 gg
->EnableLanguagesFromGenerator
2499 (this->LocalGenerator
->GetGlobalGenerator());
2500 if(this->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS"))
2502 cm
.AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS",
2503 "TRUE", "", cmCacheManager::INTERNAL
);
2507 cm
.AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS",
2508 "FALSE", "", cmCacheManager::INTERNAL
);
2510 if (cm
.Configure() != 0)
2512 cmSystemTools::Error(
2513 "Internal CMake error, TryCompile configure of cmake failed");
2514 // return to the original directory
2515 cmSystemTools::ChangeDirectory(cwd
.c_str());
2519 if (cm
.Generate() != 0)
2521 cmSystemTools::Error(
2522 "Internal CMake error, TryCompile generation of cmake failed");
2523 // return to the original directory
2524 cmSystemTools::ChangeDirectory(cwd
.c_str());
2528 // finally call the generator to actually build the resulting project
2530 this->LocalGenerator
->GetGlobalGenerator()->TryCompile(srcdir
,bindir
,
2536 cmSystemTools::ChangeDirectory(cwd
.c_str());
2540 cmake
*cmMakefile::GetCMakeInstance() const
2542 if ( this->LocalGenerator
&& this->LocalGenerator
->GetGlobalGenerator() )
2544 return this->LocalGenerator
->GetGlobalGenerator()->GetCMakeInstance();
2549 #ifdef CMAKE_BUILD_WITH_CMAKE
2550 cmVariableWatch
*cmMakefile::GetVariableWatch() const
2552 if ( this->GetCMakeInstance() &&
2553 this->GetCMakeInstance()->GetVariableWatch() )
2555 return this->GetCMakeInstance()->GetVariableWatch();
2561 void cmMakefile::AddMacro(const char* name
, const char* signature
)
2563 if ( !name
|| !signature
)
2567 this->MacrosMap
[name
] = signature
;
2570 void cmMakefile::GetListOfMacros(std::string
& macros
)
2572 StringStringMap::iterator it
;
2575 for ( it
= this->MacrosMap
.begin(); it
!= this->MacrosMap
.end(); ++it
)
2581 macros
+= it
->first
;
2586 cmCacheManager
*cmMakefile::GetCacheManager() const
2588 return this->GetCMakeInstance()->GetCacheManager();
2591 void cmMakefile::DisplayStatus(const char* message
, float s
)
2593 this->GetLocalGenerator()->GetGlobalGenerator()
2594 ->GetCMakeInstance()->UpdateProgress(message
, s
);
2597 std::string
cmMakefile::GetModulesFile(const char* filename
)
2599 std::vector
<std::string
> modulePath
;
2600 const char* def
= this->GetDefinition("CMAKE_MODULE_PATH");
2603 cmSystemTools::ExpandListArgument(def
, modulePath
);
2606 // Also search in the standard modules location.
2607 def
= this->GetDefinition("CMAKE_ROOT");
2610 std::string rootModules
= def
;
2611 rootModules
+= "/Modules";
2612 modulePath
.push_back(rootModules
);
2614 //std::string Look through the possible module directories.
2615 for(std::vector
<std::string
>::iterator i
= modulePath
.begin();
2616 i
!= modulePath
.end(); ++i
)
2618 std::string itempl
= *i
;
2619 cmSystemTools::ConvertToUnixSlashes(itempl
);
2622 if(cmSystemTools::FileExists(itempl
.c_str()))
2630 void cmMakefile::ConfigureString(const std::string
& input
,
2631 std::string
& output
, bool atOnly
,
2634 // Split input to handle one line at a time.
2635 std::string::const_iterator lineStart
= input
.begin();
2636 while(lineStart
!= input
.end())
2638 // Find the end of this line.
2639 std::string::const_iterator lineEnd
= lineStart
;
2640 while(lineEnd
!= input
.end() && *lineEnd
!= '\n')
2646 std::string
line(lineStart
, lineEnd
);
2648 // Skip the newline character.
2649 bool haveNewline
= (lineEnd
!= input
.end());
2655 // Replace #cmakedefine instances.
2656 if(this->cmDefineRegex
.find(line
))
2659 this->GetDefinition(this->cmDefineRegex
.match(1).c_str());
2660 if(!cmSystemTools::IsOff(def
))
2662 cmSystemTools::ReplaceString(line
, "#cmakedefine", "#define");
2667 output
+= "/* #undef ";
2668 output
+= this->cmDefineRegex
.match(1);
2672 else if(this->cmDefine01Regex
.find(line
))
2675 this->GetDefinition(this->cmDefine01Regex
.match(1).c_str());
2676 cmSystemTools::ReplaceString(line
, "#cmakedefine01", "#define");
2678 if(!cmSystemTools::IsOff(def
))
2697 // Move to the next line.
2698 lineStart
= lineEnd
;
2701 // Perform variable replacements.
2702 this->ExpandVariablesInString(output
, escapeQuotes
, true,
2703 atOnly
, 0, -1, true);
2706 int cmMakefile::ConfigureFile(const char* infile
, const char* outfile
,
2707 bool copyonly
, bool atOnly
, bool escapeQuotes
)
2710 if ( !this->CanIWriteThisFile(outfile
) )
2712 cmSystemTools::Error("Attempt to write file: ",
2713 outfile
, " into a source directory.");
2716 if ( !cmSystemTools::FileExists(infile
) )
2718 cmSystemTools::Error("File ", infile
, " does not exist.");
2721 std::string soutfile
= outfile
;
2722 std::string sinfile
= infile
;
2723 this->AddCMakeDependFile(infile
);
2724 cmSystemTools::ConvertToUnixSlashes(soutfile
);
2726 cmSystemTools::GetPermissions(sinfile
.c_str(), perm
);
2727 std::string::size_type pos
= soutfile
.rfind('/');
2728 if(pos
!= std::string::npos
)
2730 std::string path
= soutfile
.substr(0, pos
);
2731 cmSystemTools::MakeDirectory(path
.c_str());
2736 if ( !cmSystemTools::CopyFileIfDifferent(sinfile
.c_str(),
2744 std::string tempOutputFile
= soutfile
;
2745 tempOutputFile
+= ".tmp";
2746 std::ofstream
fout(tempOutputFile
.c_str());
2749 cmSystemTools::Error(
2750 "Could not open file for write in copy operation ",
2751 tempOutputFile
.c_str());
2752 cmSystemTools::ReportLastSystemError("");
2755 std::ifstream
fin(sinfile
.c_str());
2758 cmSystemTools::Error("Could not open file for read in copy operation ",
2763 // now copy input to output and expand variables in the
2764 // input file at the same time
2766 std::string outLine
;
2767 while( cmSystemTools::GetLineFromStream(fin
, inLine
) )
2770 this->ConfigureString(inLine
, outLine
, atOnly
, escapeQuotes
);
2771 fout
<< outLine
.c_str() << "\n";
2773 // close the files before attempting to copy
2776 if ( !cmSystemTools::CopyFileIfDifferent(tempOutputFile
.c_str(),
2783 cmSystemTools::SetPermissions(soutfile
.c_str(), perm
);
2785 cmSystemTools::RemoveFile(tempOutputFile
.c_str());
2790 void cmMakefile::AddWrittenFile(const char* file
)
2791 { this->GetCMakeInstance()->AddWrittenFile(file
); }
2793 bool cmMakefile::HasWrittenFile(const char* file
)
2794 { return this->GetCMakeInstance()->HasWrittenFile(file
); }
2796 bool cmMakefile::CheckInfiniteLoops()
2798 std::vector
<std::string
>::iterator it
;
2799 for ( it
= this->ListFiles
.begin();
2800 it
!= this->ListFiles
.end();
2803 if ( this->HasWrittenFile(it
->c_str()) )
2805 cmOStringStream str
;
2806 str
<< "File " << it
->c_str() <<
2807 " is written by WRITE_FILE (or FILE WRITE) command and should "
2808 "not be used as input to CMake. Please use CONFIGURE_FILE to "
2809 "be safe. Refer to the note next to FILE WRITE command.";
2810 cmSystemTools::Error(str
.str().c_str());
2817 void cmMakefile::SetProperty(const char* prop
, const char* value
)
2824 // handle special props
2825 std::string propname
= prop
;
2826 if ( propname
== "INCLUDE_DIRECTORIES" )
2828 std::vector
<std::string
> varArgsExpanded
;
2829 cmSystemTools::ExpandListArgument(value
, varArgsExpanded
);
2830 this->SetIncludeDirectories(varArgsExpanded
);
2834 if ( propname
== "LINK_DIRECTORIES" )
2836 std::vector
<std::string
> varArgsExpanded
;
2837 cmSystemTools::ExpandListArgument(value
, varArgsExpanded
);
2838 this->SetLinkDirectories(varArgsExpanded
);
2842 if ( propname
== "INCLUDE_REGULAR_EXPRESSION" )
2844 this->SetIncludeRegularExpression(value
);
2848 if ( propname
== "ADDITIONAL_MAKE_CLEAN_FILES" )
2850 // This property is not inherrited
2851 if ( strcmp(this->GetCurrentDirectory(),
2852 this->GetStartDirectory()) != 0 )
2858 this->Properties
.SetProperty(prop
,value
,cmProperty::DIRECTORY
);
2861 void cmMakefile::AppendProperty(const char* prop
, const char* value
)
2868 // handle special props
2869 std::string propname
= prop
;
2870 if ( propname
== "INCLUDE_DIRECTORIES" )
2872 std::vector
<std::string
> varArgsExpanded
;
2873 cmSystemTools::ExpandListArgument(value
, varArgsExpanded
);
2874 for(std::vector
<std::string
>::const_iterator vi
= varArgsExpanded
.begin();
2875 vi
!= varArgsExpanded
.end(); ++vi
)
2877 this->AddIncludeDirectory(vi
->c_str());
2882 if ( propname
== "LINK_DIRECTORIES" )
2884 std::vector
<std::string
> varArgsExpanded
;
2885 cmSystemTools::ExpandListArgument(value
, varArgsExpanded
);
2886 for(std::vector
<std::string
>::const_iterator vi
= varArgsExpanded
.begin();
2887 vi
!= varArgsExpanded
.end(); ++vi
)
2889 this->AddLinkDirectory(vi
->c_str());
2894 this->Properties
.AppendProperty(prop
,value
,cmProperty::DIRECTORY
);
2897 const char *cmMakefile::GetPropertyOrDefinition(const char* prop
)
2899 const char *ret
= this->GetProperty(prop
, cmProperty::DIRECTORY
);
2902 ret
= this->GetDefinition(prop
);
2907 const char *cmMakefile::GetProperty(const char* prop
)
2909 return this->GetProperty(prop
, cmProperty::DIRECTORY
);
2912 const char *cmMakefile::GetProperty(const char* prop
,
2913 cmProperty::ScopeType scope
)
2915 // watch for specific properties
2916 static std::string output
;
2918 if (!strcmp("PARENT_DIRECTORY",prop
))
2920 output
= this->LocalGenerator
->GetParent()
2921 ->GetMakefile()->GetStartDirectory();
2922 return output
.c_str();
2924 else if (!strcmp("INCLUDE_REGULAR_EXPRESSION",prop
) )
2926 output
= this->GetIncludeRegularExpression();
2927 return output
.c_str();
2929 else if (!strcmp("LISTFILE_STACK",prop
))
2931 for (std::deque
<cmStdString
>::iterator i
= this->ListFileStack
.begin();
2932 i
!= this->ListFileStack
.end(); ++i
)
2934 if (i
!= this->ListFileStack
.begin())
2940 return output
.c_str();
2942 else if (!strcmp("VARIABLES",prop
) || !strcmp("CACHE_VARIABLES",prop
))
2945 if ( !strcmp("CACHE_VARIABLES",prop
) )
2949 std::vector
<std::string
> vars
= this->GetDefinitions(cacheonly
);
2950 for (unsigned int cc
= 0; cc
< vars
.size(); cc
++ )
2958 return output
.c_str();
2960 else if (!strcmp("MACROS",prop
))
2962 this->GetListOfMacros(output
);
2963 return output
.c_str();
2965 else if (!strcmp("DEFINITIONS",prop
))
2967 output
= this->GetDefineFlags();
2968 return output
.c_str();
2970 else if (!strcmp("INCLUDE_DIRECTORIES",prop
) )
2972 cmOStringStream str
;
2973 for (std::vector
<std::string
>::const_iterator
2974 it
= this->GetIncludeDirectories().begin();
2975 it
!= this->GetIncludeDirectories().end();
2978 if ( it
!= this->GetIncludeDirectories().begin())
2985 return output
.c_str();
2987 else if (!strcmp("LINK_DIRECTORIES",prop
))
2989 cmOStringStream str
;
2990 for (std::vector
<std::string
>::const_iterator
2991 it
= this->GetLinkDirectories().begin();
2992 it
!= this->GetLinkDirectories().end();
2995 if ( it
!= this->GetLinkDirectories().begin())
3002 return output
.c_str();
3006 const char *retVal
=
3007 this->Properties
.GetPropertyValue(prop
, scope
, chain
);
3010 if(this->LocalGenerator
->GetParent())
3012 return this->LocalGenerator
->GetParent()->GetMakefile()->
3013 GetProperty(prop
, scope
);
3015 return this->GetCMakeInstance()->GetProperty(prop
,scope
);
3021 bool cmMakefile::GetPropertyAsBool(const char* prop
)
3023 return cmSystemTools::IsOn(this->GetProperty(prop
));
3027 cmTarget
* cmMakefile::FindTarget(const char* name
)
3029 cmTargets
& tgts
= this->GetTargets();
3031 cmTargets::iterator i
= tgts
.find ( name
);
3032 if ( i
!= tgts
.end() )
3040 cmTest
* cmMakefile::CreateTest(const char* testName
)
3046 cmTest
* test
= this->GetTest(testName
);
3052 test
->SetName(testName
);
3053 test
->SetMakefile(this);
3054 this->Tests
.push_back(test
);
3058 cmTest
* cmMakefile::GetTest(const char* testName
) const
3064 std::vector
<cmTest
*>::const_iterator it
;
3065 for ( it
= this->Tests
.begin(); it
!= this->Tests
.end(); ++ it
)
3067 if ( strcmp((*it
)->GetName(), testName
) == 0 )
3075 const std::vector
<cmTest
*> *cmMakefile::GetTests() const
3077 return &this->Tests
;
3080 std::vector
<cmTest
*> *cmMakefile::GetTests()
3082 return &this->Tests
;
3085 std::string
cmMakefile::GetListFileStack()
3087 cmOStringStream tmp
;
3088 size_t depth
= this->ListFileStack
.size();
3091 std::deque
<cmStdString
>::iterator it
= this->ListFileStack
.end();
3094 if (depth
!= this->ListFileStack
.size())
3105 while (it
!= this->ListFileStack
.begin());
3111 void cmMakefile::PushScope()
3113 // Get the index of the next stack entry.
3114 std::vector
<DefinitionMap
>::size_type index
= this->DefinitionStack
.size();
3116 // Allocate a new stack entry.
3117 this->DefinitionStack
.push_back(DefinitionMap());
3119 // Copy the previous top to the new top.
3120 this->DefinitionStack
[index
] = this->DefinitionStack
[index
-1];
3123 void cmMakefile::PopScope()
3125 this->DefinitionStack
.pop_back();
3128 void cmMakefile::RaiseScope(const char *var
, const char *varDef
)
3130 if (!var
|| !strlen(var
))
3135 // multiple scopes in this directory?
3136 if (this->DefinitionStack
.size() > 1)
3140 this->DefinitionStack
[this->DefinitionStack
.size()-2][var
] = varDef
;
3144 this->DefinitionStack
[this->DefinitionStack
.size()-2].erase(var
);
3147 // otherwise do the parent (if one exists)
3148 else if (this->LocalGenerator
->GetParent())
3150 cmMakefile
*parent
= this->LocalGenerator
->GetParent()->GetMakefile();
3155 parent
->AddDefinition(var
,varDef
);
3159 parent
->RemoveDefinition(var
);
3166 // define properties
3167 void cmMakefile::DefineProperties(cmake
*cm
)
3170 ("ADDITIONAL_MAKE_CLEAN_FILES", cmProperty::DIRECTORY
,
3171 "Additional files to clean during the make clean stage.",
3172 "A list of files that will be cleaned as a part of the "
3173 "\"make clean\" stage. ");
3176 ("CLEAN_NO_CUSTOM", cmProperty::DIRECTORY
,
3177 "Should the output of custom commands be left.",
3178 "If this is true then the outputs of custom commands for this "
3179 "directory will not be removed during the \"make clean\" stage. ");
3182 ("LISTFILE_STACK", cmProperty::DIRECTORY
,
3183 "The current stack of listfiles being processed.",
3184 "This property is mainly useful when trying to debug errors "
3185 "in your CMake scripts. It returns a list of what list files "
3186 "are currently being processed, in order. So if one listfile "
3187 "does an INCLUDE command then that is effectively pushing "
3188 "the included listfile onto the stack.");
3191 ("TEST_INCLUDE_FILE", cmProperty::DIRECTORY
,
3192 "A cmake file that will be included when ctest is run.",
3193 "If you specify TEST_INCLUDE_FILE, that file will be "
3194 "included and processed when ctest is run on the directory.");
3197 ("COMPILE_DEFINITIONS", cmProperty::DIRECTORY
,
3198 "Preprocessor definitions for compiling a directory's sources.",
3199 "The COMPILE_DEFINITIONS property may be set to a list of preprocessor "
3200 "definitions using the syntax VAR or VAR=value. Function-style "
3201 "definitions are not supported. CMake will automatically escape "
3202 "the value correctly for the native build system (note that CMake "
3203 "language syntax may require escapes to specify some values). "
3204 "This property may be set on a per-configuration basis using the name "
3205 "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
3206 "(ex. \"COMPILE_DEFINITIONS_DEBUG\"). "
3207 "This property will be initialized in each directory by its value "
3208 "in the directory's parent.\n"
3209 "CMake will automatically drop some definitions that "
3210 "are not supported by the native build tool. "
3211 "The VS6 IDE does not support definitions with values "
3212 "(but NMake does).\n"
3213 "Dislaimer: Most native build tools have poor support for escaping "
3214 "certain values. CMake has work-arounds for many cases but some "
3215 "values may just not be possible to pass correctly. If a value "
3216 "does not seem to be escaped correctly, do not attempt to "
3217 "work-around the problem by adding escape sequences to the value. "
3218 "Your work-around may break in a future version of CMake that "
3219 "has improved escape support. Instead consider defining the macro "
3220 "in a (configured) header file. Then report the limitation.");
3223 ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::DIRECTORY
,
3224 "Per-configuration preprocessor definitions in a directory.",
3225 "This is the configuration-specific version of COMPILE_DEFINITIONS. "
3226 "This property will be initialized in each directory by its value "
3227 "in the directory's parent.\n");
3230 ("EXCLUDE_FROM_ALL", cmProperty::DIRECTORY
,
3231 "Exclude the directory from the all target of its parent.",
3232 "A property on a directory that indicates if its targets are excluded "
3233 "from the default build target. If it is not, then with a Makefile "
3234 "for example typing make will cause the targets to be built. "
3235 "The same concept applies to the default build of other generators.",
3239 //----------------------------------------------------------------------------
3241 cmMakefile::AddImportedTarget(const char* name
, cmTarget::TargetType type
)
3243 // Create the target.
3244 cmsys::auto_ptr
<cmTarget
> target(new cmTarget
);
3245 target
->SetType(type
, name
);
3246 target
->SetMakefile(this);
3247 target
->MarkAsImported();
3249 // Add to the set of available imported targets.
3250 this->ImportedTargets
[name
] = target
.get();
3252 // Transfer ownership to this cmMakefile object.
3253 this->ImportedTargetsOwned
.push_back(target
.get());
3254 return target
.release();
3257 //----------------------------------------------------------------------------
3258 cmTarget
* cmMakefile::FindTargetToUse(const char* name
)
3260 // Look for an imported target. These take priority because they
3261 // are more local in scope and do not have to be globally unique.
3262 std::map
<cmStdString
, cmTarget
*>::const_iterator
3263 imported
= this->ImportedTargets
.find(name
);
3264 if(imported
!= this->ImportedTargets
.end())
3266 return imported
->second
;
3269 // Look for a target built in this project.
3270 return this->LocalGenerator
->GetGlobalGenerator()->FindTarget(0, name
);
3273 //----------------------------------------------------------------------------
3274 bool cmMakefile::EnforceUniqueName(std::string
const& name
, std::string
& msg
,
3277 if(cmTarget
* existing
= this->FindTargetToUse(name
.c_str()))
3279 // The name given conflicts with an existing target. Produce an
3280 // error in a compatible way.
3281 if(existing
->IsImported())
3283 // Imported targets were not supported in previous versions.
3284 // This is new code, so we can make it an error.
3286 e
<< "cannot create target \"" << name
3287 << "\" because an imported target with the same name already exists.";
3293 // target names must be globally unique
3294 switch (this->GetPolicyStatus(cmPolicies::CMP0002
))
3296 case cmPolicies::WARN
:
3297 this->IssueMessage(cmake::AUTHOR_WARNING
, this->GetPolicies()->
3298 GetPolicyWarning(cmPolicies::CMP0002
));
3299 case cmPolicies::OLD
:
3301 case cmPolicies::REQUIRED_IF_USED
:
3302 case cmPolicies::REQUIRED_ALWAYS
:
3303 this->IssueMessage(cmake::FATAL_ERROR
,
3304 this->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP0002
)
3307 case cmPolicies::NEW
:
3311 // The conflict is with a non-imported target.
3312 // Allow this if the user has requested support.
3314 this->LocalGenerator
->GetGlobalGenerator()->GetCMakeInstance();
3315 if(isCustom
&& existing
->GetType() == cmTarget::UTILITY
&&
3316 this != existing
->GetMakefile() &&
3317 cm
->GetPropertyAsBool("ALLOW_DUPLICATE_CUSTOM_TARGETS"))
3322 // Produce an error that tells the user how to work around the
3325 e
<< "cannot create target \"" << name
3326 << "\" because another target with the same name already exists. "
3327 << "The existing target is ";
3328 switch(existing
->GetType())
3330 case cmTarget::EXECUTABLE
:
3331 e
<< "an executable ";
3333 case cmTarget::STATIC_LIBRARY
:
3334 e
<< "a static library ";
3336 case cmTarget::SHARED_LIBRARY
:
3337 e
<< "a shared library ";
3339 case cmTarget::MODULE_LIBRARY
:
3340 e
<< "a module library ";
3342 case cmTarget::UTILITY
:
3343 e
<< "a custom target ";
3347 e
<< "created in source directory \""
3348 << existing
->GetMakefile()->GetCurrentDirectory() << "\". "
3349 << "See documentation for policy CMP0002 for more details.";
3357 cmPolicies::PolicyStatus cmMakefile
3358 ::GetPolicyStatus(cmPolicies::PolicyID id
)
3360 cmPolicies::PolicyStatus status
= cmPolicies::REQUIRED_IF_USED
;
3361 PolicyMap::iterator mappos
;
3365 // check our policy stack first
3366 for (vecpos
= static_cast<int>(this->PolicyStack
.size()) - 1;
3367 vecpos
>= 0 && !done
; vecpos
--)
3369 mappos
= this->PolicyStack
[vecpos
].find(id
);
3370 if (mappos
!= this->PolicyStack
[vecpos
].end())
3372 status
= mappos
->second
;
3377 // if not found then
3380 // pass the buck to our parent if we have one
3381 if (this->LocalGenerator
->GetParent())
3383 cmMakefile
*parent
=
3384 this->LocalGenerator
->GetParent()->GetMakefile();
3385 return parent
->GetPolicyStatus(id
);
3387 // otherwise use the default
3390 status
= this->GetPolicies()->GetPolicyStatus(id
);
3394 // warn if we see a REQUIRED_IF_USED above a OLD or WARN
3395 if (!this->GetPolicies()->IsValidUsedPolicyStatus(id
,status
))
3397 return cmPolicies::REQUIRED_IF_USED
;
3403 bool cmMakefile::SetPolicy(const char *id
,
3404 cmPolicies::PolicyStatus status
)
3406 cmPolicies::PolicyID pid
;
3407 if (!this->GetPolicies()->GetPolicyID(id
, /* out */ pid
))
3410 e
<< "Policy \"" << id
<< "\" is not known to this version of CMake.";
3411 this->IssueMessage(cmake::FATAL_ERROR
, e
.str());
3414 return this->SetPolicy(pid
,status
);
3417 bool cmMakefile::SetPolicy(cmPolicies::PolicyID id
,
3418 cmPolicies::PolicyStatus status
)
3420 // setting a REQUIRED_ALWAYS policy to WARN or OLD is an insta error
3421 if (this->GetPolicies()->
3422 IsValidPolicyStatus(id
,status
))
3424 this->PolicyStack
.back()[id
] = status
;
3426 // Special hook for presenting compatibility variable as soon as
3427 // the user requests it.
3428 if(id
== cmPolicies::CMP0001
&&
3429 (status
== cmPolicies::WARN
|| status
== cmPolicies::OLD
))
3431 if(!(this->GetCacheManager()
3432 ->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")))
3434 // Set it to 2.4 because that is the last version where the
3435 // variable had meaning.
3436 this->AddCacheDefinition
3437 ("CMAKE_BACKWARDS_COMPATIBILITY", "2.4",
3438 "For backwards compatibility, what version of CMake "
3440 "syntax should this version of CMake try to support.",
3441 cmCacheManager::STRING
);
3450 bool cmMakefile::PushPolicy()
3452 // Allocate a new stack entry.
3453 this->PolicyStack
.push_back(PolicyMap());
3457 bool cmMakefile::PopPolicy(bool reportError
)
3459 if(this->PolicyStack
.size() == 1)
3463 cmSystemTools::Error("Attempt to pop the policy stack past "
3468 this->PolicyStack
.pop_back();
3472 bool cmMakefile::SetPolicyVersion(const char *version
)
3474 return this->GetCMakeInstance()->GetPolicies()->
3475 ApplyPolicyVersion(this,version
);
3478 cmPolicies
*cmMakefile::GetPolicies()
3480 if (!this->GetCMakeInstance())
3484 return this->GetCMakeInstance()->GetPolicies();