a241a3a64308c279f855ddd6944968b62a4cbc88
[platform/upstream/cmake.git] / Source / cmCommands.cxx
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3
4 #include "cmCommands.h"
5
6 #include <cm/memory>
7
8 #include "cmAddCompileDefinitionsCommand.h"
9 #include "cmAddCustomCommandCommand.h"
10 #include "cmAddCustomTargetCommand.h"
11 #include "cmAddDefinitionsCommand.h"
12 #include "cmAddDependenciesCommand.h"
13 #include "cmAddExecutableCommand.h"
14 #include "cmAddLibraryCommand.h"
15 #include "cmAddSubDirectoryCommand.h"
16 #include "cmAddTestCommand.h"
17 #include "cmBreakCommand.h"
18 #include "cmBuildCommand.h"
19 #include "cmCMakeMinimumRequired.h"
20 #include "cmCMakePathCommand.h"
21 #include "cmCMakePolicyCommand.h"
22 #include "cmCommand.h"
23 #include "cmConfigureFileCommand.h"
24 #include "cmContinueCommand.h"
25 #include "cmCreateTestSourceList.h"
26 #include "cmDefinePropertyCommand.h"
27 #include "cmEnableLanguageCommand.h"
28 #include "cmEnableTestingCommand.h"
29 #include "cmExecProgramCommand.h"
30 #include "cmExecuteProcessCommand.h"
31 #include "cmFileCommand.h"
32 #include "cmFindFileCommand.h"
33 #include "cmFindLibraryCommand.h"
34 #include "cmFindPackageCommand.h"
35 #include "cmFindPathCommand.h"
36 #include "cmFindProgramCommand.h"
37 #include "cmForEachCommand.h"
38 #include "cmFunctionCommand.h"
39 #include "cmGetCMakePropertyCommand.h"
40 #include "cmGetDirectoryPropertyCommand.h"
41 #include "cmGetFilenameComponentCommand.h"
42 #include "cmGetPropertyCommand.h"
43 #include "cmGetSourceFilePropertyCommand.h"
44 #include "cmGetTargetPropertyCommand.h"
45 #include "cmGetTestPropertyCommand.h"
46 #include "cmIfCommand.h"
47 #include "cmIncludeCommand.h"
48 #include "cmIncludeDirectoryCommand.h"
49 #include "cmIncludeGuardCommand.h"
50 #include "cmIncludeRegularExpressionCommand.h"
51 #include "cmInstallCommand.h"
52 #include "cmInstallFilesCommand.h"
53 #include "cmInstallTargetsCommand.h"
54 #include "cmLinkDirectoriesCommand.h"
55 #include "cmListCommand.h"
56 #include "cmMacroCommand.h"
57 #include "cmMakeDirectoryCommand.h"
58 #include "cmMarkAsAdvancedCommand.h"
59 #include "cmMathCommand.h"
60 #include "cmMessageCommand.h"
61 #include "cmOptionCommand.h"
62 #include "cmParseArgumentsCommand.h"
63 #include "cmPolicies.h"
64 #include "cmProjectCommand.h"
65 #include "cmReturnCommand.h"
66 #include "cmSeparateArgumentsCommand.h"
67 #include "cmSetCommand.h"
68 #include "cmSetDirectoryPropertiesCommand.h"
69 #include "cmSetPropertyCommand.h"
70 #include "cmSetSourceFilesPropertiesCommand.h"
71 #include "cmSetTargetPropertiesCommand.h"
72 #include "cmSetTestsPropertiesCommand.h"
73 #include "cmSiteNameCommand.h"
74 #include "cmState.h"
75 #include "cmStringCommand.h"
76 #include "cmSubdirCommand.h"
77 #include "cmTargetCompileDefinitionsCommand.h"
78 #include "cmTargetCompileFeaturesCommand.h"
79 #include "cmTargetCompileOptionsCommand.h"
80 #include "cmTargetIncludeDirectoriesCommand.h"
81 #include "cmTargetLinkLibrariesCommand.h"
82 #include "cmTargetLinkOptionsCommand.h"
83 #include "cmTargetPrecompileHeadersCommand.h"
84 #include "cmTargetSourcesCommand.h"
85 #include "cmTryCompileCommand.h"
86 #include "cmTryRunCommand.h"
87 #include "cmUnsetCommand.h"
88 #include "cmWhileCommand.h"
89
90 #if !defined(CMAKE_BOOTSTRAP)
91 #  include "cmAddCompileOptionsCommand.h"
92 #  include "cmAddLinkOptionsCommand.h"
93 #  include "cmAuxSourceDirectoryCommand.h"
94 #  include "cmBuildNameCommand.h"
95 #  include "cmCMakeHostSystemInformationCommand.h"
96 #  include "cmCMakeLanguageCommand.h"
97 #  include "cmExportCommand.h"
98 #  include "cmExportLibraryDependenciesCommand.h"
99 #  include "cmFLTKWrapUICommand.h"
100 #  include "cmIncludeExternalMSProjectCommand.h"
101 #  include "cmInstallProgramsCommand.h"
102 #  include "cmLinkLibrariesCommand.h"
103 #  include "cmLoadCacheCommand.h"
104 #  include "cmLoadCommandCommand.h"
105 #  include "cmOutputRequiredFilesCommand.h"
106 #  include "cmQTWrapCPPCommand.h"
107 #  include "cmQTWrapUICommand.h"
108 #  include "cmRemoveCommand.h"
109 #  include "cmRemoveDefinitionsCommand.h"
110 #  include "cmSourceGroupCommand.h"
111 #  include "cmSubdirDependsCommand.h"
112 #  include "cmTargetLinkDirectoriesCommand.h"
113 #  include "cmUseMangledMesaCommand.h"
114 #  include "cmUtilitySourceCommand.h"
115 #  include "cmVariableRequiresCommand.h"
116 #  include "cmVariableWatchCommand.h"
117 #  include "cmWriteFileCommand.h"
118 #endif
119
120 void GetScriptingCommands(cmState* state)
121 {
122   state->AddFlowControlCommand("break", cmBreakCommand);
123   state->AddFlowControlCommand("continue", cmContinueCommand);
124   state->AddFlowControlCommand("foreach", cmForEachCommand);
125   state->AddFlowControlCommand("function", cmFunctionCommand);
126   state->AddFlowControlCommand("if", cmIfCommand);
127   state->AddFlowControlCommand("macro", cmMacroCommand);
128   state->AddFlowControlCommand("return", cmReturnCommand);
129   state->AddFlowControlCommand("while", cmWhileCommand);
130
131   state->AddBuiltinCommand("cmake_minimum_required", cmCMakeMinimumRequired);
132   state->AddBuiltinCommand("cmake_path", cmCMakePathCommand);
133   state->AddBuiltinCommand("cmake_policy", cmCMakePolicyCommand);
134   state->AddBuiltinCommand("configure_file", cmConfigureFileCommand);
135   state->AddBuiltinCommand("exec_program", cmExecProgramCommand);
136   state->AddBuiltinCommand("execute_process", cmExecuteProcessCommand);
137   state->AddBuiltinCommand("file", cmFileCommand);
138   state->AddBuiltinCommand("find_file", cmFindFile);
139   state->AddBuiltinCommand("find_library", cmFindLibrary);
140   state->AddBuiltinCommand("find_package", cmFindPackage);
141   state->AddBuiltinCommand("find_path", cmFindPath);
142   state->AddBuiltinCommand("find_program", cmFindProgram);
143   state->AddBuiltinCommand("get_cmake_property", cmGetCMakePropertyCommand);
144   state->AddBuiltinCommand("get_directory_property",
145                            cmGetDirectoryPropertyCommand);
146   state->AddBuiltinCommand("get_filename_component",
147                            cmGetFilenameComponentCommand);
148   state->AddBuiltinCommand("get_property", cmGetPropertyCommand);
149   state->AddBuiltinCommand("include", cmIncludeCommand);
150   state->AddBuiltinCommand("include_guard", cmIncludeGuardCommand);
151   state->AddBuiltinCommand("list", cmListCommand);
152   state->AddBuiltinCommand("make_directory", cmMakeDirectoryCommand);
153   state->AddBuiltinCommand("mark_as_advanced", cmMarkAsAdvancedCommand);
154   state->AddBuiltinCommand("math", cmMathCommand);
155   state->AddBuiltinCommand("message", cmMessageCommand);
156   state->AddBuiltinCommand("option", cmOptionCommand);
157   state->AddBuiltinCommand("cmake_parse_arguments", cmParseArgumentsCommand);
158   state->AddBuiltinCommand("separate_arguments", cmSeparateArgumentsCommand);
159   state->AddBuiltinCommand("set", cmSetCommand);
160   state->AddBuiltinCommand("set_directory_properties",
161                            cmSetDirectoryPropertiesCommand);
162   state->AddBuiltinCommand("set_property", cmSetPropertyCommand);
163   state->AddBuiltinCommand("site_name", cmSiteNameCommand);
164   state->AddBuiltinCommand("string", cmStringCommand);
165   state->AddBuiltinCommand("unset", cmUnsetCommand);
166
167   state->AddUnexpectedFlowControlCommand(
168     "else",
169     "An ELSE command was found outside of a proper "
170     "IF ENDIF structure. Or its arguments did not match "
171     "the opening IF command.");
172   state->AddUnexpectedFlowControlCommand(
173     "elseif",
174     "An ELSEIF command was found outside of a proper "
175     "IF ENDIF structure.");
176   state->AddUnexpectedFlowControlCommand(
177     "endforeach",
178     "An ENDFOREACH command was found outside of a proper "
179     "FOREACH ENDFOREACH structure. Or its arguments did "
180     "not match the opening FOREACH command.");
181   state->AddUnexpectedFlowControlCommand(
182     "endfunction",
183     "An ENDFUNCTION command was found outside of a proper "
184     "FUNCTION ENDFUNCTION structure. Or its arguments did not "
185     "match the opening FUNCTION command.");
186   state->AddUnexpectedFlowControlCommand(
187     "endif",
188     "An ENDIF command was found outside of a proper "
189     "IF ENDIF structure. Or its arguments did not match "
190     "the opening IF command.");
191   state->AddUnexpectedFlowControlCommand(
192     "endmacro",
193     "An ENDMACRO command was found outside of a proper "
194     "MACRO ENDMACRO structure. Or its arguments did not "
195     "match the opening MACRO command.");
196   state->AddUnexpectedFlowControlCommand(
197     "endwhile",
198     "An ENDWHILE command was found outside of a proper "
199     "WHILE ENDWHILE structure. Or its arguments did not "
200     "match the opening WHILE command.");
201
202 #if !defined(CMAKE_BOOTSTRAP)
203   state->AddBuiltinCommand("cmake_host_system_information",
204                            cmCMakeHostSystemInformationCommand);
205   state->AddBuiltinCommand("cmake_language", cmCMakeLanguageCommand);
206   state->AddBuiltinCommand("load_cache", cmLoadCacheCommand);
207   state->AddBuiltinCommand("remove", cmRemoveCommand);
208   state->AddBuiltinCommand("variable_watch", cmVariableWatchCommand);
209   state->AddBuiltinCommand("write_file", cmWriteFileCommand);
210
211   state->AddDisallowedCommand(
212     "build_name", cmBuildNameCommand, cmPolicies::CMP0036,
213     "The build_name command should not be called; see CMP0036.");
214   state->AddDisallowedCommand(
215     "use_mangled_mesa", cmUseMangledMesaCommand, cmPolicies::CMP0030,
216     "The use_mangled_mesa command should not be called; see CMP0030.");
217
218 #endif
219 }
220
221 void GetProjectCommands(cmState* state)
222 {
223   state->AddBuiltinCommand("add_custom_command", cmAddCustomCommandCommand);
224   state->AddBuiltinCommand("add_custom_target", cmAddCustomTargetCommand);
225   state->AddBuiltinCommand("add_definitions", cmAddDefinitionsCommand);
226   state->AddBuiltinCommand("add_dependencies", cmAddDependenciesCommand);
227   state->AddBuiltinCommand("add_executable", cmAddExecutableCommand);
228   state->AddBuiltinCommand("add_library", cmAddLibraryCommand);
229   state->AddBuiltinCommand("add_subdirectory", cmAddSubDirectoryCommand);
230   state->AddBuiltinCommand("add_test", cmAddTestCommand);
231   state->AddBuiltinCommand("build_command", cmBuildCommand);
232   state->AddBuiltinCommand("create_test_sourcelist", cmCreateTestSourceList);
233   state->AddBuiltinCommand("define_property", cmDefinePropertyCommand);
234   state->AddBuiltinCommand("enable_language", cmEnableLanguageCommand);
235   state->AddBuiltinCommand("enable_testing", cmEnableTestingCommand);
236   state->AddBuiltinCommand("get_source_file_property",
237                            cmGetSourceFilePropertyCommand);
238   state->AddBuiltinCommand("get_target_property", cmGetTargetPropertyCommand);
239   state->AddBuiltinCommand("get_test_property", cmGetTestPropertyCommand);
240   state->AddBuiltinCommand("include_directories", cmIncludeDirectoryCommand);
241   state->AddBuiltinCommand("include_regular_expression",
242                            cmIncludeRegularExpressionCommand);
243   state->AddBuiltinCommand("install", cmInstallCommand);
244   state->AddBuiltinCommand("install_files", cmInstallFilesCommand);
245   state->AddBuiltinCommand("install_targets", cmInstallTargetsCommand);
246   state->AddBuiltinCommand("link_directories", cmLinkDirectoriesCommand);
247   state->AddBuiltinCommand("project", cmProjectCommand);
248   state->AddBuiltinCommand("set_source_files_properties",
249                            cmSetSourceFilesPropertiesCommand);
250   state->AddBuiltinCommand("set_target_properties",
251                            cmSetTargetPropertiesCommand);
252   state->AddBuiltinCommand("set_tests_properties",
253                            cmSetTestsPropertiesCommand);
254   state->AddBuiltinCommand("subdirs", cmSubdirCommand);
255   state->AddBuiltinCommand("target_compile_definitions",
256                            cmTargetCompileDefinitionsCommand);
257   state->AddBuiltinCommand("target_compile_features",
258                            cmTargetCompileFeaturesCommand);
259   state->AddBuiltinCommand("target_compile_options",
260                            cmTargetCompileOptionsCommand);
261   state->AddBuiltinCommand("target_include_directories",
262                            cmTargetIncludeDirectoriesCommand);
263   state->AddBuiltinCommand("target_link_libraries",
264                            cmTargetLinkLibrariesCommand);
265   state->AddBuiltinCommand("target_link_options", cmTargetLinkOptionsCommand);
266   state->AddBuiltinCommand("target_sources", cmTargetSourcesCommand);
267   state->AddBuiltinCommand("try_compile",
268                            cm::make_unique<cmTryCompileCommand>());
269   state->AddBuiltinCommand("try_run", cm::make_unique<cmTryRunCommand>());
270   state->AddBuiltinCommand("target_precompile_headers",
271                            cmTargetPrecompileHeadersCommand);
272
273 #if !defined(CMAKE_BOOTSTRAP)
274   state->AddBuiltinCommand("add_compile_definitions",
275                            cmAddCompileDefinitionsCommand);
276   state->AddBuiltinCommand("add_compile_options", cmAddCompileOptionsCommand);
277   state->AddBuiltinCommand("aux_source_directory",
278                            cmAuxSourceDirectoryCommand);
279   state->AddBuiltinCommand("export", cmExportCommand);
280   state->AddBuiltinCommand("fltk_wrap_ui", cmFLTKWrapUICommand);
281   state->AddBuiltinCommand("include_external_msproject",
282                            cmIncludeExternalMSProjectCommand);
283   state->AddBuiltinCommand("install_programs", cmInstallProgramsCommand);
284   state->AddBuiltinCommand("add_link_options", cmAddLinkOptionsCommand);
285   state->AddBuiltinCommand("link_libraries", cmLinkLibrariesCommand);
286   state->AddBuiltinCommand("target_link_directories",
287                            cmTargetLinkDirectoriesCommand);
288   state->AddBuiltinCommand("qt_wrap_cpp", cmQTWrapCPPCommand);
289   state->AddBuiltinCommand("qt_wrap_ui", cmQTWrapUICommand);
290   state->AddBuiltinCommand("remove_definitions", cmRemoveDefinitionsCommand);
291   state->AddBuiltinCommand("source_group", cmSourceGroupCommand);
292
293   state->AddDisallowedCommand(
294     "export_library_dependencies", cmExportLibraryDependenciesCommand,
295     cmPolicies::CMP0033,
296     "The export_library_dependencies command should not be called; "
297     "see CMP0033.");
298   state->AddDisallowedCommand(
299     "load_command", cmLoadCommandCommand, cmPolicies::CMP0031,
300     "The load_command command should not be called; see CMP0031.");
301   state->AddDisallowedCommand(
302     "output_required_files", cmOutputRequiredFilesCommand, cmPolicies::CMP0032,
303     "The output_required_files command should not be called; see CMP0032.");
304   state->AddDisallowedCommand(
305     "subdir_depends", cmSubdirDependsCommand, cmPolicies::CMP0029,
306     "The subdir_depends command should not be called; see CMP0029.");
307   state->AddDisallowedCommand(
308     "utility_source", cmUtilitySourceCommand, cmPolicies::CMP0034,
309     "The utility_source command should not be called; see CMP0034.");
310   state->AddDisallowedCommand(
311     "variable_requires", cmVariableRequiresCommand, cmPolicies::CMP0035,
312     "The variable_requires command should not be called; see CMP0035.");
313 #endif
314 }
315
316 void GetProjectCommandsInScriptMode(cmState* state)
317 {
318 #define CM_UNEXPECTED_PROJECT_COMMAND(NAME)                                   \
319   state->AddUnexpectedCommand(NAME, "command is not scriptable")
320
321   CM_UNEXPECTED_PROJECT_COMMAND("add_compile_options");
322   CM_UNEXPECTED_PROJECT_COMMAND("add_custom_command");
323   CM_UNEXPECTED_PROJECT_COMMAND("add_custom_target");
324   CM_UNEXPECTED_PROJECT_COMMAND("add_definitions");
325   CM_UNEXPECTED_PROJECT_COMMAND("add_dependencies");
326   CM_UNEXPECTED_PROJECT_COMMAND("add_executable");
327   CM_UNEXPECTED_PROJECT_COMMAND("add_library");
328   CM_UNEXPECTED_PROJECT_COMMAND("add_subdirectory");
329   CM_UNEXPECTED_PROJECT_COMMAND("add_test");
330   CM_UNEXPECTED_PROJECT_COMMAND("aux_source_directory");
331   CM_UNEXPECTED_PROJECT_COMMAND("build_command");
332   CM_UNEXPECTED_PROJECT_COMMAND("create_test_sourcelist");
333   CM_UNEXPECTED_PROJECT_COMMAND("define_property");
334   CM_UNEXPECTED_PROJECT_COMMAND("enable_language");
335   CM_UNEXPECTED_PROJECT_COMMAND("enable_testing");
336   CM_UNEXPECTED_PROJECT_COMMAND("export");
337   CM_UNEXPECTED_PROJECT_COMMAND("fltk_wrap_ui");
338   CM_UNEXPECTED_PROJECT_COMMAND("get_source_file_property");
339   CM_UNEXPECTED_PROJECT_COMMAND("get_target_property");
340   CM_UNEXPECTED_PROJECT_COMMAND("get_test_property");
341   CM_UNEXPECTED_PROJECT_COMMAND("include_directories");
342   CM_UNEXPECTED_PROJECT_COMMAND("include_external_msproject");
343   CM_UNEXPECTED_PROJECT_COMMAND("include_regular_expression");
344   CM_UNEXPECTED_PROJECT_COMMAND("install");
345   CM_UNEXPECTED_PROJECT_COMMAND("link_directories");
346   CM_UNEXPECTED_PROJECT_COMMAND("link_libraries");
347   CM_UNEXPECTED_PROJECT_COMMAND("project");
348   CM_UNEXPECTED_PROJECT_COMMAND("qt_wrap_cpp");
349   CM_UNEXPECTED_PROJECT_COMMAND("qt_wrap_ui");
350   CM_UNEXPECTED_PROJECT_COMMAND("remove_definitions");
351   CM_UNEXPECTED_PROJECT_COMMAND("set_source_files_properties");
352   CM_UNEXPECTED_PROJECT_COMMAND("set_target_properties");
353   CM_UNEXPECTED_PROJECT_COMMAND("set_tests_properties");
354   CM_UNEXPECTED_PROJECT_COMMAND("source_group");
355   CM_UNEXPECTED_PROJECT_COMMAND("target_compile_definitions");
356   CM_UNEXPECTED_PROJECT_COMMAND("target_compile_features");
357   CM_UNEXPECTED_PROJECT_COMMAND("target_compile_options");
358   CM_UNEXPECTED_PROJECT_COMMAND("target_include_directories");
359   CM_UNEXPECTED_PROJECT_COMMAND("target_link_libraries");
360   CM_UNEXPECTED_PROJECT_COMMAND("target_sources");
361   CM_UNEXPECTED_PROJECT_COMMAND("try_compile");
362   CM_UNEXPECTED_PROJECT_COMMAND("try_run");
363
364   // deprecated commands
365   CM_UNEXPECTED_PROJECT_COMMAND("export_library_dependencies");
366   CM_UNEXPECTED_PROJECT_COMMAND("load_command");
367   CM_UNEXPECTED_PROJECT_COMMAND("output_required_files");
368   CM_UNEXPECTED_PROJECT_COMMAND("subdir_depends");
369   CM_UNEXPECTED_PROJECT_COMMAND("utility_source");
370   CM_UNEXPECTED_PROJECT_COMMAND("variable_requires");
371
372 #undef CM_UNEXPECTED_PROJECT_COMMAND
373 }