1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmUtilitySourceCommand.h"
14 // cmUtilitySourceCommand
15 bool cmUtilitySourceCommand
16 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
20 this->SetError("called with incorrect number of arguments");
24 std::vector<std::string>::const_iterator arg = args.begin();
26 // The first argument is the cache entry name.
27 std::string cacheEntry = *arg++;
28 const char* cacheValue =
29 this->Makefile->GetDefinition(cacheEntry.c_str());
30 // If it exists already and appears up to date then we are done. If
31 // the string contains "(IntDir)" but that is not the
32 // CMAKE_CFG_INTDIR setting then the value is out of date.
34 this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
36 bool haveCacheValue = false;
37 if (this->Makefile->IsOn("CMAKE_CROSSCOMPILING"))
39 haveCacheValue = (cacheValue != 0);
42 std::string msg = "UTILITY_SOURCE is used in cross compiling mode for ";
44 msg += ". If your intention is to run this executable, you need to "
45 "preload the cache with the full path to a version of that "
46 "program, which runs on this build machine.";
47 cmSystemTools::Message(msg.c_str() ,"Warning");
52 haveCacheValue = (cacheValue &&
53 (strstr(cacheValue, "(IntDir)") == 0 ||
54 (intDir && strcmp(intDir, "$(IntDir)") == 0)) &&
55 (this->Makefile->GetCacheMajorVersion() != 0 &&
56 this->Makefile->GetCacheMinorVersion() != 0 ));
64 // The second argument is the utility's executable name, which will be
66 std::string utilityName = *arg++;
68 // The third argument specifies the relative directory of the source
70 std::string relativeSource = *arg++;
71 std::string utilitySource = this->Makefile->GetCurrentDirectory();
72 utilitySource = utilitySource+"/"+relativeSource;
74 // If the directory doesn't exist, the source has not been included.
75 if(!cmSystemTools::FileExists(utilitySource.c_str()))
78 // Make sure all the files exist in the source directory.
79 while(arg != args.end())
81 std::string file = utilitySource+"/"+*arg++;
82 if(!cmSystemTools::FileExists(file.c_str()))
87 std::string cmakeCFGout =
88 this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
89 std::string utilityDirectory = this->Makefile->GetCurrentOutputDirectory();
91 if (this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
93 exePath = this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
97 utilityDirectory = exePath;
101 utilityDirectory += "/"+relativeSource;
104 // Construct the cache entry for the executable's location.
105 std::string utilityExecutable =
106 utilityDirectory+"/"+cmakeCFGout+"/"
107 +utilityName+this->Makefile->GetDefinition("CMAKE_EXECUTABLE_SUFFIX");
109 // make sure we remove any /./ in the name
110 cmSystemTools::ReplaceString(utilityExecutable, "/./", "/");
112 // Enter the value into the cache.
113 this->Makefile->AddCacheDefinition(cacheEntry.c_str(),
114 utilityExecutable.c_str(),
115 "Path to an internal program.",
116 cmCacheManager::FILEPATH);
117 // add a value into the cache that maps from the
118 // full path to the name of the project
119 cmSystemTools::ConvertToUnixSlashes(utilityExecutable);
120 this->Makefile->AddCacheDefinition(utilityExecutable.c_str(),
122 "Executable to project name.",
123 cmCacheManager::INTERNAL);