Skip to content

Commit 58d2d69

Browse files
committed
Fix slow find_package(Python) on Windows
It seems that, even though we give it an exact `Python_ROOT_DIR`, CMake does still search the system for all other Python versions. In the end, it does correctly select the one in `Python_ROOT_DIR` as we specified but the this entire process is very slow: between 20 seconds and a full minute. The fix is to give CMake more info: tell it which version of Python is at `Python_ROOT_DIR` and request it to be EXACT. This seems to allow it to return immediately without considering others. It brings the time down to ~3 seconds. And if we also tell it the exact location of `Python_EXECUTABLE`, the time is down to ~1 second.
1 parent 3f901f0 commit 58d2d69

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v1.3.1 | 2021-06-04
4+
5+
- Fixed very slow `find_package(Python)` on Windows
6+
37
## v1.3.0 | 2021-06-03
48

59
- Added support for Linux and macOS with a couple of caveats to be resolved later:

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class EmbeddedPython(ConanFile):
88
name = "embedded_python"
9-
version = "1.3.0" # of the Conan package, `options.version` is the Python version
9+
version = "1.3.1" # of the Conan package, `options.version` is the Python version
1010
description = "Embedded distribution of Python"
1111
url = "https://www.python.org/"
1212
license = "PSFL"

embedded_python.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
# A hint for `find_package(Python)`
12
set(Python_ROOT_DIR "${CONAN_EMBEDDED_PYTHON_ROOT}/embedded_python")
2-
find_package(Python COMPONENTS Interpreter Development REQUIRED)
3+
4+
if(WIN32) # Extra hint to speed up the find (not needed for correctness)
5+
set(Python_EXECUTABLE "${Python_ROOT_DIR}/python.exe")
6+
endif()
7+
8+
find_package(Python ${CONAN_USER_EMBEDDED_PYTHON_pyversion} EXACT REQUIRED
9+
COMPONENTS Interpreter Development)

0 commit comments

Comments
 (0)