Skip to content

cmake: replace CURL_*_DIR with {PROJECT,CMAKE_CURRENT}_*_DIR - #15331

Closed
vszakats wants to merge 7 commits into
curl:masterfrom
vszakats:cm-tidy-project-root-var
Closed

cmake: replace CURL_*_DIR with {PROJECT,CMAKE_CURRENT}_*_DIR#15331
vszakats wants to merge 7 commits into
curl:masterfrom
vszakats:cm-tidy-project-root-var

Conversation

@vszakats

@vszakats vszakats commented Oct 18, 2024

Copy link
Copy Markdown
Member

It reduces the number of synonym variables in the code.
Makes it easier to grok and grep.

  • replace CURL_SOURCE_DIR
    with PROJECT_SOURCE_DIR.

  • replace CURL_BINARY_DIR
    with PROJECT_BINARY_DIR or CMAKE_CURRENT_BINARY_DIR.

  • replace a single use of CMAKE_BINARY_DIR
    with PROJECT_BINARY_DIR.

  • replace CMAKE_CURRENT_*_DIR
    with PROJECT_*_DIR where it makes the code more uniform.

  • quote an argument (formatting).


  • check CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR as an alternative for PROJECT_*.

@vszakats
vszakats marked this pull request as draft October 18, 2024 08:40
@vszakats vszakats changed the title cmake: rename CURL_*_DIR to CMAKE_CURRENT_*_DIR [WIP] cmake: rename CURL_*_DIR to CMAKE_CURRENT_*_DIR Oct 18, 2024
@vszakats vszakats changed the title [WIP] cmake: rename CURL_*_DIR to CMAKE_CURRENT_*_DIR [WIP] cmake: replace CURL_*_DIR variables Oct 18, 2024
@vszakats vszakats changed the title [WIP] cmake: replace CURL_*_DIR variables [WIP] cmake: replace CURL_*_DIR variables with generic ones Oct 18, 2024
@vszakats vszakats changed the title [WIP] cmake: replace CURL_*_DIR variables with generic ones cmake: replace CURL_*_DIR variables with generic ones Oct 18, 2024
@vszakats
vszakats force-pushed the cm-tidy-project-root-var branch from f98609a to c6d4c54 Compare October 18, 2024 11:49
@vszakats vszakats changed the title cmake: replace CURL_*_DIR variables with generic ones cmake: replace CURL_*_DIR variables with {PROJECT,CMAKE_CURRENT}_*_DIR Oct 18, 2024
@vszakats vszakats changed the title cmake: replace CURL_*_DIR variables with {PROJECT,CMAKE_CURRENT}_*_DIR cmake: replace CURL_*_DIR with {PROJECT,CMAKE_CURRENT}_*_DIR Oct 18, 2024
@vszakats
vszakats marked this pull request as ready for review October 18, 2024 12:33
@vszakats
vszakats force-pushed the cm-tidy-project-root-var branch 3 times, most recently from 23ddb17 to 9babf14 Compare October 22, 2024 11:03
It's counterintuitive but `PROJECT_*_DIR` seems to be the preferred
variable to retrieve curl's root directory.

In libssh2 this was done for this reason:
"Fixes compiling as dependency with FetchContent"
libssh2/libssh2#1121

curl already used `PROJECT_*_DIR` everywhere, except one place.

Previous change:
curl@72646c2 curl#488 curl#498

That previous fix didn't address the remaining CMAKE_BINARY_DIR inside
the macro. Probably because the actual directory isn't relevant, just
a mandatory argument of `try_compile()`. Newer CMake version allow for
an improved argument list, where `BINARY_DIR` argument is optional.
@vszakats
vszakats force-pushed the cm-tidy-project-root-var branch from 9babf14 to 270df5f Compare October 22, 2024 13:18
@vszakats vszakats closed this in 9126eb5 Oct 22, 2024
@vszakats
vszakats deleted the cm-tidy-project-root-var branch October 22, 2024 17:15
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
It reduces the number of synonym variables in the code.
Makes it easier to grok and grep.

- replace `CURL_SOURCE_DIR`
  with `PROJECT_SOURCE_DIR`.

- replace `CURL_BINARY_DIR`
  with `PROJECT_BINARY_DIR` or `CMAKE_CURRENT_BINARY_DIR`.

- replace a single use of `CMAKE_BINARY_DIR`
  with `PROJECT_BINARY_DIR`.

- replace `CMAKE_CURRENT_*_DIR`
  with `PROJECT_*_DIR` where it makes the code more uniform.

- quote an argument (formatting).

Closes curl#15331
vszakats added a commit that referenced this pull request Jun 26, 2026
Use `PROJECT_SOURCE_DIR` for these files, replacing
`CMAKE_CURRENT_SOURCE_DIR`, to make it consistent with rest of CMake
sources and to reflect that the locations of these files are fixed and
do not depend on the CMake source location referencing them.

Exception: keep as-is before calling `project()`, which is where
`PROJECT_SOURCE_DIR` is initialized.

Ref: https://cmake.org/cmake/help/v3.18/command/project.html

Follow-up to #22187
Follow-up to 9126eb5 #15331

Closes #22188
vszakats added a commit that referenced this pull request Jun 26, 2026
- drop `generated` subdir, move these files to build root.
  To move them next to CPack and other config files, and to avoid
  a subdirectory for only 2 files.
  Follow-up to 6932849 #2849

- add 'Consumed variables' comment for `CMake/cmake_uninstall.in.cmake`.

- move generated `cmake_uninstall.cmake` to the build root directory
  (from `CMake/`). To:
  - avoid creating a `CMake` subdirectory within the build directory
    with this single file in it.
  - move it next to its `cmake_install.cmake` counterpart.
  - move it next to `install_manifest.txt` which it relies on.

  Follow-up to 27e2a47

- Use `PROJECT_SOURCE_DIR` for these files, replacing
  `CMAKE_CURRENT_SOURCE_DIR`, to make it consistent with rest of CMake
  sources, and to reduce ambiguity in `CMake/cmake_uninstall.in.cmake`
  template.

Follow-up to 8198e38 #22188
Follow-up to 4839029 #22187
Follow-up to 9126eb5 #15331

Closes #22192
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant