ENH: put the 64 bit paths first
[cmake.git] / Source / cmUtilitySourceCommand.cxx
blob7a36a898946775bf7f1426377dd1c81c3b6f5d4f
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmUtilitySourceCommand.cxx,v $
5 Language: C++
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 &)
23 if(args.size() < 3)
25 this->SetError("called with incorrect number of arguments");
26 return false;
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.
38 const char* intDir =
39 this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
41 bool haveCacheValue = false;
42 if (this->Makefile->IsOn("CMAKE_CROSSCOMPILING"))
44 haveCacheValue = (cacheValue != 0);
45 if (!haveCacheValue)
47 std::string msg = "UTILITY_SOURCE is used in cross compiling mode for ";
48 msg += cacheEntry;
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");
55 else
57 haveCacheValue = (cacheValue &&
58 (strstr(cacheValue, "(IntDir)") == 0 ||
59 intDir && strcmp(intDir, "$(IntDir)") == 0) &&
60 (this->Makefile->GetCacheMajorVersion() != 0 &&
61 this->Makefile->GetCacheMinorVersion() != 0 ));
64 if(haveCacheValue)
66 return true;
69 // The second argument is the utility's executable name, which will be
70 // needed later.
71 std::string utilityName = *arg++;
73 // The third argument specifies the relative directory of the source
74 // of the utility.
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()))
81 { return true; }
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()))
88 { return true; }
91 // The source exists.
92 std::string cmakeCFGout =
93 this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
94 std::string utilityDirectory = this->Makefile->GetCurrentOutputDirectory();
95 std::string exePath;
96 if (this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
98 exePath = this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
100 if(exePath.size())
102 utilityDirectory = exePath;
104 else
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(),
126 utilityName.c_str(),
127 "Executable to project name.",
128 cmCacheManager::INTERNAL);
130 return true;