Skip to content

Commit 9c1ef8d

Browse files
corrodedHashbuddly27
authored andcommitted
Fix uninitialized variable errors in FindPytest.cmake with -Werror=dev
CMake reported uninitialized variable errors for `LD_LIBRARY_PATH` and `PYTHONPATH` when using `-Werror=dev --warn-uninitialized`, causing `pytest_discover_tests` to fail.
1 parent 892ad1f commit 9c1ef8d

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

cmake/FindPytest.cmake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,16 @@ if (Pytest_FOUND AND NOT TARGET Pytest::Pytest)
7171
endif()
7272

7373
# Convert paths to CMake-friendly format.
74-
cmake_path(CONVERT "$ENV{${LIBRARY_ENV_NAME}}" TO_CMAKE_PATH_LIST LIBRARY_PATH)
75-
cmake_path(CONVERT "$ENV{PYTHONPATH}" TO_CMAKE_PATH_LIST PYTHON_PATH)
74+
if(DEFINED ENV{${LIBRARY_ENV_NAME}})
75+
cmake_path(CONVERT "$ENV{${LIBRARY_ENV_NAME}}" TO_CMAKE_PATH_LIST LIBRARY_PATH)
76+
else()
77+
set(LIBRARY_PATH "")
78+
endif()
79+
if(DEFINED ENV{PYTHONPATH})
80+
cmake_path(CONVERT "$ENV{PYTHONPATH}" TO_CMAKE_PATH_LIST PYTHON_PATH)
81+
else()
82+
set(PYTHON_PATH "")
83+
endif()
7684

7785
# Prepend specified paths to the library and Python paths.
7886
if (_LIBRARY_PATH_PREPEND)

doc/release/release_notes.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
Release Notes
55
*************
66

7+
.. release:: Upcoming
8+
9+
.. change:: fixed
10+
11+
Updated scripts to prevent uninitialized variable errors when using `-Werror=dev
12+
<https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-Werror>`_
13+
and `--warn-uninitialized
14+
<https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-warn-uninitialized>`_
15+
options. Thanks :github_user:`corrodedHash`!
16+
717
.. release:: 0.11.3
818
:date: 2025-01-19
919

0 commit comments

Comments
 (0)