cmCommands.cxx 17 KB

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