Skip to content

Allow building with cmake on Windows#2090

Open
gabrieljreed wants to merge 4 commits intoAcademySoftwareFoundation:mainfrom
gabrieljreed:fix-cmake-on-windows
Open

Allow building with cmake on Windows#2090
gabrieljreed wants to merge 4 commits intoAcademySoftwareFoundation:mainfrom
gabrieljreed:fix-cmake-on-windows

Conversation

@gabrieljreed
Copy link
Copy Markdown

Resolves #1321

Premise

Path normalization

On Windows, rez applies path normalization (converting forward slashes to back slashes) to any environment variable whose name matches the pattern in the pathed_env_vars config setting, which defaults to *PATH. This is correct behavior for variables like PATH, PYTHONPATH, and LD_LIBRARY_PATH, which need native Windows path separators. However, CMAKE_MODULE_PATH also matches *PATH, but Cmake requires forward slashes in this variable.

Unterminated string literal in rez_install_python

When building rez packages on Windows that use rez_install_python (with nmake), the build fails with a Python SyntaxError: unterminated string literal

File "<string>", line 1
    'import
    ^
SyntaxError: unterminated string literal (detected at line 1)

The root cause is in InstallPython.cmake - the add_custom_command that compiles .py files into .pyc uses single quotes around the Python -c argument.

COMMAND ${py_bin} -c 'import py_compile \; py_compile.compile(...)'

On Unix, make dispatches commands via /bin/sh where single quotes are valid string delimiters. On Windows, nmake dispatches via cmd.exe, where single quotes are literal characters, so Python receives 'import as the start of an unterminated string literal.

Changes

  • Add a new configuration setting, non_pathed_env_vars, which is an exclusion list that takes priority over pathed_env_vars.
    • Any variable matching a pattern in this list is except from path normalization, even if it also matches pathed_env_vars
    • Supports the same fnmatch wildcards as pathed_env_vars
    • The default value ships with CMAKE_MODULE_PATH out of the box, since this is a known case where we don't want normalization
  • Fix install_python macro
    • Switch from single quoted shell args to cmake double quoted string for the -c argument
    • Add VERBATIM keyword to add_custom_command so Cmake handles all platform-specific argument quoting correctly

Tests

  • I'm able to build the hello_world example package on both Windows and Linux after setting build_system = "cmake"
  • Add new tests for ActionInterpreter._is_pathed_key and shell.set_env
  • I was unable to write tests for the rez_install_python cmake macro, but I verified that it worked manually

@gabrieljreed gabrieljreed requested a review from a team as a code owner April 15, 2026 23:27
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Apr 15, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

- Introduced `non_pathed_env_vars` configuration to exclude specific
variables from path normalization
- Updated `_is_pathed_key` method to respect the new configuration
- Added tests to verify behavior of non-pathed environment variables in
Windows shell

Signed-off-by: Gabriel Reed <[email protected]>
Signed-off-by: Gabriel Reed <[email protected]>
@gabrieljreed gabrieljreed force-pushed the fix-cmake-on-windows branch from a548e19 to ce9ff60 Compare April 15, 2026 23:33
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.

CMake breaks due to windows penchant for escape characters as path separators

1 participant