Skip to content

STYLE: Add PUBLIC to target_link_libraries and elastix_link_itk calls - #1457

Merged
N-Dekker merged 1 commit into
mainfrom
target_link_libraries-PUBLIC
Jul 9, 2026
Merged

STYLE: Add PUBLIC to target_link_libraries and elastix_link_itk calls#1457
N-Dekker merged 1 commit into
mainfrom
target_link_libraries-PUBLIC

Conversation

@N-Dekker

@N-Dekker N-Dekker commented Jul 9, 2026

Copy link
Copy Markdown
Member

Using Notepad++, Replace in Files, doing

Find what: (target_link_libraries\([^ \r\n]+)
Replace with: \1 PUBLIC
Find what: (target_link_libraries\([^ \r\n]+)$
Replace with: \1 PUBLIC
Find what: (elastix_link_itk\([^ \r\n]+) MODULES
Replace with: \1 PUBLIC MODULES
Filters: CMakeLists*.txt
(*) Regular expression

It appears clearer, and more modern, to explicitly specify the scope (by adding the PUBLIC keyword).

Doing so would prevent a CMake error when having multiple target_link_libraries calls on the same target, saying:

The plain signature for target_link_libraries has already been used with
the target "...".  All uses of target_link_libraries with a target must
be either all-keyword or all-plain.

As experienced with CMake 4.3.2


@blowekamp Please check! Do you agree that the PUBLIC keyword is preferred over leaving the scope unspecified (implicitly transitive)?

Using Notepad++, Replace in Files, doing

  Find what: `(target_link_libraries\([^ \r\n]+) `
  Replace with: `\1 PUBLIC `
  Find what: `(target_link_libraries\([^ \r\n]+)$`
  Replace with: `\1 PUBLIC`
  Find what: `(elastix_link_itk\([^ \r\n]+) MODULES`
  Replace with: `\1 PUBLIC MODULES`
  Filters: `CMakeLists*.txt`
  (*) Regular expression

It appears clearer, and more modern, to explicitly specify the scope (by adding the `PUBLIC` keyword).

Doing so would prevent a CMake error when having multiple target_link_libraries calls on the same target, saying:

    The plain signature for target_link_libraries has already been used with
    the target "...".  All uses of target_link_libraries with a target must
    be either all-keyword or all-plain.

As experienced with CMake 4.3.2
@N-Dekker
N-Dekker force-pushed the target_link_libraries-PUBLIC branch from ce8d0de to 7fcad33 Compare July 9, 2026 13:34
@blowekamp

Copy link
Copy Markdown
Contributor

Look good.

Ideally further work would include more specific specification on which dependencies libraries are using in the header ( PUBLIC ) vs the libraries whose headers are only used in compiled files ( PRIVATE ). And there is also the potential case where a header/library is only used in a header file but not compiled by the library ( INTERFACE ).

@N-Dekker
N-Dekker merged commit 5c71a23 into main Jul 9, 2026
7 of 8 checks passed
@N-Dekker
N-Dekker deleted the target_link_libraries-PUBLIC branch July 9, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants