Skip to content

CMake: Normalize installation path on Windows to avoid mixing slashes and backslashes - #9187

Merged
seisman merged 4 commits into
masterfrom
ci/fix-path
Sep 8, 2026
Merged

CMake: Normalize installation path on Windows to avoid mixing slashes and backslashes#9187
seisman merged 4 commits into
masterfrom
ci/fix-path

Conversation

@seisman

@seisman seisman commented Sep 8, 2026

Copy link
Copy Markdown
Member

Previously, we had issues building GMT on Windows with errors like:

CMake Error at cmake_install.cmake:5 (set):
  Syntax error in cmake code at

    D:/a/gmt/gmt/build/cmake_install.cmake:5

  when parsing string

    D:\a\gmt\gmt/gmt-install-dir

  Invalid character escape '\a'.

The real cause is that Windows uses backslashes (D:\a\gmt\gmt) while CI (and CMake) uses slashes.

PR #9097 fixed the issue by applying a workaround to convert backslashes to slashes. It works for CI, but users who build GMT locally (via WSL or similar) may still have the same issue.

This PR fixes the root issue by normalizing paths on Windows using CMake's TO_CMAKE_PATH directive (xref: https://cmake.org/cmake/help/latest/command/file.html#to-cmake-path). With the fix, the CI workflows can be simplified.

Helped with Claude Opus 5.

@seisman seisman added the maintenance Boring but important stuff for the core devs label Sep 8, 2026
@seisman seisman added this to the 6.8.0 milestone Sep 8, 2026
@seisman

seisman commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

@joa-quim Could you please check if it works for you on Windows locally?

@joa-quim

joa-quim commented Sep 8, 2026

Copy link
Copy Markdown
Member

Hmm, I don't see what I can test locally. I don't use those recipes to build GMT. I have a ConfigUser.cmake to set all that I need.

@seisman

seisman commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

This PR adds the following lines to cmake/modules/ConfigCMake.cmake, so it should affect your local builds:

# Normalize the installation prefix on Windows (avoid mixing slashes and backslashes).
if (WIN32)
	file (TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" CMAKE_INSTALL_PREFIX)
endif (WIN32)

@joa-quim

joa-quim commented Sep 8, 2026

Copy link
Copy Markdown
Member

Rebuilt and installed locally and no issues.

@seisman
seisman requested a review from Esteban82 September 8, 2026 13:08
@Esteban82 Esteban82 added the AI-assisted All (or most) of the code was written by Artificial Intelligence. label Sep 8, 2026
@seisman
seisman merged commit ea55e56 into master Sep 8, 2026
13 of 16 checks passed
@seisman
seisman deleted the ci/fix-path branch September 8, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-assisted All (or most) of the code was written by Artificial Intelligence. maintenance Boring but important stuff for the core devs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants