ENH: mark some vars as advanced (and resort the list)
[cmake.git] / Source / cmTryRunCommand.cxx
blob73013e0753581e00ce586171fe5b3aeb6ea65b58
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmTryRunCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2002-09-24 17:17:39 $
7 Version: $Revision: 1.8 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 "cmTryRunCommand.h"
18 #include "cmCacheManager.h"
19 #include "cmTryCompileCommand.h"
21 // cmExecutableCommand
22 bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv)
24 if(argv.size() < 4)
26 return false;
29 if ( m_Makefile->GetLocal() )
31 return true;
34 // build an arg list for TryCompile and extract the runArgs
35 std::vector<std::string> tryCompile;
36 std::string runArgs;
37 unsigned int i;
38 for (i = 1; i < argv.size(); ++i)
40 if (argv[i] == "ARGS")
42 ++i;
43 while (i < argv.size() && argv[i] != "COMPILE_DEFINITIONS" &&
44 argv[i] != "CMAKE_FLAGS")
46 runArgs += " ";
47 runArgs += argv[i];
48 ++i;
50 if (i < argv.size())
52 tryCompile.push_back(argv[i]);
55 else
57 tryCompile.push_back(argv[i]);
61 // do the try compile
62 int res = cmTryCompileCommand::CoreTryCompileCode(m_Makefile, tryCompile, false);
64 // now try running the command if it compiled
65 std::string binaryDirectory = argv[2] + "/CMakeTmp";
66 if (!res)
68 int retVal;
69 std::string output;
70 std::string command;
71 command = binaryDirectory;
72 command += "/cmTryCompileExec";
73 command += cmSystemTools::GetExecutableExtension();
74 std::string fullPath;
75 if(cmSystemTools::FileExists(command.c_str()))
77 fullPath = cmSystemTools::CollapseFullPath(command.c_str());
79 else
81 command = binaryDirectory;
82 command += "/Debug/cmTryCompileExec";
83 command += cmSystemTools::GetExecutableExtension();
84 if(cmSystemTools::FileExists(command.c_str()))
86 fullPath = cmSystemTools::CollapseFullPath(command.c_str());
88 else
90 cmSystemTools::Error("Unable to find executable for TRY_RUN",
91 command.c_str());
94 if (fullPath.size() > 1)
96 std::string finalCommand = fullPath;
97 finalCommand = cmSystemTools::ConvertToOutputPath(fullPath.c_str());
98 if(runArgs.size())
100 finalCommand += runArgs;
102 cmSystemTools::RunCommand(finalCommand.c_str(), output, retVal, 0, false);
103 // set the run var
104 char retChar[1000];
105 sprintf(retChar,"%i",retVal);
106 m_Makefile->AddCacheDefinition(argv[0].c_str(), retChar,
107 "Result of TRY_RUN", cmCacheManager::INTERNAL);
111 // if we created a directory etc, then cleanup after ourselves
112 std::string cacheFile = binaryDirectory;
113 cacheFile += "/CMakeLists.txt";
114 cmListFileCache::GetInstance()->FlushCache(cacheFile.c_str());
115 cmTryCompileCommand::CleanupFiles(binaryDirectory.c_str());
116 return true;