Skip to content

Commit d6848cd

Browse files
committed
correct windows install-python.cmake
1 parent dea542e commit d6848cd

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ if(NOT CMAKE_C_COMPILER)
2424
unset(CMAKE_C_COMPILER CACHE)
2525
endif()
2626

27-
project(CPython
28-
LANGUAGES C
29-
)
27+
project(CPython LANGUAGES C)
3028

3129
include(ExternalProject)
3230
include(GNUInstallDirs)

scripts/install-python.cmake

+11-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
# Download Windows executable
22

3-
cmake_minimum_required(VERSION 3.19)
3+
cmake_minimum_required(VERSION 3.24)
44

55
include(FetchContent)
66

77
option(CMAKE_TLS_VERIFY "verify TLS certificates" on)
88

9-
if(NOT WIN32)
10-
message(FATAL_ERROR "Embedded Python downloader is Windows-only")
11-
endif()
12-
139
if(NOT python_version)
14-
file(READ ${CMAKE_CURRENT_LIST_DIR}/../cmake/libraries.json json_meta)
10+
file(READ ${CMAKE_CURRENT_LIST_DIR}/../libraries.json json_meta)
1511
string(JSON python_version GET ${json_meta} "python" "version")
1612
endif()
1713

1814
if(NOT prefix)
19-
get_filename_component(prefix ~/python-${python_version} ABSOLUTE)
15+
file(REAL_PATH "~/python-${python_version}" prefix EXPAND_TILDE)
2016
endif()
2117

18+
if(NOT DEFINED ENV{PROCESSOR_ARCHITECTURE})
19+
message(FATAL_ERROR "PROCESSOR_ARCHITECTURE not set, could not determine CPU arch")
20+
endif()
2221
set(arch $ENV{PROCESSOR_ARCHITECTURE})
2322

2423
if(arch STREQUAL "ARM64")
@@ -42,12 +41,7 @@ message(STATUS "Python ${python_version} ${prefix}")
4241

4342
set(FETCHCONTENT_QUIET false)
4443

45-
FetchContent_Populate(cmake
46-
URL ${python_url}
47-
TLS_VERIFY ${CMAKE_TLS_VERIFY}
48-
UPDATE_DISCONNECTED true
49-
INACTIVITY_TIMEOUT 60
50-
)
44+
FetchContent_Populate(cmake URL ${python_url} SOURCE_DIR ${prefix})
5145

5246
file(MAKE_DIRECTORY ${prefix})
5347
file(COPY ${cmake_SOURCE_DIR}/ DESTINATION ${prefix})
@@ -60,7 +54,8 @@ find_file(pth
6054
NAMES python${python_version_short}._pth
6155
HINTS ${prefix}
6256
NO_DEFAULT_PATH
63-
REQUIRED)
57+
REQUIRE
58+
)
6459

6560
file(RENAME ${pth} ${prefix}/python${python_version_short}.pth)
6661

@@ -71,10 +66,8 @@ find_program(python_exe
7166
NAMES python3 python
7267
HINTS ${prefix}
7368
NO_DEFAULT_PATH
69+
REQUIRED
7470
)
75-
if(NOT python_exe)
76-
message(FATAL_ERROR "failed to install Python ${python_version} to ${prefix}")
77-
endif()
7871

7972
# --- add paths to Python
8073
file(APPEND "${pth}" "${prefix}/Lib\n")
@@ -84,6 +77,5 @@ file(DOWNLOAD https://bootstrap.pypa.io/get-pip.py ${prefix}/get-pip.py)
8477

8578
execute_process(COMMAND ${python_exe} ${prefix}/get-pip.py)
8679

87-
88-
get_filename_component(bindir ${python_exe} DIRECTORY)
80+
cmake_path(GET python_exe PARENT_PATH bindir)
8981
message(STATUS "installed Python ${python_version} to ${bindir}")

0 commit comments

Comments
 (0)