2009-09-28 15:43:28 +00:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2002-09-19 13:48:39 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2002-09-19 13:48:39 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2002-09-19 13:48:39 +00:00
|
|
|
#ifndef cmTryRunCommand_h
|
|
|
|
#define cmTryRunCommand_h
|
|
|
|
|
2007-05-24 15:27:51 +00:00
|
|
|
#include "cmCoreTryCompile.h"
|
2002-09-19 13:48:39 +00:00
|
|
|
|
|
|
|
/** \class cmTryRunCommand
|
|
|
|
* \brief Specifies where to install some files
|
|
|
|
*
|
|
|
|
* cmTryRunCommand is used to test if soucre code can be compiled
|
|
|
|
*/
|
2007-05-24 15:27:51 +00:00
|
|
|
class cmTryRunCommand : public cmCoreTryCompile
|
2002-09-19 13:48:39 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* This is a virtual constructor for the command.
|
|
|
|
*/
|
2012-08-13 17:42:58 +00:00
|
|
|
virtual cmCommand* Clone()
|
2002-09-19 13:48:39 +00:00
|
|
|
{
|
|
|
|
return new cmTryRunCommand;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called when the command is first encountered in
|
|
|
|
* the CMakeLists.txt file.
|
|
|
|
*/
|
2008-01-23 15:28:26 +00:00
|
|
|
virtual bool InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus &status);
|
2002-09-19 13:48:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The name of the command as specified in CMakeList.txt.
|
|
|
|
*/
|
2012-02-25 06:49:24 +00:00
|
|
|
virtual const char* GetName() const { return "try_run";}
|
2002-09-19 13:48:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Succinct documentation.
|
|
|
|
*/
|
2012-02-25 06:49:24 +00:00
|
|
|
virtual const char* GetTerseDocumentation() const
|
2002-09-19 13:48:39 +00:00
|
|
|
{
|
|
|
|
return "Try compiling and then running some code.";
|
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2002-09-19 13:48:39 +00:00
|
|
|
/**
|
|
|
|
* More documentation.
|
|
|
|
*/
|
2012-02-25 06:49:24 +00:00
|
|
|
virtual const char* GetFullDocumentation() const
|
2002-09-19 13:48:39 +00:00
|
|
|
{
|
|
|
|
return
|
2007-10-10 15:47:43 +00:00
|
|
|
" try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR\n"
|
2007-06-01 15:16:29 +00:00
|
|
|
" bindir srcfile [CMAKE_FLAGS <Flags>]\n"
|
|
|
|
" [COMPILE_DEFINITIONS <flags>]\n"
|
|
|
|
" [COMPILE_OUTPUT_VARIABLE comp]\n"
|
|
|
|
" [RUN_OUTPUT_VARIABLE run]\n"
|
|
|
|
" [OUTPUT_VARIABLE var]\n"
|
|
|
|
" [ARGS <arg1> <arg2>...])\n"
|
|
|
|
"Try compiling a srcfile. Return TRUE or FALSE for success or failure "
|
|
|
|
"in COMPILE_RESULT_VAR. Then if the compile succeeded, run the "
|
|
|
|
"executable and return its exit code in RUN_RESULT_VAR. "
|
|
|
|
"If the executable was built, but failed to run, then RUN_RESULT_VAR "
|
|
|
|
"will be set to FAILED_TO_RUN. "
|
|
|
|
"COMPILE_OUTPUT_VARIABLE specifies the variable where the output from "
|
|
|
|
"the compile step goes. RUN_OUTPUT_VARIABLE specifies the variable "
|
|
|
|
"where the output from the running executable goes.\n"
|
|
|
|
"For compatibility reasons OUTPUT_VARIABLE is still supported, which "
|
2009-09-03 19:29:29 +00:00
|
|
|
"gives you the output from the compile and run step combined.\n"
|
2007-06-01 15:16:29 +00:00
|
|
|
"Cross compiling issues\n"
|
|
|
|
"When cross compiling, the executable compiled in the first step "
|
2007-10-10 15:47:43 +00:00
|
|
|
"usually cannot be run on the build host. try_run() checks the "
|
2007-06-01 15:16:29 +00:00
|
|
|
"CMAKE_CROSSCOMPILING variable to detect whether CMake is in "
|
|
|
|
"crosscompiling mode. If that's the case, it will still try to compile "
|
|
|
|
"the executable, but it will not try to run the executable. Instead it "
|
|
|
|
"will create cache variables which must be filled by the user or by "
|
|
|
|
"presetting them in some CMake script file to the values the "
|
2012-11-07 13:17:32 +00:00
|
|
|
"executable would have produced if it had been run on its actual "
|
2007-06-01 15:16:29 +00:00
|
|
|
"target platform. These variables are RUN_RESULT_VAR (explanation see "
|
|
|
|
"above) and if RUN_OUTPUT_VARIABLE (or OUTPUT_VARIABLE) was used, an "
|
|
|
|
"additional cache variable "
|
|
|
|
"RUN_RESULT_VAR__COMPILE_RESULT_VAR__TRYRUN_OUTPUT."
|
|
|
|
"This is intended to hold stdout and stderr from the executable.\n"
|
2007-10-10 15:47:43 +00:00
|
|
|
"In order to make cross compiling your project easier, use try_run "
|
|
|
|
"only if really required. If you use try_run, use RUN_OUTPUT_VARIABLE "
|
2007-06-01 15:16:29 +00:00
|
|
|
"(or OUTPUT_VARIABLE) only if really required. Using them will require "
|
|
|
|
"that when crosscompiling, the cache variables will have to be set "
|
|
|
|
"manually to the output of the executable. You can also \"guard\" the "
|
2007-10-10 15:47:43 +00:00
|
|
|
"calls to try_run with if(CMAKE_CROSSCOMPILING) and provide an "
|
2011-01-17 22:23:15 +00:00
|
|
|
"easy-to-preset alternative for this case.\n"
|
|
|
|
"Set variable CMAKE_TRY_COMPILE_CONFIGURATION to choose a build "
|
|
|
|
"configuration."
|
|
|
|
;
|
2002-09-19 13:48:39 +00:00
|
|
|
}
|
2007-06-01 15:16:29 +00:00
|
|
|
|
2007-05-24 15:27:51 +00:00
|
|
|
cmTypeMacro(cmTryRunCommand, cmCoreTryCompile);
|
2007-06-01 15:16:29 +00:00
|
|
|
private:
|
2012-08-13 17:42:58 +00:00
|
|
|
void RunExecutable(const std::string& runArgs,
|
2007-07-20 12:36:16 +00:00
|
|
|
std::string* runOutputContents);
|
2012-08-13 17:42:58 +00:00
|
|
|
void DoNotRunExecutable(const std::string& runArgs,
|
|
|
|
const std::string& srcFile,
|
2007-07-20 12:36:16 +00:00
|
|
|
std::string* runOutputContents);
|
2002-09-19 13:48:39 +00:00
|
|
|
|
2007-06-01 15:16:29 +00:00
|
|
|
std::string CompileResultVariable;
|
|
|
|
std::string RunResultVariable;
|
|
|
|
std::string OutputVariable;
|
|
|
|
std::string RunOutputVariable;
|
|
|
|
std::string CompileOutputVariable;
|
2002-09-19 13:48:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|