cmCommands.cxx 17 KB

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