cmTryCompileCommand.h 3.0 KB

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