From f0d26ddf32f8ee0f77a2407f3fbe738cddbdce9d Mon Sep 17 00:00:00 2001 From: Dean Moldovan Date: Wed, 4 Jan 2017 18:31:23 +0100 Subject: [PATCH] Make Python version selection in CMake more convenient This way a non-CACHE variable can also be used. For example: ``` set(PYBIND11_PYTHON_VERSION ) add_subdirectory(...) ``` --- tools/pybind11Tools.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/pybind11Tools.cmake b/tools/pybind11Tools.cmake index fba76adee9..082afe07bc 100644 --- a/tools/pybind11Tools.cmake +++ b/tools/pybind11Tools.cmake @@ -8,7 +8,9 @@ cmake_minimum_required(VERSION 2.8.12) # Add a CMake parameter for choosing a desired Python version -set(PYBIND11_PYTHON_VERSION "" CACHE STRING "Python version to use for compiling modules") +if(NOT PYBIND11_PYTHON_VERSION) + set(PYBIND11_PYTHON_VERSION "" CACHE STRING "Python version to use for compiling modules") +endif() set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5 3.4) find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} REQUIRED)