summaryrefslogtreecommitdiff
path: root/Source/cmTryRunCommand.h
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2007-06-01 11:16:29 -0400
committerAlexander Neundorf <neundorf@kde.org>2007-06-01 11:16:29 -0400
commiteddf1cf39f50f9b06131ead26b5b84b8edfd60da (patch)
tree1cbc429b0f2006f19ee9c19773f841648405793d /Source/cmTryRunCommand.h
parent26a5a295eb231dc9fae9ea90f6cf28d3b4eecaa2 (diff)
downloadcmake-eddf1cf39f50f9b06131ead26b5b84b8edfd60da.tar.gz
ENH: improve TRY_RUN() for crosscompiling: instead of just failing, it now
creates two cache variables, one for the RUN_RESULT, one for the RUN_OUTPUT (if required), which can be set or preset by the user. It has now also two new arguments: RUN_OUTPUT_VARIABLE and COMPILE_OUTPUT_VARIABLE (the old OUTPUT_VARIABLE merges both), so if only COMPILE_OUTPUT_VARIABLE is used the run time output of the TRY_RUN is unused and the user doesn't have to care about the output when crosscompiling. This is now used in FindThreads.cmake, CheckC/CXXSourceRuns.cmake and TestBigEndian.cmake, which used the output only for the logfile (compile output is still there). Test/TryCompile/ now also tests the behaviour of OUTPUT_VARIABLE, RUN_OUTPUT_VARIABLE and COMPILE_OUTPUT_VARIABLE. Alex
Diffstat (limited to 'Source/cmTryRunCommand.h')
-rw-r--r--Source/cmTryRunCommand.h59
1 files changed, 46 insertions, 13 deletions
diff --git a/Source/cmTryRunCommand.h b/Source/cmTryRunCommand.h
index b11a7c46a6..8c4788c203 100644
--- a/Source/cmTryRunCommand.h
+++ b/Source/cmTryRunCommand.h
@@ -61,22 +61,55 @@ public:
{
return
" TRY_RUN(RUN_RESULT_VAR COMPILE_RESULT_VAR\n"
- " bindir srcfile <CMAKE_FLAGS <Flags>>\n"
- " <COMPILE_DEFINITIONS <flags>>\n"
- " <OUTPUT_VARIABLE var>\n"
- " <ARGS <arg1> <arg2>...>)\n"
- "Try compiling a srcfile. Return the success or failure in "
- "COMPILE_RESULT_VAR. Then if the compile succeeded, run the "
- "executable and return the result in RUN_RESULT_VAR. "
- "If the executable was built, but failed to run for some"
- "reason, then RUN_RESULT_VAR will be set to FAILED_TO_RUN, and "
- "the output will be in the COMPILE_RESULT_VAR. OUTPUT_VARIABLE "
- "specifies the name of the variable to put all of the standard "
- "output and standard error into.";
+ " 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 "
+ "gives you the output from the compile and run step combined.\n\n"
+ "Cross compiling issues\n"
+ "When cross compiling, the executable compiled in the first step "
+ "usually cannot be run on the build host. TRY_RUN() checks the "
+ "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 "
+ "executable would have produced if it would have been run on its actual "
+ "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"
+ "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 "
+ "(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 "
+ "calls to TRY_RUN with IF(CMAKE_CROSSCOMPILING) and provide an "
+ "easy-to-preset alternative for this case.\n";
}
-
+
cmTypeMacro(cmTryRunCommand, cmCoreTryCompile);
+private:
+ void RunExecutable(const std::string& runArgs, std::string* runOutputContents);
+ void DoNotRunExecutable(const std::string& runArgs, const std::string& srcFile, std::string* runOutputContents);
+ std::string CompileResultVariable;
+ std::string RunResultVariable;
+ std::string OutputVariable;
+ std::string RunOutputVariable;
+ std::string CompileOutputVariable;
};