cmake: Avoid use of non-target directives #1996

pull hebasto wants to merge 4 commits into bitcoin-core:master from hebasto:261113-non-target-directive changing 4 files +115 −66
  1. hebasto commented at 6:07 PM on November 13, 2026: member

    Use of non-target directives, such as add_compile_definitions(), include_directories() or add_compile_options(), is not recommended. As of CMake 4.5.0, it triggers -Wnon-target-directive warnings.

    For example:

    $ cmake -B build -Wnon-target-directive
    -- The C compiler identification is GNU 16.2.1
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: /usr/lib64/ccache/cc - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    CMake Warning (non-target-directive) at CMakeLists.txt:66 (add_compile_definitions):
      Use of non-target directives is not recommended.  Consider
      target_compile_definitions instead.
    This warning is for project developers.  Use -Wno-author or
    -Wno-non-target-directive to suppress it.
    
    CMake Warning (non-target-directive) at CMakeLists.txt:78 (add_compile_definitions):
      Use of non-target directives is not recommended.  Consider
      target_compile_definitions instead.
    This warning is for project developers.  Use -Wno-author or
    -Wno-non-target-directive to suppress it.
    
    CMake Warning (non-target-directive) at CMakeLists.txt:79 (add_compile_definitions):
      Use of non-target directives is not recommended.  Consider
      target_compile_definitions instead.
    This warning is for project developers.  Use -Wno-author or
    -Wno-non-target-directive to suppress it.
    ...
    

    This issue affects downstream projects. For example, Bitcoin Core sets "errors": {"dev": true} in its "dev-mode" preset, which makes the configuration step fail.

    This PR introduces a project-wide interface library, following the approach used in Bitcoin Core.

  2. cmake: Introduce `secp256k1_common` interface library
    The new `secp256k1_common` interface library encapsulates usage
    requirements shared by all buildable targets. It is empty for
    now, so this change has no effect on the build. The following commits
    populate it.
    71ffd49a5f
  3. cmake: Switch `add_compile_definitions` -> `target_compile_definitions`
    Use of non-target directives is not recommended. It triggers
    `-Wnon-target-directive` warnings since CMake 4.5.0.
    7723e5f3a1
  4. cmake: Switch `include_directories` -> `target_include_directories`
    Use of non-target directives is not recommended. It triggers
    `-Wnon-target-directive` warnings since CMake 4.5.0.
    870ea8ed84
  5. cmake: Switch `add_compile_options` -> `target_compile_options`
    Use of non-target directives is not recommended. It triggers
    `-Wnon-target-directive` warnings since CMake 4.5.0.
    acf8dab74a
  6. hebasto renamed this:
    261113 non target directive
    cmake: Avoid Use of non-target directives
    on Nov 13, 2026
  7. hebasto renamed this:
    cmake: Avoid Use of non-target directives
    cmake: Avoid use of non-target directives
    on Nov 13, 2026
Contributors

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-14 00:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me