File: FindCython.cmake

package info (click to toggle)
cvc5 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 87,260 kB
  • sloc: cpp: 383,850; java: 12,207; python: 12,090; sh: 5,679; ansic: 4,729; lisp: 763; perl: 208; makefile: 38
file content (106 lines) | stat: -rw-r--r-- 3,903 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
###############################################################################
# Top contributors (to current version):
#   Daniel Larraz
#
# This file is part of the cvc5 project.
#
# Copyright (c) 2009-2025 by the authors listed in the file AUTHORS
# in the top-level source directory and their institutional affiliations.
# All rights reserved.  See the file COPYING in the top-level source
# directory for licensing information.
# #############################################################################
#
# Find Cython
# Cython_FOUND - found Cython Python module
##

macro(get_cython_version)
  execute_process(
      COMMAND "${Python_EXECUTABLE}" -c "import Cython; print(Cython.__version__)"
      RESULT_VARIABLE Cython_VERSION_CHECK_RESULT
      OUTPUT_VARIABLE Cython_VERSION
      ERROR_QUIET
      OUTPUT_STRIP_TRAILING_WHITESPACE
  )
endmacro()

get_cython_version()

if (Cython_FIND_REQUIRED)
  set(Cython_FIND_MODE FATAL_ERROR)
else()
  set(Cython_FIND_MODE STATUS)
endif()

if (Cython_VERSION_CHECK_RESULT EQUAL 0)
    set(Cython_FOUND TRUE)
    message(STATUS "Found Cython version: ${Cython_VERSION}")
    if (DEFINED Cython_FIND_VERSION)
        if(Cython_FIND_VERSION_EXACT)
            if (NOT (Cython_VERSION VERSION_EQUAL ${Cython_FIND_VERSION}))
              if(ENABLE_AUTO_DOWNLOAD)
                message(STATUS
                  "Installing module Cython==${Cython_FIND_VERSION}"
                )
                execute_process(
                  COMMAND
                  ${Python_EXECUTABLE} -m pip install Cython==${Cython_FIND_VERSION}
                  RESULT_VARIABLE CYTHON_INSTALL_CMD_EXIT_CODE
                )
                if(CYTHON_INSTALL_CMD_EXIT_CODE)
                  message(${Cython_FIND_MODE}
                    "Could not install Cython==${Cython_FIND_VERSION}")
                else()
                  get_cython_version()
                endif()
              else()
                message(${Cython_FIND_MODE}
                  "Cython version == ${Cython_FIND_VERSION} is required, "
                  "but found version ${Cython_VERSION}")
              endif()
            endif()
        else()
            if (Cython_VERSION VERSION_LESS ${Cython_FIND_VERSION})
              if(ENABLE_AUTO_DOWNLOAD)
                message(STATUS "Upgrading module Cython")
                execute_process(COMMAND
                  ${Python_EXECUTABLE} -m pip install Cython -U
                  RESULT_VARIABLE CYTHON_INSTALL_CMD_EXIT_CODE
                )
                if(CYTHON_INSTALL_CMD_EXIT_CODE)
                  message(${Cython_FIND_MODE}
                    "Could not install Cython >= ${Cython_FIND_VERSION}")
                else()
                  get_cython_version()
                endif()
              else()
                message(${Cython_FIND_MODE}
                  "Cython version >= ${Cython_FIND_VERSION} is required, "
                  "but found version ${Cython_VERSION}")
              endif()
            endif()
        endif()
    endif()
else()
  set(Cython_FOUND FALSE)
  if(ENABLE_AUTO_DOWNLOAD)
    message(STATUS "Installing module Cython")
    execute_process(
      COMMAND ${Python_EXECUTABLE} -m pip install Cython
      RESULT_VARIABLE CYTHON_INSTALL_CMD_EXIT_CODE)
    if(CYTHON_INSTALL_CMD_EXIT_CODE)
      message(${Cython_FIND_MODE} "Could not install module Cython")
    else()
      set(Cython_FOUND TRUE)
      get_cython_version()
    endif()
  else()
    message(${Cython_FIND_MODE}
        "Could not find module Cython for Python "
        "version ${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}. "
        "Make sure to install Cython for this Python version "
        "via \n`${Python_EXECUTABLE} -m pip install Cython'.\n"
        "or use --auto-download to let us install it for you.\n"
        "Note: You need to have pip installed for this Python version.")
  endif()
endif()