Skip to content

Commit 74124fa

Browse files
committed
Add an alternative method for cmake 3.15+ with fewer side-effects
1 parent 82a9130 commit 74124fa

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Python_FIND_REGISTRY and CMAKE_FIND_FRAMEWORK should be set to NEVER:
22
# - https://cmake.org/cmake/help/v3.13/module/FindPython.html#hints
3+
# From 3.15 use Python_FIND_VIRTUALENV = ONLY as it has fewer side effects
4+
# - https://cmake.org/cmake/help/v3.15/module/FindPython.html#hints
35
cmake_minimum_required(VERSION 3.13)
46

57
project(hunter_venv)

cmake/template/Config.cmake.in

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,21 @@ get_filename_component(
1313
ABSOLUTE
1414
)
1515

16-
set(CMAKE_FIND_FRAMEWORK NEVER CACHE STRING "...")
17-
if(NOT "${CMAKE_FIND_FRAMEWORK}" STREQUAL "NEVER")
18-
message(FATAL_ERROR "CMAKE_FIND_FRAMEWORK is not NEVER")
19-
endif()
16+
if(CMAKE_VERSION VERSION_LESS "3.15.0")
17+
set(CMAKE_FIND_FRAMEWORK NEVER CACHE STRING "...")
18+
if(NOT "${CMAKE_FIND_FRAMEWORK}" STREQUAL "NEVER")
19+
message(FATAL_ERROR "CMAKE_FIND_FRAMEWORK is not NEVER")
20+
endif()
2021

21-
set(Python_FIND_REGISTRY NEVER CACHE STRING "...")
22-
if(NOT "${Python_FIND_REGISTRY}" STREQUAL "NEVER")
23-
message(FATAL_ERROR "Python_FIND_REGISTRY is not NEVER")
22+
set(Python_FIND_REGISTRY NEVER CACHE STRING "...")
23+
if(NOT "${Python_FIND_REGISTRY}" STREQUAL "NEVER")
24+
message(FATAL_ERROR "Python_FIND_REGISTRY is not NEVER")
25+
endif()
26+
else()
27+
set(Python_FIND_VIRTUALENV ONLY CACHE STRING "...")
28+
if(NOT "${Python_FIND_VIRTUALENV}" STREQUAL "ONLY")
29+
message(FATAL_ERROR "Python_FIND_VIRTUALENV is not ONLY")
30+
endif()
2431
endif()
2532

2633
if("@HUNTER_VENV_USE_2@")
@@ -32,9 +39,16 @@ if("@HUNTER_VENV_USE_2@")
3239
set(Python2_ROOT_DIR "${__hunter_venv_root}")
3340
endif()
3441

35-
set(Python2_FIND_REGISTRY NEVER CACHE STRING "...")
36-
if(NOT "${Python2_FIND_REGISTRY}" STREQUAL "NEVER")
37-
message(FATAL_ERROR "Python2_FIND_REGISTRY is not NEVER")
42+
if(CMAKE_VERSION VERSION_LESS "3.15.0")
43+
set(Python2_FIND_REGISTRY NEVER CACHE STRING "...")
44+
if(NOT "${Python2_FIND_REGISTRY}" STREQUAL "NEVER")
45+
message(FATAL_ERROR "Python2_FIND_REGISTRY is not NEVER")
46+
endif()
47+
else()
48+
set(Python2_FIND_VIRTUALENV ONLY CACHE STRING "...")
49+
if(NOT "${Python2_FIND_VIRTUALENV}" STREQUAL "ONLY")
50+
message(FATAL_ERROR "Python2_FIND_VIRTUALENV is not ONLY")
51+
endif()
3852
endif()
3953

4054
find_package(Python "@HUNTER_VENV_PYTHON_VERSION@" EXACT QUIET REQUIRED)
@@ -50,9 +64,16 @@ if("@HUNTER_VENV_USE_3@")
5064
set(Python3_ROOT_DIR "${__hunter_venv_root}")
5165
endif()
5266

53-
set(Python3_FIND_REGISTRY NEVER CACHE STRING "...")
54-
if(NOT "${Python3_FIND_REGISTRY}" STREQUAL "NEVER")
55-
message(FATAL_ERROR "Python3_FIND_REGISTRY is not NEVER")
67+
if(CMAKE_VERSION VERSION_LESS "3.15.0")
68+
set(Python3_FIND_REGISTRY NEVER CACHE STRING "...")
69+
if(NOT "${Python3_FIND_REGISTRY}" STREQUAL "NEVER")
70+
message(FATAL_ERROR "Python3_FIND_REGISTRY is not NEVER")
71+
endif()
72+
else()
73+
set(Python3_FIND_VIRTUALENV ONLY CACHE STRING "...")
74+
if(NOT "${Python3_FIND_VIRTUALENV}" STREQUAL "ONLY")
75+
message(FATAL_ERROR "Python3_FIND_VIRTUALENV is not ONLY")
76+
endif()
5677
endif()
5778

5879
find_package(Python "@HUNTER_VENV_PYTHON_VERSION@" EXACT QUIET REQUIRED)

0 commit comments

Comments
 (0)