You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.6 KiB

23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmTryRunCommand_h
  14. #define cmTryRunCommand_h
  15. #include "cmCoreTryCompile.h"
  16. /** \class cmTryRunCommand
  17. * \brief Specifies where to install some files
  18. *
  19. * cmTryRunCommand is used to test if soucre code can be compiled
  20. */
  21. class cmTryRunCommand : public cmCoreTryCompile
  22. {
  23. public:
  24. /**
  25. * This is a virtual constructor for the command.
  26. */
  27. virtual cmCommand* Clone()
  28. {
  29. return new cmTryRunCommand;
  30. }
  31. /**
  32. * This is called when the command is first encountered in
  33. * the CMakeLists.txt file.
  34. */
  35. virtual bool InitialPass(std::vector<std::string> const& args);
  36. /**
  37. * The name of the command as specified in CMakeList.txt.
  38. */
  39. virtual const char* GetName() { return "try_run";}
  40. /**
  41. * Succinct documentation.
  42. */
  43. virtual const char* GetTerseDocumentation()
  44. {
  45. return "Try compiling and then running some code.";
  46. }
  47. /**
  48. * More documentation.
  49. */
  50. virtual const char* GetFullDocumentation()
  51. {
  52. return
  53. " try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR\n"
  54. " bindir srcfile [CMAKE_FLAGS <Flags>]\n"
  55. " [COMPILE_DEFINITIONS <flags>]\n"
  56. " [COMPILE_OUTPUT_VARIABLE comp]\n"
  57. " [RUN_OUTPUT_VARIABLE run]\n"
  58. " [OUTPUT_VARIABLE var]\n"
  59. " [ARGS <arg1> <arg2>...])\n"
  60. "Try compiling a srcfile. Return TRUE or FALSE for success or failure "
  61. "in COMPILE_RESULT_VAR. Then if the compile succeeded, run the "
  62. "executable and return its exit code in RUN_RESULT_VAR. "
  63. "If the executable was built, but failed to run, then RUN_RESULT_VAR "
  64. "will be set to FAILED_TO_RUN. "
  65. "COMPILE_OUTPUT_VARIABLE specifies the variable where the output from "
  66. "the compile step goes. RUN_OUTPUT_VARIABLE specifies the variable "
  67. "where the output from the running executable goes.\n"
  68. "For compatibility reasons OUTPUT_VARIABLE is still supported, which "
  69. "gives you the output from the compile and run step combined.\n\n"
  70. "Cross compiling issues\n"
  71. "When cross compiling, the executable compiled in the first step "
  72. "usually cannot be run on the build host. try_run() checks the "
  73. "CMAKE_CROSSCOMPILING variable to detect whether CMake is in "
  74. "crosscompiling mode. If that's the case, it will still try to compile "
  75. "the executable, but it will not try to run the executable. Instead it "
  76. "will create cache variables which must be filled by the user or by "
  77. "presetting them in some CMake script file to the values the "
  78. "executable would have produced if it would have been run on its actual "
  79. "target platform. These variables are RUN_RESULT_VAR (explanation see "
  80. "above) and if RUN_OUTPUT_VARIABLE (or OUTPUT_VARIABLE) was used, an "
  81. "additional cache variable "
  82. "RUN_RESULT_VAR__COMPILE_RESULT_VAR__TRYRUN_OUTPUT."
  83. "This is intended to hold stdout and stderr from the executable.\n"
  84. "In order to make cross compiling your project easier, use try_run "
  85. "only if really required. If you use try_run, use RUN_OUTPUT_VARIABLE "
  86. "(or OUTPUT_VARIABLE) only if really required. Using them will require "
  87. "that when crosscompiling, the cache variables will have to be set "
  88. "manually to the output of the executable. You can also \"guard\" the "
  89. "calls to try_run with if(CMAKE_CROSSCOMPILING) and provide an "
  90. "easy-to-preset alternative for this case.\n";
  91. }
  92. cmTypeMacro(cmTryRunCommand, cmCoreTryCompile);
  93. private:
  94. void RunExecutable(const std::string& runArgs,
  95. std::string* runOutputContents);
  96. void DoNotRunExecutable(const std::string& runArgs,
  97. const std::string& srcFile,
  98. std::string* runOutputContents);
  99. std::string CompileResultVariable;
  100. std::string RunResultVariable;
  101. std::string OutputVariable;
  102. std::string RunOutputVariable;
  103. std::string CompileOutputVariable;
  104. };
  105. #endif