From e01f49246298f3fb7f825a911f1e8d838cda83d7 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 21 Sep 2020 18:34:48 -0400 Subject: [PATCH] fix: Add a nice CMake error when Interpreter component is missing. (#2519) Closes #2515, found by @rhjdjong --- tools/pybind11NewTools.cmake | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake index 27eb4d920..8710cff58 100644 --- a/tools/pybind11NewTools.cmake +++ b/tools/pybind11NewTools.cmake @@ -70,6 +70,16 @@ if(PYBIND11_MASTER_PROJECT) endif() endif() +# If a user finds Python, they may forget to include the Interpreter component +# and the following two steps require it. It is highly recommended by CMake +# when finding development libraries anyway, so we will require it. +if(NOT DEFINED ${_Python}_EXECUTABLE) + message( + FATAL_ERROR + "${_Python} was found without the Interpreter component. Pybind11 requires this component.") + +endif() + # Debug check - see https://stackoverflow.com/questions/646518/python-how-to-detect-debug-Interpreter execute_process( COMMAND "${${_Python}_EXECUTABLE}" "-c" "import sys; sys.exit(hasattr(sys, 'gettotalrefcount'))"