cmTryCompileCommand.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "cmCoreTryCompile.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 cmCoreTryCompile
  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. * More documentation. */
  49. virtual const char* GetFullDocumentation()
  50. {
  51. return
  52. " TRY_COMPILE(RESULT_VAR bindir srcdir\n"
  53. " projectName <targetname> <CMAKE_FLAGS <Flags>>\n"
  54. " <OUTPUT_VARIABLE var>)\n"
  55. "Try compiling a program. In this form, srcdir should contain a complete "
  56. "CMake project with a CMakeLists.txt file and all sources. The bindir and "
  57. "srcdir will not be deleted after this command is run. "
  58. "If <target name> is specified then build just that target "
  59. "otherwise the all or ALL_BUILD target is built.\n"
  60. " TRY_COMPILE(RESULT_VAR bindir srcfile\n"
  61. " <CMAKE_FLAGS <Flags>>\n"
  62. " <COMPILE_DEFINITIONS <flags> ...>\n"
  63. " <OUTPUT_VARIABLE var>)\n"
  64. "Try compiling a srcfile. In this case, the user need only supply a "
  65. "source file. CMake will create the appropriate CMakeLists.txt file "
  66. "to build the source. "
  67. "In this version all files in bindir/CMakeFiles/CMakeTmp, "
  68. "will be cleaned automatically, for debugging a --debug-trycompile can "
  69. "be passed to cmake to avoid the clean. Some extra flags that "
  70. " can be included are, "
  71. "INCLUDE_DIRECTORIES, LINK_DIRECTORIES, and LINK_LIBRARIES. "
  72. "COMPILE_DEFINITIONS are -Ddefinition that will be passed to the "
  73. "compile line. "
  74. "TRY_COMPILE creates a CMakeList.txt "
  75. "file on the fly that looks like this:\n"
  76. " ADD_DEFINITIONS( <expanded COMPILE_DEFINITIONS from calling "
  77. "cmake>)\n"
  78. " INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES})\n"
  79. " LINK_DIRECTORIES(${LINK_DIRECTORIES})\n"
  80. " ADD_EXECUTABLE(cmTryCompileExec sources)\n"
  81. " TARGET_LINK_LIBRARIES(cmTryCompileExec ${LINK_LIBRARIES})\n"
  82. "In both versions of the command, "
  83. "if OUTPUT_VARIABLE is specified, then the "
  84. "output from the build process is stored in the given variable. "
  85. "Return the success or failure in "
  86. "RESULT_VAR. CMAKE_FLAGS can be used to pass -DVAR:TYPE=VALUE flags "
  87. "to the cmake that is run during the build. "
  88. "";
  89. }
  90. cmTypeMacro(cmTryCompileCommand, cmCoreTryCompile);
  91. };
  92. #endif