Skip to content

Commit c8cfc62

Browse files
authored
Merge pull request #64 from YCHuang2112sub/master
Checking cmake is in the system path for windows
2 parents ea925e8 + 96f3cf3 commit c8cfc62

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

setup.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,43 @@ def build_extensions(self):
7171
raise RuntimeError("Cython is required to generate C++ code")
7272

7373

74+
def check_cmake_in_path():
75+
try:
76+
result = subprocess.run(
77+
["cmake", "--version"],
78+
stdout=subprocess.PIPE,
79+
stderr=subprocess.PIPE,
80+
text=True,
81+
)
82+
if result.returncode == 0:
83+
# CMake is in the system path
84+
return True, result.stdout.strip()
85+
else:
86+
# CMake is not in the system path
87+
return False, None
88+
except FileNotFoundError:
89+
# CMake command not found
90+
return False, None
91+
92+
93+
if os.name == "nt": # Check if the OS is Windows
94+
# Check if CMake is in the system path
95+
cmake_found, cmake_version = check_cmake_in_path()
96+
97+
if cmake_found:
98+
print(
99+
f"CMake is in the system path. Version: \
100+
{cmake_version}"
101+
)
102+
else:
103+
raise SystemError(
104+
"CMake is not found in the \
105+
system path. Make sure CMake \
106+
is installed and in the system \
107+
path."
108+
)
109+
110+
74111
# Workaround for `distutils.spawn` problem on Windows python < 3.9
75112
# See details: [bpo-39763: distutils.spawn now uses subprocess (GH-18743)]
76113
# (https://github.com/python/cpython/commit/1ec63b62035e73111e204a0e03b83503e1c58f2e)

0 commit comments

Comments
 (0)