1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmTryRunCommand.cxx,v $
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
)
29 if ( m_Makefile
->GetLocal() )
34 // build an arg list for TryCompile and extract the runArgs
35 std::vector
<std::string
> tryCompile
;
38 for (i
= 1; i
< argv
.size(); ++i
)
40 if (argv
[i
] == "ARGS")
43 while (i
< argv
.size() && argv
[i
] != "COMPILE_DEFINITIONS" &&
44 argv
[i
] != "CMAKE_FLAGS")
52 tryCompile
.push_back(argv
[i
]);
57 tryCompile
.push_back(argv
[i
]);
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";
71 command
= binaryDirectory
;
72 command
+= "/cmTryCompileExec";
73 command
+= cmSystemTools::GetExecutableExtension();
75 if(cmSystemTools::FileExists(command
.c_str()))
77 fullPath
= cmSystemTools::CollapseFullPath(command
.c_str());
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());
90 cmSystemTools::Error("Unable to find executable for TRY_RUN",
94 if (fullPath
.size() > 1)
96 std::string finalCommand
= fullPath
;
97 finalCommand
= cmSystemTools::ConvertToOutputPath(fullPath
.c_str());
100 finalCommand
+= runArgs
;
102 cmSystemTools::RunCommand(finalCommand
.c_str(), output
, retVal
, 0, false);
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());