cmCommands.cxx 17 KB

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