cmTryCompileCommand.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 <targetname> <CMAKE_FLAGS <Flags>>\n"
  67. " <OUTPUT_VARIABLE var>)\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. " <OUTPUT_VARIABLE var>)\n"
  75. "Try compiling a srcfile. Return the success or failure in RESULT_VAR. "
  76. "CMAKE_FLAGS can be used to pass -DVAR:TYPE=VALUE flags to cmake. Some "
  77. "extra flags that can be included are, "
  78. "INCLUDE_DIRECTORIES, LINK_DIRECTORIES, and LINK_LIBRARIES. "
  79. "COMPILE_DEFINITIONS are -Ddefinition that will be passed to the "
  80. "compile line. If srcfile is specified the files in "
  81. "bindir/CMakeFiles/CMakeTmp "
  82. "are cleaned automatically. If OUTPUT_VARIABLE is specified, then the "
  83. "output from the build process is stored in the given variable. "
  84. "TRY_COMPILE creates a CMakeList.txt "
  85. "file on the fly, and in that file it looks like this:\n"
  86. " ADD_DEFINITIONS( <expanded COMPILE_DEFINITIONS from calling cmake>)\n"
  87. " INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES})\n"
  88. " LINK_DIRECTORIES(${LINK_DIRECTORIES})\n"
  89. " ADD_EXECUTABLE(cmTryCompileExec sources)\n"
  90. " TARGET_LINK_LIBRARIES(cmTryCompileExec ${LINK_LIBRARIES})\n";
  91. }
  92. cmTypeMacro(cmTryCompileCommand, cmCommand);
  93. };
  94. #endif