cmTryCompileCommand.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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() const { return "try_compile";}
  38. /**
  39. * Succinct documentation.
  40. */
  41. virtual const char* GetTerseDocumentation() const
  42. {
  43. return "Try building some code.";
  44. }
  45. /**
  46. * More documentation. */
  47. virtual const char* GetFullDocumentation() const
  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 building a project. In this form, srcdir should contain a "
  54. "complete CMake project with a CMakeLists.txt file and all sources. "
  55. "The bindir and srcdir will not be deleted after this command is run. "
  56. "Specify targetName to build a specific target instead of the 'all' or "
  57. "'ALL_BUILD' target."
  58. "\n"
  59. " try_compile(RESULT_VAR <bindir> <srcfile>\n"
  60. " [CMAKE_FLAGS flags...]\n"
  61. " [COMPILE_DEFINITIONS flags...]\n"
  62. " [LINK_LIBRARIES libs...]\n"
  63. " [OUTPUT_VARIABLE <var>]\n"
  64. " [COPY_FILE <fileName>])\n"
  65. "Try building a source file into an executable. "
  66. "In this form the user need only supply a source file that defines "
  67. "a 'main'. "
  68. "CMake will create a CMakeLists.txt file to build the source "
  69. "as an executable. "
  70. "Specify COPY_FILE to get a copy of the linked executable at the "
  71. "given fileName."
  72. "\n"
  73. "In this version all files in bindir/CMakeFiles/CMakeTmp "
  74. "will be cleaned automatically. For debugging, --debug-trycompile can "
  75. "be passed to cmake to avoid this clean. However, multiple sequential "
  76. "try_compile operations reuse this single output directory. If you "
  77. "use --debug-trycompile, you can only debug one try_compile call at a "
  78. "time. The recommended procedure is to configure with cmake all the "
  79. "way through once, then delete the cache entry associated with "
  80. "the try_compile call of interest, and then re-run cmake again with "
  81. "--debug-trycompile."
  82. "\n"
  83. "Some extra flags that can be included are, "
  84. "INCLUDE_DIRECTORIES, LINK_DIRECTORIES, and LINK_LIBRARIES. "
  85. "COMPILE_DEFINITIONS are -Ddefinition that will be passed to the "
  86. "compile line.\n"
  87. "The srcfile signature also accepts a LINK_LIBRARIES argument which "
  88. "may contain a list of libraries or IMPORTED targets which will be "
  89. "linked to in the generated project. If LINK_LIBRARIES is specified "
  90. "as a parameter to try_compile, then any LINK_LIBRARIES passed as "
  91. "CMAKE_FLAGS will be ignored.\n"
  92. "try_compile creates a CMakeList.txt "
  93. "file on the fly that looks like this:\n"
  94. " add_definitions( <expanded COMPILE_DEFINITIONS from calling "
  95. "cmake>)\n"
  96. " include_directories(${INCLUDE_DIRECTORIES})\n"
  97. " link_directories(${LINK_DIRECTORIES})\n"
  98. " add_executable(cmTryCompileExec sources)\n"
  99. " target_link_libraries(cmTryCompileExec ${LINK_LIBRARIES})\n"
  100. "In both versions of the command, "
  101. "if OUTPUT_VARIABLE is specified, then the "
  102. "output from the build process is stored in the given variable. "
  103. "The success or failure of the try_compile, i.e. TRUE or FALSE "
  104. "respectively, is returned in "
  105. "RESULT_VAR. CMAKE_FLAGS can be used to pass -DVAR:TYPE=VALUE flags "
  106. "to the cmake that is run during the build. "
  107. "Set variable CMAKE_TRY_COMPILE_CONFIGURATION to choose a build "
  108. "configuration."
  109. ;
  110. }
  111. cmTypeMacro(cmTryCompileCommand, cmCoreTryCompile);
  112. };
  113. #endif