diff --git a/Help/command/add_compile_definitions.rst b/Help/command/add_compile_definitions.rst index 04cb4c23cb..aaff3629e5 100644 --- a/Help/command/add_compile_definitions.rst +++ b/Help/command/add_compile_definitions.rst @@ -27,7 +27,5 @@ language syntax may require escapes to specify some values). .. |command_name| replace:: ``add_compile_definitions`` .. include:: include/GENEX_NOTE.rst -See Also -^^^^^^^^ - -* The command :command:`target_compile_definitions` adds target-specific definitions. +.. |target_command_name| replace:: :command:`target_compile_definitions` +.. include:: include/NON_TARGET_NOTE.rst diff --git a/Help/command/add_compile_options.rst b/Help/command/add_compile_options.rst index 3f7ab6c0ec..429dcd4d71 100644 --- a/Help/command/add_compile_options.rst +++ b/Help/command/add_compile_options.rst @@ -16,6 +16,9 @@ directory and below. These options are not used when linking. See the :command:`add_link_options` command for that. +.. |target_command_name| replace:: :command:`target_compile_options` +.. include:: include/NON_TARGET_NOTE.rst + Arguments ^^^^^^^^^ diff --git a/Help/command/add_definitions.rst b/Help/command/add_definitions.rst index 5c1f7b43bd..4c5149cafa 100644 --- a/Help/command/add_definitions.rst +++ b/Help/command/add_definitions.rst @@ -16,9 +16,15 @@ flags, but it is intended to add preprocessor definitions. This command has been superseded by alternatives: - * Use :command:`add_compile_definitions` to add preprocessor definitions. - * Use :command:`include_directories` to add include directories. - * Use :command:`add_compile_options` to add other options. + * Use :command:`add_compile_definitions` + or :command:`target_compile_definitions` + to add preprocessor definitions. + * Use :command:`add_compile_options` + or :command:`target_compile_options` + to add other options. + * Use :command:`include_directories` + or :command:`target_include_directories` + to add include directories. Flags beginning in ``-D`` or ``/D`` that look like preprocessor definitions are automatically added to the :prop_dir:`COMPILE_DEFINITIONS` directory diff --git a/Help/command/add_link_options.rst b/Help/command/add_link_options.rst index 462fee9985..98abb7e9fd 100644 --- a/Help/command/add_link_options.rst +++ b/Help/command/add_link_options.rst @@ -26,6 +26,9 @@ exist to add libraries (:command:`target_link_libraries` or .. |command_name| replace:: ``add_link_options`` .. include:: include/GENEX_NOTE.rst +.. |target_command_name| replace:: :command:`target_link_options` +.. include:: include/NON_TARGET_NOTE.rst + .. include:: include/DEVICE_LINK_OPTIONS.rst .. include:: include/OPTIONS_SHELL.rst diff --git a/Help/command/include/NON_TARGET_NOTE.rst b/Help/command/include/NON_TARGET_NOTE.rst new file mode 100644 index 0000000000..7162789b9c --- /dev/null +++ b/Help/command/include/NON_TARGET_NOTE.rst @@ -0,0 +1,2 @@ +.. note:: + .. include:: include/NON_TARGET_NOTE_BODY.rst diff --git a/Help/command/include/NON_TARGET_NOTE_BODY.rst b/Help/command/include/NON_TARGET_NOTE_BODY.rst new file mode 100644 index 0000000000..535f2ca667 --- /dev/null +++ b/Help/command/include/NON_TARGET_NOTE_BODY.rst @@ -0,0 +1,6 @@ +Use of the |command_name| command for new development is discouraged. +Unencapsulated alterations to the build environment can have unintentionally +broad effect, potentially resulting in unnecessary build dependencies. +Additionally, the |command_name| command cannot be used to express interface +usage requirements. It is recommended that new development use the +|target_command_name| command instead. diff --git a/Help/command/include_directories.rst b/Help/command/include_directories.rst index dcb5620929..ae1d6afbc4 100644 --- a/Help/command/include_directories.rst +++ b/Help/command/include_directories.rst @@ -32,11 +32,8 @@ considered in dependency calculations - see compiler docs. .. |command_name| replace:: ``include_directories`` .. include:: include/GENEX_NOTE.rst -.. note:: - - Prefer the :command:`target_include_directories` command to add include - directories to individual targets and optionally propagate/export them - to dependents. +.. |target_command_name| replace:: :command:`target_include_directories` +.. include:: include/NON_TARGET_NOTE.rst See Also ^^^^^^^^ diff --git a/Help/command/link_libraries.rst b/Help/command/link_libraries.rst index 8665cb7892..e285a7e7ae 100644 --- a/Help/command/link_libraries.rst +++ b/Help/command/link_libraries.rst @@ -13,7 +13,10 @@ the current directory or below by commands such as :command:`add_executable` or :command:`add_library`. See the :command:`target_link_libraries` command for meaning of arguments. +.. |command_name| replace:: ``link_libraries`` +.. |target_command_name| replace:: :command:`target_link_libraries` .. note:: - The :command:`target_link_libraries` command should be preferred whenever - possible. Library dependencies are chained automatically, so directory-wide + .. include:: include/NON_TARGET_NOTE_BODY.rst + + Library dependencies are chained automatically, so directory-wide specification of link libraries is rarely needed. diff --git a/Help/diagnostic/CMD_INSTALL_ABSOLUTE_DESTINATION.rst b/Help/diagnostic/CMD_INSTALL_ABSOLUTE_DESTINATION.rst index e414f38245..2e540280d4 100644 --- a/Help/diagnostic/CMD_INSTALL_ABSOLUTE_DESTINATION.rst +++ b/Help/diagnostic/CMD_INSTALL_ABSOLUTE_DESTINATION.rst @@ -5,7 +5,7 @@ CMD_INSTALL_ABSOLUTE_DESTINATION .. diagnostic:: :default: ignore - :parent: CMD_AUTHOR + :parent: CMD_STRICT Warn when an :command:`install` command specifies an absolute ``DESTINATION`` path. Absolute destinations are typically undesirable because they prevent diff --git a/Help/diagnostic/CMD_NON_TARGET_DIRECTIVE.rst b/Help/diagnostic/CMD_NON_TARGET_DIRECTIVE.rst new file mode 100644 index 0000000000..316b567664 --- /dev/null +++ b/Help/diagnostic/CMD_NON_TARGET_DIRECTIVE.rst @@ -0,0 +1,15 @@ +CMD_NON_TARGET_DIRECTIVE +------------------------ + +.. versionadded:: 4.5 + +.. diagnostic:: + :default: ignore + :parent: CMD_STRICT + + Warn about use of non-target directives which alter the build environment. + Unencapsulated alterations to the build environment can have unintentionally + broad effect, potentially resulting in unnecessary build dependencies. + Additionally, such commands cannot be used to express interface usage + requirements. It is recommended that new development use target-specific + commands instead. diff --git a/Help/diagnostic/CMD_STRICT.rst b/Help/diagnostic/CMD_STRICT.rst new file mode 100644 index 0000000000..f19af78e81 --- /dev/null +++ b/Help/diagnostic/CMD_STRICT.rst @@ -0,0 +1,14 @@ +CMD_STRICT +---------- + +.. versionadded:: 4.5 + +.. diagnostic:: + :default: ignore + :parent: CMD_AUTHOR + + Control diagnostics related to allowed but disrecommended usage. This is + the parent of the following diagnostics: + + * :diagnostic:`CMD_INSTALL_ABSOLUTE_DESTINATION` + * :diagnostic:`CMD_NON_TARGET_DIRECTIVE` diff --git a/Help/manual/cmake-diagnostics.7.rst b/Help/manual/cmake-diagnostics.7.rst index cafc50d2a1..d87a5f8177 100644 --- a/Help/manual/cmake-diagnostics.7.rst +++ b/Help/manual/cmake-diagnostics.7.rst @@ -90,6 +90,8 @@ The following categories are defined: /diagnostic/CMD_DEPRECATED /diagnostic/CMD_EXPERIMENTAL /diagnostic/CMD_INSTALL_ABSOLUTE_DESTINATION + /diagnostic/CMD_NON_TARGET_DIRECTIVE /diagnostic/CMD_POLICY + /diagnostic/CMD_STRICT /diagnostic/CMD_UNINITIALIZED /diagnostic/CMD_UNUSED_CLI diff --git a/Help/manual/cmake-presets.7.rst b/Help/manual/cmake-presets.7.rst index 732287c113..d760c70471 100644 --- a/Help/manual/cmake-presets.7.rst +++ b/Help/manual/cmake-presets.7.rst @@ -487,7 +487,8 @@ they were added and a summary of the new features and changes is given below. :preset:`configurePresets.errors`. * The ``installAbsoluteDestination`` field was added to - :preset:`configurePresets.warnings` and :preset:`configurePresets.errors`. + :preset:`configurePresets.warnings` and + :preset:`configurePresets.errors`. * Changes to `Macro Expansion`_ @@ -501,6 +502,15 @@ they were added and a summary of the new features and changes is given below. * The :preset:`testPresets.execution.testPassthroughArguments` field was added to forward arguments to test executables. + ``13`` + .. versionadded:: 4.5 + + * Changes to `Configure Presets `_: + + * The ``strict`` and ``nonTargetDirective`` fields were added to + :preset:`configurePresets.warnings` and + :preset:`configurePresets.errors`. + Schema ====== diff --git a/Help/manual/presets/errors-properties.rst b/Help/manual/presets/errors-properties.rst index 00b65a09ff..494ff6e385 100644 --- a/Help/manual/presets/errors-properties.rst +++ b/Help/manual/presets/errors-properties.rst @@ -50,6 +50,15 @@ :cmake-option:`-Wno-error=install-absolute-destination` on the command line. This may not be set to ``true`` if ``warnings.installAbsoluteDestination`` is set to ``false``. +.. _`CMakePresets.configurePresets.errors.nonTargetDirective`: + +``nonTargetDirective`` + .. presets-versionadded:: 13 + + An optional boolean. Equivalent to passing :cmake-option:`-Werror=non-target-directive` or + :cmake-option:`-Wno-error=non-target-directive` on the command line. + This may not be set to ``true`` if ``warnings.nonTargetDirective`` is set to ``false``. + .. _`CMakePresets.configurePresets.errors.policy`: ``policy`` @@ -59,6 +68,15 @@ :cmake-option:`-Wno-error=policy` on the command line. This may not be set to ``true`` if ``warnings.policy`` is set to ``false``. +.. _`CMakePresets.configurePresets.errors.strict`: + +``strict`` + .. presets-versionadded:: 13 + + An optional boolean. Equivalent to passing :cmake-option:`-Werror=strict` or + :cmake-option:`-Wno-error=strict` on the command line. + This may not be set to ``true`` if ``warnings.strict`` is set to ``false``. + .. _`CMakePresets.configurePresets.errors.uninitialized`: ``uninitialized`` diff --git a/Help/manual/presets/schema.json b/Help/manual/presets/schema.json index ff30429d0d..34a51d3272 100644 --- a/Help/manual/presets/schema.json +++ b/Help/manual/presets/schema.json @@ -420,7 +420,51 @@ "$ref": "#/definitions/buildPresets@v10.." }, "testPresets": { - "$ref": "#/definitions/testPresets@v12" + "$ref": "#/definitions/testPresets@v12.." + }, + "packagePresets": { + "$ref": "#/definitions/packagePresets@v10.." + }, + "workflowPresets": { + "$ref": "#/definitions/workflowPresets@v10.." + }, + "$comment": { + "$ref": "#/definitions/$comment@v10.." + } + }, + "required": [ + "version" + ], + "additionalProperties": false + }, + { + "description": "The presets specify the generator and the build directory, and optionally an array of variables and other arguments to pass to CMake.", + "properties": { + "$schema": { + "$ref": "#/definitions/$schema@v8.." + }, + "version": { + "type": "integer", + "description": "A required integer representing the version of the JSON schema.", + "const": 13 + }, + "cmakeMinimumRequired": { + "$ref": "#/definitions/cmakeMinimumRequired@v10.." + }, + "include": { + "$ref": "#/definitions/include@v4.." + }, + "vendor": { + "$ref": "#/definitions/vendor@v1.." + }, + "configurePresets": { + "$ref": "#/definitions/configurePresets@v13" + }, + "buildPresets": { + "$ref": "#/definitions/buildPresets@v10.." + }, + "testPresets": { + "$ref": "#/definitions/testPresets@v12.." }, "packagePresets": { "$ref": "#/definitions/packagePresets@v10.." @@ -893,6 +937,86 @@ ] } }, + "configurePresets@v13": { + "type": "array", + "description": "An optional array of configure preset objects.", + "items": { + "type": "object", + "description": "A configure preset object.", + "unevaluatedProperties": false, + "properties": { + "name": { + "$ref": "#/definitions/configurePresets.name@v1.." + }, + "hidden": { + "$ref": "#/definitions/configurePresets.hidden@v1.." + }, + "inherits": { + "$ref": "#/definitions/configurePresets.inherits@v1.." + }, + "condition": { + "$ref": "#/definitions/configurePresets.condition@v10.." + }, + "vendor": { + "$ref": "#/definitions/configurePresets.vendor@v1.." + }, + "displayName": { + "$ref": "#/definitions/configurePresets.displayName@v1.." + }, + "description": { + "$ref": "#/definitions/configurePresets.description@v1.." + }, + "generator": { + "$ref": "#/definitions/configurePresets.generator@v3.." + }, + "architecture": { + "$ref": "#/definitions/configurePresets.architecture@v10.." + }, + "toolset": { + "$ref": "#/definitions/configurePresets.toolset@v10.." + }, + "toolchainFile": { + "$ref": "#/definitions/configurePresets.toolchainFile@v3.." + }, + "graphviz": { + "$ref": "#/definitions/configurePresets.graphviz@v10.." + }, + "binaryDir": { + "$ref": "#/definitions/configurePresets.binaryDir@v3.." + }, + "installDir": { + "$ref": "#/definitions/configurePresets.installDir@v3.." + }, + "cmakeExecutable": { + "$ref": "#/definitions/configurePresets.cmakeExecutable@v1.." + }, + "cacheVariables": { + "$ref": "#/definitions/configurePresets.cacheVariables@v10.." + }, + "environment": { + "$ref": "#/definitions/configurePresets.environment@v1.." + }, + "warnings": { + "$ref": "#/definitions/configurePresets.warnings@v13" + }, + "errors": { + "$ref": "#/definitions/configurePresets.errors@v13" + }, + "debug": { + "$ref": "#/definitions/configurePresets.debug@v10.." + }, + "trace": { + "$ref": "#/definitions/configurePresets.trace@v10.." + }, + "$comment": { + "$ref": "#/definitions/$comment@v10.." + } + }, + "required": [ + "name" + ] + } + }, "configurePresets.name@v1..": { "type": "string", "minLength": 1, @@ -1281,19 +1405,19 @@ "unevaluatedProperties": false, "properties": { "author": { - "$ref": "#/definitions/configurePresets.warnings.author@v12" + "$ref": "#/definitions/configurePresets.warnings.author@v12.." }, "deprecated": { "$ref": "#/definitions/configurePresets.warnings.deprecated@v1.." }, "experimental": { - "$ref": "#/definitions/configurePresets.warnings.experimental@v12" + "$ref": "#/definitions/configurePresets.warnings.experimental@v12.." }, "installAbsoluteDestination": { - "$ref": "#/definitions/configurePresets.warnings.installAbsoluteDestination@v12" + "$ref": "#/definitions/configurePresets.warnings.installAbsoluteDestination@v12.." }, "policy": { - "$ref": "#/definitions/configurePresets.warnings.policy@v12" + "$ref": "#/definitions/configurePresets.warnings.policy@v12.." }, "uninitialized": { "$ref": "#/definitions/configurePresets.warnings.uninitialized@v1.." @@ -1309,7 +1433,47 @@ } } }, - "configurePresets.warnings.author@v12": { + "configurePresets.warnings@v13": { + "type": "object", + "description": "An optional object specifying the warnings to enable.", + "unevaluatedProperties": false, + "properties": { + "author": { + "$ref": "#/definitions/configurePresets.warnings.author@v12.." + }, + "deprecated": { + "$ref": "#/definitions/configurePresets.warnings.deprecated@v1.." + }, + "experimental": { + "$ref": "#/definitions/configurePresets.warnings.experimental@v12.." + }, + "installAbsoluteDestination": { + "$ref": "#/definitions/configurePresets.warnings.installAbsoluteDestination@v12.." + }, + "nonTargetDirective": { + "$ref": "#/definitions/configurePresets.warnings.nonTargetDirective@v13" + }, + "policy": { + "$ref": "#/definitions/configurePresets.warnings.policy@v12.." + }, + "strict": { + "$ref": "#/definitions/configurePresets.warnings.strict@v13" + }, + "uninitialized": { + "$ref": "#/definitions/configurePresets.warnings.uninitialized@v1.." + }, + "unusedCli": { + "$ref": "#/definitions/configurePresets.warnings.unusedCli@v1.." + }, + "systemVars": { + "$ref": "#/definitions/configurePresets.warnings.systemVars@v1.." + }, + "$comment": { + "$ref": "#/definitions/$comment@v10.." + } + } + }, + "configurePresets.warnings.author@v12..": { "type": "boolean", "description": "An optional boolean. Equivalent to passing -Wauthor or -Wno-author on the command line. This may not be set to false if errors.author is set to true." }, @@ -1321,18 +1485,26 @@ "type": "boolean", "description": "An optional boolean. Equivalent to passing -Wdev or -Wno-dev on the command line. This may not be set to false if errors.dev is set to true." }, - "configurePresets.warnings.experimental@v12": { + "configurePresets.warnings.experimental@v12..": { "type": "boolean", "description": "An optional boolean. Equivalent to passing -Wexperimental or -Wno-experimental on the command line. This may not be set to false if errors.experimental is set to true." }, - "configurePresets.warnings.installAbsoluteDestination@v12": { + "configurePresets.warnings.installAbsoluteDestination@v12..": { "type": "boolean", "description": "An optional boolean. Equivalent to passing -Winstall-absolute-destination or -Wno-install-absolute-destination on the command line. This may not be set to false if errors.installAbsoluteDestination is set to true." }, - "configurePresets.warnings.policy@v12": { + "configurePresets.warnings.nonTargetDirective@v13": { + "type": "boolean", + "description": "An optional boolean. Equivalent to passing -Wnon-target-directive or -Wno-non-target-directive on the command line. This may not be set to false if errors.nonTargetDirective is set to true." + }, + "configurePresets.warnings.policy@v12..": { "type": "boolean", "description": "An optional boolean. Equivalent to passing -Wpolicy or -Wno-policy on the command line. This may not be set to false if errors.policy is set to true." }, + "configurePresets.warnings.strict@v13": { + "type": "boolean", + "description": "An optional boolean. Equivalent to passing -Wstrict or -Wno-strict on the command line. This may not be set to false if errors.strict is set to true." + }, "configurePresets.warnings.uninitialized@v1..": { "type": "boolean", "description": "An optional boolean. Equivalent to passing -Wuninitialized or -Wno-uninitialized on the command line. This may not be set to false if errors.uninitialized is set to true." @@ -1380,32 +1552,69 @@ "unevaluatedProperties": false, "properties": { "author": { - "$ref": "#/definitions/configurePresets.errors.author@v12" + "$ref": "#/definitions/configurePresets.errors.author@v12.." }, "deprecated": { "$ref": "#/definitions/configurePresets.errors.deprecated@v1.." }, "experimental": { - "$ref": "#/definitions/configurePresets.errors.experimental@v12" + "$ref": "#/definitions/configurePresets.errors.experimental@v12.." }, "installAbsoluteDestination": { - "$ref": "#/definitions/configurePresets.errors.installAbsoluteDestination@v12" + "$ref": "#/definitions/configurePresets.errors.installAbsoluteDestination@v12.." }, "policy": { - "$ref": "#/definitions/configurePresets.errors.policy@v12" + "$ref": "#/definitions/configurePresets.errors.policy@v12.." }, "uninitialized": { - "$ref": "#/definitions/configurePresets.errors.uninitialized@v12" + "$ref": "#/definitions/configurePresets.errors.uninitialized@v12.." }, "unusedCli": { - "$ref": "#/definitions/configurePresets.errors.unusedCli@v12" + "$ref": "#/definitions/configurePresets.errors.unusedCli@v12.." }, "$comment": { "$ref": "#/definitions/$comment@v10.." } } }, - "configurePresets.errors.author@v12": { + "configurePresets.errors@v13": { + "type": "object", + "description": "An optional object specifying the errors to enable.", + "unevaluatedProperties": false, + "properties": { + "author": { + "$ref": "#/definitions/configurePresets.errors.author@v12.." + }, + "deprecated": { + "$ref": "#/definitions/configurePresets.errors.deprecated@v1.." + }, + "experimental": { + "$ref": "#/definitions/configurePresets.errors.experimental@v12.." + }, + "installAbsoluteDestination": { + "$ref": "#/definitions/configurePresets.errors.installAbsoluteDestination@v12.." + }, + "nonTargetDirective": { + "$ref": "#/definitions/configurePresets.errors.nonTargetDirective@v13" + }, + "policy": { + "$ref": "#/definitions/configurePresets.errors.policy@v12.." + }, + "strict": { + "$ref": "#/definitions/configurePresets.errors.strict@v13" + }, + "uninitialized": { + "$ref": "#/definitions/configurePresets.errors.uninitialized@v12.." + }, + "unusedCli": { + "$ref": "#/definitions/configurePresets.errors.unusedCli@v12.." + }, + "$comment": { + "$ref": "#/definitions/$comment@v10.." + } + } + }, + "configurePresets.errors.author@v12..": { "type": "boolean", "description": "An optional boolean. Equivalent to passing -Werror=author or -Wno-error=author on the command line. This may not be set to true if warnings.author is set to false." }, @@ -1417,23 +1626,31 @@ "type": "boolean", "description": "An optional boolean. Equivalent to passing -Werror=dev or -Wno-error=dev on the command line. This may not be set to true if warnings.dev is set to false." }, - "configurePresets.errors.experimental@v12": { + "configurePresets.errors.experimental@v12..": { "type": "boolean", "description": "An optional boolean. Equivalent to passing -Werror=experimental or -Wno-error=experimental on the command line. This may not be set to true if warnings.experimental is set to false." }, - "configurePresets.errors.installAbsoluteDestination@v12": { + "configurePresets.errors.installAbsoluteDestination@v12..": { "type": "boolean", "description": "An optional boolean. Equivalent to passing -Werror=install-absolute-destination or -Wno-error=install-absolute-destination on the command line. This may not be set to true if warnings.installAbsoluteDestination is set to false." }, - "configurePresets.errors.policy@v12": { + "configurePresets.errors.nonTargetDirective@v13": { + "type": "boolean", + "description": "An optional boolean. Equivalent to passing -Werror=non-target-directive or -Wno-error=non-target-directive on the command line. This may not be set to true if warnings.nonTargetDirective is set to false." + }, + "configurePresets.errors.policy@v12..": { "type": "boolean", "description": "An optional boolean. Equivalent to passing -Werror=policy or -Wno-error=policy on the command line. This may not be set to true if warnings.policy is set to false." }, - "configurePresets.errors.uninitialized@v12": { + "configurePresets.errors.strict@v13": { + "type": "boolean", + "description": "An optional boolean. Equivalent to passing -Werror=strict or -Wno-error=strict on the command line. This may not be set to true if warnings.strict is set to false." + }, + "configurePresets.errors.uninitialized@v12..": { "type": "boolean", "description": "An optional boolean. Equivalent to passing -Werror=uninitialized or -Wno-error=uninitialized on the command line. This may not be set to true if warnings.uninitialized is set to false." }, - "configurePresets.errors.unusedCli@v12": { + "configurePresets.errors.unusedCli@v12..": { "type": "boolean", "description": "An optional boolean. Equivalent to passing -Werror=unused-cli or -Wno-error=unused-cli on the command line. This may not be set to true if warnings.unusedCli is set to false." }, @@ -2315,7 +2532,7 @@ ] } }, - "testPresets@v12": { + "testPresets@v12..": { "type": "array", "description": "An optional array of test preset objects. Used to specify arguments to ctest.", "items": { @@ -2366,7 +2583,7 @@ "$ref": "#/definitions/testPresets.filter@v10.." }, "execution": { - "$ref": "#/definitions/testPresets.execution@v12" + "$ref": "#/definitions/testPresets.execution@v12.." }, "$comment": { "$ref": "#/definitions/$comment@v10.." @@ -3088,7 +3305,7 @@ } } }, - "testPresets.execution@v12": { + "testPresets.execution@v12..": { "type": "object", "description": "An optional object specifying options for test execution.", "unevaluatedProperties": false, @@ -3127,7 +3344,7 @@ "$ref": "#/definitions/testPresets.execution.noTestsAction@v2.." }, "testPassthroughArguments": { - "$ref": "#/definitions/testPresets.execution.testPassthroughArguments@v12" + "$ref": "#/definitions/testPresets.execution.testPassthroughArguments@v12.." }, "$comment": { "$ref": "#/definitions/$comment@v10.." @@ -3249,7 +3466,7 @@ ], "description": "An optional string specifying the behavior if no tests are found. Must be one of the following values: \"default\" (equivalent to not passing any value on the command line), \"error\" (equivalent to passing --no-tests=error on the command line), or \"ignore\" (equivalent to passing --no-tests-ignore on the command line)." }, - "testPresets.execution.testPassthroughArguments@v12": { + "testPresets.execution.testPassthroughArguments@v12..": { "type": "array", "description": "An optional array of strings. Each element is forwarded as an argument to every test executable. Equivalent to passing arguments after -- on the ctest command line.", "items": { diff --git a/Help/manual/presets/schema.yaml b/Help/manual/presets/schema.yaml index 7650fa459f..631acd042e 100644 --- a/Help/manual/presets/schema.yaml +++ b/Help/manual/presets/schema.yaml @@ -1,5 +1,5 @@ --- -version: 12 +version: 13 types: - id: condition type: variant diff --git a/Help/manual/presets/warnings-properties.rst b/Help/manual/presets/warnings-properties.rst index 9c9b7bc6de..b98c06f1c5 100644 --- a/Help/manual/presets/warnings-properties.rst +++ b/Help/manual/presets/warnings-properties.rst @@ -50,6 +50,15 @@ :option:`-Wno-install-absolute-destination ` on the command line. This may not be set to ``false`` if ``errors.installAbsoluteDestination`` is set to ``true``. +.. _`CMakePresets.configurePresets.warnings.nonTargetDirective`: + +``nonTargetDirective`` + .. presets-versionadded:: 13 + + An optional boolean. Equivalent to passing :option:`-Wnon-target-directive ` or + :option:`-Wno-non-target-directive ` on the command line. + This may not be set to ``false`` if ``errors.nonTargetDirective`` is set to ``true``. + .. _`CMakePresets.configurePresets.warnings.policy`: ``policy`` @@ -59,6 +68,15 @@ :option:`-Wno-policy ` on the command line. This may not be set to ``false`` if ``errors.policy`` is set to ``true``. +.. _`CMakePresets.configurePresets.warnings.strict`: + +``strict`` + .. presets-versionadded:: 13 + + An optional boolean. Equivalent to passing :option:`-Wstrict ` or + :option:`-Wno-strict ` on the command line. + This may not be set to ``false`` if ``errors.strict`` is set to ``true``. + .. _`CMakePresets.configurePresets.warnings.uninitialized`: ``uninitialized`` diff --git a/Help/release/dev/presets-v13.rst b/Help/release/dev/presets-v13.rst new file mode 100644 index 0000000000..154e6053f8 --- /dev/null +++ b/Help/release/dev/presets-v13.rst @@ -0,0 +1,4 @@ +presets-v13 +----------- + +* :manual:`cmake-presets(7)` files now support schema version 13. diff --git a/Help/release/dev/warn-strict.rst b/Help/release/dev/warn-strict.rst new file mode 100644 index 0000000000..1c717d937b --- /dev/null +++ b/Help/release/dev/warn-strict.rst @@ -0,0 +1,20 @@ +warn-strict +----------- + +* The :diagnostic:`CMD_NON_TARGET_DIRECTIVE` diagnostic category was added to + diagnose commands that affect the directory scope when comparable + target-specific commands exist. The use of such directives is disrecommended. + This diagnostic may be controlled with the + :option:`-Wnon-target-directive ` command-line option, + the ``nonTargetDirective`` field in a + :manual:`CMake Presets ` + :preset:`configurePresets.warnings` object, + or the :command:`cmake_diagnostic` command. + +* The :diagnostic:`CMD_STRICT` diagnostic category was added to control + diagnostics regarding allowed but disrecommended usage as a group. + This diagnostic may be controlled with the :option:`-Wstrict ` + command-line option, the ``strict`` field in a + :manual:`CMake Presets ` + :preset:`configurePresets.warnings` object, + or the :command:`cmake_diagnostic` command. diff --git a/Source/cmAddCompileDefinitionsCommand.cxx b/Source/cmAddCompileDefinitionsCommand.cxx index cc0c28a0f4..5673630ed4 100644 --- a/Source/cmAddCompileDefinitionsCommand.cxx +++ b/Source/cmAddCompileDefinitionsCommand.cxx @@ -2,6 +2,7 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmAddCompileDefinitionsCommand.h" +#include "cmDiagnostics.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" @@ -9,8 +10,14 @@ bool cmAddCompileDefinitionsCommand(std::vector const& args, cmExecutionStatus& status) { cmMakefile& mf = status.GetMakefile(); + + mf.IssueDiagnostic(cmDiagnostics::CMD_NON_TARGET_DIRECTIVE, + "Use of non-target directives is not recommended. " + "Consider target_compile_definitions instead."); + for (std::string const& i : args) { mf.AddCompileDefinition(i); } + return true; } diff --git a/Source/cmAddCompileOptionsCommand.cxx b/Source/cmAddCompileOptionsCommand.cxx index 9c7be38827..f5c2e691b4 100644 --- a/Source/cmAddCompileOptionsCommand.cxx +++ b/Source/cmAddCompileOptionsCommand.cxx @@ -2,6 +2,7 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmAddCompileOptionsCommand.h" +#include "cmDiagnostics.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" @@ -9,8 +10,14 @@ bool cmAddCompileOptionsCommand(std::vector const& args, cmExecutionStatus& status) { cmMakefile& mf = status.GetMakefile(); + + mf.IssueDiagnostic(cmDiagnostics::CMD_NON_TARGET_DIRECTIVE, + "Use of non-target directives is not recommended. " + "Consider target_compile_options instead."); + for (std::string const& i : args) { mf.AddCompileOption(i); } + return true; } diff --git a/Source/cmAddDefinitionsCommand.cxx b/Source/cmAddDefinitionsCommand.cxx index 4ab82aa18c..6401053fe2 100644 --- a/Source/cmAddDefinitionsCommand.cxx +++ b/Source/cmAddDefinitionsCommand.cxx @@ -2,6 +2,7 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmAddDefinitionsCommand.h" +#include "cmDiagnostics.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" @@ -9,8 +10,16 @@ bool cmAddDefinitionsCommand(std::vector const& args, cmExecutionStatus& status) { cmMakefile& mf = status.GetMakefile(); + + mf.IssueDiagnostic( + cmDiagnostics::CMD_NON_TARGET_DIRECTIVE, + "Use of non-target directives is not recommended. " + "Consider target_compile_definitions, target_compile_options, or " + "target_include_directories instead."); + for (std::string const& i : args) { mf.AddDefineFlag(i); } + return true; } diff --git a/Source/cmAddLinkOptionsCommand.cxx b/Source/cmAddLinkOptionsCommand.cxx index 33ad9ed66e..bc138179e3 100644 --- a/Source/cmAddLinkOptionsCommand.cxx +++ b/Source/cmAddLinkOptionsCommand.cxx @@ -2,6 +2,7 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmAddLinkOptionsCommand.h" +#include "cmDiagnostics.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" @@ -9,8 +10,14 @@ bool cmAddLinkOptionsCommand(std::vector const& args, cmExecutionStatus& status) { cmMakefile& mf = status.GetMakefile(); + + mf.IssueDiagnostic(cmDiagnostics::CMD_NON_TARGET_DIRECTIVE, + "Use of non-target directives is not recommended. " + "Consider target_link_options instead."); + for (std::string const& i : args) { mf.AddLinkOption(i); } + return true; } diff --git a/Source/cmDiagnostics.h b/Source/cmDiagnostics.h index 5c1461cb4e..fa3b1960fc 100644 --- a/Source/cmDiagnostics.h +++ b/Source/cmDiagnostics.h @@ -29,7 +29,9 @@ SELECT(ACTION, Warn, CMD_NONE, CMD_AUTHOR, 12) \ SELECT(ACTION, Warn, CMD_AUTHOR, CMD_DEPRECATED, 1) \ SELECT(ACTION, Warn, CMD_AUTHOR, CMD_EXPERIMENTAL, 12) \ - SELECT(ACTION, Ignore, CMD_AUTHOR, CMD_INSTALL_ABSOLUTE_DESTINATION, 12) \ + SELECT(ACTION, Ignore, CMD_AUTHOR, CMD_STRICT, 13) \ + SELECT(ACTION, Ignore, CMD_STRICT, CMD_INSTALL_ABSOLUTE_DESTINATION, 12) \ + SELECT(ACTION, Ignore, CMD_STRICT, CMD_NON_TARGET_DIRECTIVE, 13) \ SELECT(ACTION, Warn, CMD_AUTHOR, CMD_POLICY, 12) \ SELECT(ACTION, Ignore, CMD_NONE, CMD_UNINITIALIZED, 1) \ SELECT(ACTION, Warn, CMD_NONE, CMD_UNUSED_CLI, 1) diff --git a/Source/cmIncludeDirectoryCommand.cxx b/Source/cmIncludeDirectoryCommand.cxx index c08d15e892..fc99dc287e 100644 --- a/Source/cmIncludeDirectoryCommand.cxx +++ b/Source/cmIncludeDirectoryCommand.cxx @@ -8,6 +8,7 @@ #include +#include "cmDiagnostics.h" #include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" #include "cmMakefile.h" @@ -22,12 +23,16 @@ static void NormalizeInclude(cmMakefile& mf, std::string& inc); bool cmIncludeDirectoryCommand(std::vector const& args, cmExecutionStatus& status) { + cmMakefile& mf = status.GetMakefile(); + + mf.IssueDiagnostic(cmDiagnostics::CMD_NON_TARGET_DIRECTIVE, + "Use of non-target directives is not recommended. " + "Consider target_include_directories instead."); + if (args.empty()) { return true; } - cmMakefile& mf = status.GetMakefile(); - auto i = args.begin(); bool before = mf.IsOn("CMAKE_INCLUDE_DIRECTORIES_BEFORE"); diff --git a/Source/cmLinkDirectoriesCommand.cxx b/Source/cmLinkDirectoriesCommand.cxx index a08118601e..90e44ed197 100644 --- a/Source/cmLinkDirectoriesCommand.cxx +++ b/Source/cmLinkDirectoriesCommand.cxx @@ -2,6 +2,7 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmLinkDirectoriesCommand.h" +#include "cmDiagnostics.h" #include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" #include "cmList.h" @@ -15,11 +16,16 @@ static void AddLinkDir(cmMakefile& mf, std::string const& dir, bool cmLinkDirectoriesCommand(std::vector const& args, cmExecutionStatus& status) { + cmMakefile& mf = status.GetMakefile(); + + mf.IssueDiagnostic(cmDiagnostics::CMD_NON_TARGET_DIRECTIVE, + "Use of non-target directives is not recommended. " + "Consider target_link_directories instead."); + if (args.empty()) { return true; } - cmMakefile& mf = status.GetMakefile(); bool before = mf.IsOn("CMAKE_LINK_DIRECTORIES_BEFORE"); auto i = args.cbegin(); diff --git a/Source/cmLinkLibrariesCommand.cxx b/Source/cmLinkLibrariesCommand.cxx index 74fe393939..7f12185bde 100644 --- a/Source/cmLinkLibrariesCommand.cxx +++ b/Source/cmLinkLibrariesCommand.cxx @@ -2,16 +2,23 @@ file LICENSE.rst or https://cmake.org/licensing for details. */ #include "cmLinkLibrariesCommand.h" +#include "cmDiagnostics.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" bool cmLinkLibrariesCommand(std::vector const& args, cmExecutionStatus& status) { + cmMakefile& mf = status.GetMakefile(); + + mf.IssueDiagnostic(cmDiagnostics::CMD_NON_TARGET_DIRECTIVE, + "Use of non-target directives is not recommended. " + "Consider target_link_libraries instead."); + if (args.empty()) { return true; } - cmMakefile& mf = status.GetMakefile(); + // add libraries, note that there is an optional prefix // of debug and optimized than can be used for (auto i = args.begin(); i != args.end(); ++i) { diff --git a/Tests/RunCMake/Diagnostics/NonTargetDirectives-stderr.txt b/Tests/RunCMake/Diagnostics/NonTargetDirectives-stderr.txt new file mode 100644 index 0000000000..93efa879da --- /dev/null +++ b/Tests/RunCMake/Diagnostics/NonTargetDirectives-stderr.txt @@ -0,0 +1,56 @@ +CMake Warning \(non-target-directive\) at NonTargetDirectives\.cmake:[0-9]+ \(add_definitions\): + Use of non-target directives is not recommended\. Consider + target_compile_definitions, target_compile_options, or + target_include_directories instead\. +Call Stack \(most recent call first\): + CMakeLists\.txt:3 \(include\) +This warning is for project developers\. Use -Wno-author or +-Wno-non-target-directive to suppress it\. + +CMake Warning \(non-target-directive\) at NonTargetDirectives\.cmake:[0-9]+ \(add_compile_definitions\): + Use of non-target directives is not recommended\. Consider + target_compile_definitions instead\. +Call Stack \(most recent call first\): + CMakeLists\.txt:3 \(include\) +This warning is for project developers\. Use -Wno-author or +-Wno-non-target-directive to suppress it\. + +CMake Warning \(non-target-directive\) at NonTargetDirectives\.cmake:[0-9]+ \(add_compile_options\): + Use of non-target directives is not recommended\. Consider + target_compile_options instead\. +Call Stack \(most recent call first\): + CMakeLists\.txt:3 \(include\) +This warning is for project developers\. Use -Wno-author or +-Wno-non-target-directive to suppress it\. + +CMake Warning \(non-target-directive\) at NonTargetDirectives\.cmake:[0-9]+ \(add_link_options\): + Use of non-target directives is not recommended\. Consider + target_link_options instead\. +Call Stack \(most recent call first\): + CMakeLists\.txt:3 \(include\) +This warning is for project developers\. Use -Wno-author or +-Wno-non-target-directive to suppress it\. + +CMake Warning \(non-target-directive\) at NonTargetDirectives\.cmake:[0-9]+ \(include_directories\): + Use of non-target directives is not recommended\. Consider + target_include_directories instead\. +Call Stack \(most recent call first\): + CMakeLists\.txt:3 \(include\) +This warning is for project developers\. Use -Wno-author or +-Wno-non-target-directive to suppress it\. + +CMake Warning \(non-target-directive\) at NonTargetDirectives\.cmake:[0-9]+ \(link_directories\): + Use of non-target directives is not recommended\. Consider + target_link_directories instead\. +Call Stack \(most recent call first\): + CMakeLists\.txt:3 \(include\) +This warning is for project developers\. Use -Wno-author or +-Wno-non-target-directive to suppress it\. + +CMake Warning \(non-target-directive\) at NonTargetDirectives\.cmake:[0-9]+ \(link_libraries\): + Use of non-target directives is not recommended\. Consider + target_link_libraries instead\. +Call Stack \(most recent call first\): + CMakeLists\.txt:3 \(include\) +This warning is for project developers\. Use -Wno-author or +-Wno-non-target-directive to suppress it\. diff --git a/Tests/RunCMake/Diagnostics/NonTargetDirectives.cmake b/Tests/RunCMake/Diagnostics/NonTargetDirectives.cmake new file mode 100644 index 0000000000..16a497104b --- /dev/null +++ b/Tests/RunCMake/Diagnostics/NonTargetDirectives.cmake @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 4.4) +project(NonTargetDirectives) + +# Test diagnostics for non-target directives. Note that, because we don't +# need to actually compile anything, it doesn't matter if we use options, +# directories, or libraries that don't exist. + +add_definitions(-DFOO) + +add_compile_definitions(BAR) +add_compile_options(-fPIC) + +add_link_options(-Wl,--no-undefined) + +include_directories(${CMAKE_SOURCE_DIR}/include) + +link_directories(${CMAKE_SOURCE_DIR}/lib) + +link_libraries(/usr/lib/libm.so) diff --git a/Tests/RunCMake/Diagnostics/RunCMakeTest.cmake b/Tests/RunCMake/Diagnostics/RunCMakeTest.cmake index 630d18229b..2420ff2ffc 100644 --- a/Tests/RunCMake/Diagnostics/RunCMakeTest.cmake +++ b/Tests/RunCMake/Diagnostics/RunCMakeTest.cmake @@ -29,3 +29,6 @@ block() set(RunCMake_TEST_NO_CLEAN 1) run_persist_test(Persist2 -Wauthor) endblock() + +run_cmake_with_options(NonTargetDirectives -Wstrict) +run_cmake_with_options(NonTargetDirectives -Wnon-target-directive)