cmTryCompileCommand.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmTryCompileCommand_h
  11. #define cmTryCompileCommand_h
  12. #include "cmCoreTryCompile.h"
  13. /** \class cmTryCompileCommand
  14. * \brief Specifies where to install some files
  15. *
  16. * cmTryCompileCommand is used to test if soucre code can be compiled
  17. */
  18. class cmTryCompileCommand : public cmCoreTryCompile
  19. {
  20. public:
  21. /**
  22. * This is a virtual constructor for the command.
  23. */
  24. virtual cmCommand* Clone()
  25. {
  26. return new cmTryCompileCommand;
  27. }
  28. /**
  29. * This is called when the command is first encountered in
  30. * the CMakeLists.txt file.
  31. */
  32. virtual bool InitialPass(std::vector<std::string> const& args,
  33. cmExecutionStatus &status);
  34. /**
  35. * The name of the command as specified in CMakeList.txt.
  36. */
  37. virtual const char* GetName() { return "try_compile";}
  38. /**
  39. * Succinct documentation.
  40. */
  41. virtual const char* GetTerseDocumentation()
  42. {
  43. return "Try compiling some code.";
  44. }
  45. /**
  46. * More documentation. */
  47. virtual const char* GetFullDocumentation()
  48. {
  49. return
  50. " try_compile(RESULT_VAR bindir srcdir\n"
  51. " projectName <targetname> [CMAKE_FLAGS <Flags>]\n"
  52. " [OUTPUT_VARIABLE var])\n"
  53. "Try compiling a program. In this form, srcdir should contain a "
  54. "complete CMake project with a CMakeLists.txt file and all sources. The "
  55. "bindir and srcdir will not be deleted after this command is run. "
  56. "If <target name> is specified then build just that target "
  57. "otherwise the all or ALL_BUILD target is built.\n"
  58. " try_compile(RESULT_VAR bindir srcfile\n"
  59. " [CMAKE_FLAGS <Flags>]\n"
  60. " [COMPILE_DEFINITIONS <flags> ...]\n"
  61. " [OUTPUT_VARIABLE var]\n"
  62. " [COPY_FILE <filename> )\n"
  63. "Try compiling a srcfile. In this case, the user need only supply a "
  64. "source file. CMake will create the appropriate CMakeLists.txt file "
  65. "to build the source. If COPY_FILE is used, the compiled file will be "
  66. "copied to the given file.\n"
  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