cmTryCompileCommand.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 cmTryCompileCommand_h
  14. #define cmTryCompileCommand_h
  15. #include "cmCommand.h"
  16. /** \class cmTryCompileCommand
  17. * \brief Specifies where to install some files
  18. *
  19. * cmTryCompileCommand is used to test if soucre code can be compiled
  20. */
  21. class cmTryCompileCommand : public cmCommand
  22. {
  23. public:
  24. /**
  25. * This is a virtual constructor for the command.
  26. */
  27. virtual cmCommand* Clone()
  28. {
  29. return new cmTryCompileCommand;
  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_COMPILE";}
  40. /**
  41. * Succinct documentation.
  42. */
  43. virtual const char* GetTerseDocumentation()
  44. {
  45. return "Try compiling some code.";
  46. }
  47. /**
  48. * This is the core code for try compile. It is here so that other
  49. * commands, such as TryRun can access the same logic without
  50. * duplication.
  51. */
  52. static int CoreTryCompileCode(
  53. cmMakefile *mf, std::vector<std::string> const& argv, bool clean);
  54. /**
  55. * This deletes all the files created by TRY_COMPILE or TRY_RUN
  56. * code. This way we do not have to rely on the timing and
  57. * dependencies of makefiles.
  58. */
  59. static void CleanupFiles(const char* binDir);
  60. /**
  61. * More documentation. */
  62. virtual const char* GetFullDocumentation()
  63. {
  64. return
  65. " TRY_COMPILE(RESULT_VAR bindir srcdir\n"
  66. " projectName <CMAKE_FLAGS <Flags>>)\n"
  67. "Try compiling a program. Return the success or failure in RESULT_VAR. "
  68. "If <target name> is specified then build just that target "
  69. "otherwise the all or ALL_BUILD target is built.\n"
  70. " TRY_COMPILE(RESULT_VAR bindir srcfile\n"
  71. " <CMAKE_FLAGS <Flags>>\n"
  72. " <COMPILE_DEFINITIONS <flags> ...>)\n"
  73. "Try compiling a srcfile. Return the success or failure in RESULT_VAR. "
  74. "CMAKE_FLAGS can be used to pass -DVAR:TYPE=VALUE flags to cmake. The "
  75. "COMPILE_DEFINITIONS are -Ddefinition that will be passed to the "
  76. "compile line. If srcfile is specified the files in bindir/CMakeTmp "
  77. "are cleaned.";
  78. }
  79. cmTypeMacro(cmTryCompileCommand, cmCommand);
  80. };
  81. #endif