1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #ifndef cmTryCompileCommand_h
13 #define cmTryCompileCommand_h
15 #include "cmCoreTryCompile.h"
17 /** \class cmTryCompileCommand
18 * \brief Specifies where to install some files
20 * cmTryCompileCommand is used to test if soucre code can be compiled
22 class cmTryCompileCommand : public cmCoreTryCompile
26 * This is a virtual constructor for the command.
28 virtual cmCommand* Clone()
30 return new cmTryCompileCommand;
34 * This is called when the command is first encountered in
35 * the CMakeLists.txt file.
37 virtual bool InitialPass(std::vector<std::string> const& args,
38 cmExecutionStatus &status);
41 * The name of the command as specified in CMakeList.txt.
43 virtual const char* GetName() const { return "try_compile";}
46 * Succinct documentation.
48 virtual const char* GetTerseDocumentation() const
50 return "Try building some code.";
54 * More documentation. */
55 virtual const char* GetFullDocumentation() const
58 " try_compile(RESULT_VAR <bindir> <srcdir>\n"
59 " <projectName> [targetName] [CMAKE_FLAGS flags...]\n"
60 " [OUTPUT_VARIABLE <var>])\n"
61 "Try building a project. In this form, srcdir should contain a "
62 "complete CMake project with a CMakeLists.txt file and all sources. "
63 "The bindir and srcdir will not be deleted after this command is run. "
64 "Specify targetName to build a specific target instead of the 'all' or "
67 " try_compile(RESULT_VAR <bindir> <srcfile|SOURCES srcfile...>\n"
68 " [CMAKE_FLAGS flags...]\n"
69 " [COMPILE_DEFINITIONS flags...]\n"
70 " [LINK_LIBRARIES libs...]\n"
71 " [OUTPUT_VARIABLE <var>]\n"
72 " [COPY_FILE <fileName> [COPY_FILE_ERROR <var>]])\n"
73 "Try building an executable from one or more source files. "
74 "In this form the user need only supply one or more source files "
75 "that include a definition for 'main'. "
76 "CMake will create a CMakeLists.txt file to build the source(s) "
78 "Specify COPY_FILE to get a copy of the linked executable at the "
79 "given fileName and optionally COPY_FILE_ERROR to capture any error."
81 "In this version all files in bindir/CMakeFiles/CMakeTmp "
82 "will be cleaned automatically. For debugging, --debug-trycompile can "
83 "be passed to cmake to avoid this clean. However, multiple sequential "
84 "try_compile operations reuse this single output directory. If you "
85 "use --debug-trycompile, you can only debug one try_compile call at a "
86 "time. The recommended procedure is to configure with cmake all the "
87 "way through once, then delete the cache entry associated with "
88 "the try_compile call of interest, and then re-run cmake again with "
91 "Some extra flags that can be included are, "
92 "INCLUDE_DIRECTORIES, LINK_DIRECTORIES, and LINK_LIBRARIES. "
93 "COMPILE_DEFINITIONS are -Ddefinition that will be passed to the "
95 "The srcfile signature also accepts a LINK_LIBRARIES argument which "
96 "may contain a list of libraries or IMPORTED targets which will be "
97 "linked to in the generated project. If LINK_LIBRARIES is specified "
98 "as a parameter to try_compile, then any LINK_LIBRARIES passed as "
99 "CMAKE_FLAGS will be ignored.\n"
100 "try_compile creates a CMakeList.txt "
101 "file on the fly that looks like this:\n"
102 " add_definitions( <expanded COMPILE_DEFINITIONS from calling "
104 " include_directories(${INCLUDE_DIRECTORIES})\n"
105 " link_directories(${LINK_DIRECTORIES})\n"
106 " add_executable(cmTryCompileExec sources)\n"
107 " target_link_libraries(cmTryCompileExec ${LINK_LIBRARIES})\n"
108 "In both versions of the command, "
109 "if OUTPUT_VARIABLE is specified, then the "
110 "output from the build process is stored in the given variable. "
111 "The success or failure of the try_compile, i.e. TRUE or FALSE "
112 "respectively, is returned in "
113 "RESULT_VAR. CMAKE_FLAGS can be used to pass -DVAR:TYPE=VALUE flags "
114 "to the cmake that is run during the build. "
115 "Set variable CMAKE_TRY_COMPILE_CONFIGURATION to choose a build "
120 cmTypeMacro(cmTryCompileCommand, cmCoreTryCompile);