cmCommands.cxx 17 KB

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