File: UnversionedNames.cmake

package info (click to toggle)
cmake 4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 152,348 kB
  • sloc: ansic: 403,894; cpp: 303,807; sh: 4,097; python: 3,582; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 108; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (65 lines) | stat: -rw-r--r-- 2,271 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

# check if it is possible to find python with a generic name
find_program(UNVERSIONED_Python3 NAMES python3)

if (NOT UNVERSIONED_Python3)
  # no generic name available
  # test cannot be done
  return()
endif()

# search with default configuration
find_package(Python3 REQUIRED COMPONENTS Interpreter)

if (Python3_EXECUTABLE STREQUAL UNVERSIONED_Python3)
  # default configuration pick-up the generic name
  # test cannot be completed
  return()
endif()

unset(Python3_EXECUTABLE)
# Force now to search first for  generic name
set(Python3_FIND_UNVERSIONED_NAMES FIRST)

set(Python3_FIND_FRAMEWORK NEVER)

find_package(Python3 REQUIRED COMPONENTS Interpreter)

if (NOT Python3_EXECUTABLE STREQUAL UNVERSIONED_Python3)
  message(SEND_ERROR "Found unexpected interpreter ${Python3_EXECUTABLE} instead of ${UNVERSIONED_Python3}")
endif()

# To check value 'NEVER", creates  directory holding a symlink to the generic name
file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/bin")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
file(CREATE_LINK "${UNVERSIONED_Python3}" "${CMAKE_CURRENT_BINARY_DIR}/bin/python3" SYMBOLIC)

unset(Python3_EXECUTABLE)
set(Python3_FIND_UNVERSIONED_NAMES FIRST)
set(Python3_ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
# First search: generic name must be found
find_package(Python3 REQUIRED COMPONENTS Interpreter)

if (NOT Python3_EXECUTABLE STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/bin/python3")
  message(FATAL_ERROR "Found unexpected interpreter ${Python3_EXECUTABLE} instead of ${CMAKE_CURRENT_BINARY_DIR}/bin/python3")
endif()

unset(Python3_EXECUTABLE)
set(Python3_FIND_UNVERSIONED_NAMES LAST)

# Second search: generic name must be found
find_package(Python3 REQUIRED COMPONENTS Interpreter)

if (NOT Python3_EXECUTABLE STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/bin/python3")
  message(FATAL_ERROR "Found unexpected interpreter ${Python3_EXECUTABLE} instead of ${CMAKE_CURRENT_BINARY_DIR}/bin/python3")
endif()

unset(Python3_EXECUTABLE)
set(Python3_FIND_UNVERSIONED_NAMES NEVER)

# Third search: generic name must NOT be found
find_package(Python3 REQUIRED COMPONENTS Interpreter)

if (Python3_EXECUTABLE STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/bin/python3")
  message(FATAL_ERROR "Found unexpected interpreter ${Python3_EXECUTABLE}")
endif()