11# Download Windows executable
22
3- cmake_minimum_required (VERSION 3.19 )
3+ cmake_minimum_required (VERSION 3.24 )
44
55include (FetchContent )
66
77option (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-
139if (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" )
1612endif ()
1713
1814if (NOT prefix)
19- get_filename_component ( prefix ~/python-${python_version} ABSOLUTE )
15+ file ( REAL_PATH " ~/python-${python_version} " prefix EXPAND_TILDE )
2016endif ()
2117
18+ if (NOT DEFINED ENV{PROCESSOR_ARCHITECTURE})
19+ message (FATAL_ERROR "PROCESSOR_ARCHITECTURE not set, could not determine CPU arch" )
20+ endif ()
2221set (arch $ENV{PROCESSOR_ARCHITECTURE} )
2322
2423if (arch STREQUAL "ARM64" )
@@ -42,12 +41,7 @@ message(STATUS "Python ${python_version} ${prefix}")
4241
4342set (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
5246file (MAKE_DIRECTORY ${prefix} )
5347file (COPY ${cmake_SOURCE_DIR} / DESTINATION ${prefix} )
@@ -60,7 +54,8 @@ find_file(pth
6054NAMES python${python_version_short}._pth
6155HINTS ${prefix}
6256NO_DEFAULT_PATH
63- REQUIRED )
57+ REQUIRE
58+ )
6459
6560file (RENAME ${pth} ${prefix} /python${python_version_short}.pth )
6661
@@ -71,10 +66,8 @@ find_program(python_exe
7166NAMES python3 python
7267HINTS ${prefix}
7368NO_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
8073file (APPEND "${pth} " "${prefix} /Lib\n " )
@@ -84,6 +77,5 @@ file(DOWNLOAD https://bootstrap.pypa.io/get-pip.py ${prefix}/get-pip.py)
8477
8578execute_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 )
8981message (STATUS "installed Python ${python_version} to ${bindir} " )
0 commit comments