1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmUtilitySourceCommand.cxx,v $
6 Date: $Date: 2008-01-23 15:27:59 $
7 Version: $Revision: 1.25 $
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 "cmUtilitySourceCommand.h"
19 // cmUtilitySourceCommand
20 bool cmUtilitySourceCommand
21 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
25 this->SetError("called with incorrect number of arguments");
29 std::vector
<std::string
>::const_iterator arg
= args
.begin();
31 // The first argument is the cache entry name.
32 std::string cacheEntry
= *arg
++;
33 const char* cacheValue
=
34 this->Makefile
->GetDefinition(cacheEntry
.c_str());
35 // If it exists already and appears up to date then we are done. If
36 // the string contains "(IntDir)" but that is not the
37 // CMAKE_CFG_INTDIR setting then the value is out of date.
39 this->Makefile
->GetRequiredDefinition("CMAKE_CFG_INTDIR");
41 bool haveCacheValue
= false;
42 if (this->Makefile
->IsOn("CMAKE_CROSSCOMPILING"))
44 haveCacheValue
= (cacheValue
!= 0);
47 std::string msg
= "UTILITY_SOURCE is used in cross compiling mode for ";
49 msg
+= ". If your intention is to run this executable, you need to "
50 "preload the cache with the full path to a version of that "
51 "program, which runs on this build machine.";
52 cmSystemTools::Message(msg
.c_str() ,"Warning");
57 haveCacheValue
= (cacheValue
&&
58 (strstr(cacheValue
, "(IntDir)") == 0 ||
59 intDir
&& strcmp(intDir
, "$(IntDir)") == 0) &&
60 (this->Makefile
->GetCacheMajorVersion() != 0 &&
61 this->Makefile
->GetCacheMinorVersion() != 0 ));
69 // The second argument is the utility's executable name, which will be
71 std::string utilityName
= *arg
++;
73 // The third argument specifies the relative directory of the source
75 std::string relativeSource
= *arg
++;
76 std::string utilitySource
= this->Makefile
->GetCurrentDirectory();
77 utilitySource
= utilitySource
+"/"+relativeSource
;
79 // If the directory doesn't exist, the source has not been included.
80 if(!cmSystemTools::FileExists(utilitySource
.c_str()))
83 // Make sure all the files exist in the source directory.
84 while(arg
!= args
.end())
86 std::string file
= utilitySource
+"/"+*arg
++;
87 if(!cmSystemTools::FileExists(file
.c_str()))
92 std::string cmakeCFGout
=
93 this->Makefile
->GetRequiredDefinition("CMAKE_CFG_INTDIR");
94 std::string utilityDirectory
= this->Makefile
->GetCurrentOutputDirectory();
96 if (this->Makefile
->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
98 exePath
= this->Makefile
->GetDefinition("EXECUTABLE_OUTPUT_PATH");
102 utilityDirectory
= exePath
;
106 utilityDirectory
+= "/"+relativeSource
;
109 // Construct the cache entry for the executable's location.
110 std::string utilityExecutable
=
111 utilityDirectory
+"/"+cmakeCFGout
+"/"
112 +utilityName
+this->Makefile
->GetDefinition("CMAKE_EXECUTABLE_SUFFIX");
114 // make sure we remove any /./ in the name
115 cmSystemTools::ReplaceString(utilityExecutable
, "/./", "/");
117 // Enter the value into the cache.
118 this->Makefile
->AddCacheDefinition(cacheEntry
.c_str(),
119 utilityExecutable
.c_str(),
120 "Path to an internal program.",
121 cmCacheManager::FILEPATH
);
122 // add a value into the cache that maps from the
123 // full path to the name of the project
124 cmSystemTools::ConvertToUnixSlashes(utilityExecutable
);
125 this->Makefile
->AddCacheDefinition(utilityExecutable
.c_str(),
127 "Executable to project name.",
128 cmCacheManager::INTERNAL
);