Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Python3 detection #160

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,67 @@ endif()

enable_language(C CXX ASM)

execute_process(COMMAND cmake --version OUTPUT_VARIABLE TEST_CMAKE_VERSION)
message(STATUS "Using CMake Version: ${TEST_CMAKE_VERSION}")

# Find a suitable version of Python3 higher than 3.8.
set(PYTHON_VERSIONS 3.9;3.10;3.11;3.12;3.13)
set(GOOD_PYTHON_FOUND FALSE)

message(STATUS: "Python Before Loop:")
message(STATUS: "Python3_FOUND: ${Python3_FOUND}")
message(STATUS: "Python3_Interpreter_FOUND: ${Python3_Interpreter_FOUND}")

foreach(X IN LISTS PYTHON_VERSIONS)
message(STATUS "Searching for Python Version ${X} ...")

set(Python3_REQUIRED_VERSION ${X} EXACT)
find_package(Python3 ${X} EXACT QUIET COMPONENTS Interpreter OPTIONAL_COMPONENTS Development)

if (NOT ${Python3_FOUND})
message(STATUS "PYTHON VERSION ${X} NOT FOUND.")
set(GOOD_PYTHON_FOUND FALSE)
continue()
endif()

if (NOT ${Python3_Interpreter_FOUND})
message(STATUS "PYTHON INTERPRETER VERSION ${X} NOT FOUND.")
set(GOOD_PYTHON_FOUND FALSE)
continue()
else()
set(GOOD_PYTHON_FOUND TRUE)
endif()

if (${Python3_VERSION_MINOR} LESS "9")
message(STATUS "Minor Version ${Python3_VERSION_MINOR} not a candidate.")
set(GOOD_PYTHON_FOUND FALSE)
continue()
else()
if (NOT ${Python3_Interpreter_FOUND})
message(STATUS "Could not find a Python Interpreter for Version ${X}")
set(GOOD_PYTHON_FOUND FALSE)
continue()
else()
set(GOOD_PYTHON_FOUND TRUE)
endif()
endif()

if (${Python3_FOUND} AND ${Python3_Interpreter_FOUND})
message(STATUS "Found Python Version ${Python3_VERSION}.")
set(GOOD_PYTHON_FOUND TRUE)
break()
endif()
endforeach()

if (NOT ${GOOD_PYTHON_FOUND})
message(FATAL_ERROR "Could not find a suitable version of Python.")
endif()

message(STATUS: "Python After Loop:")
message(STATUS: "Python3_FOUND: ${Python3_FOUND}")
message(STATUS: "Python3_Interpreter_FOUND: ${Python3_Interpreter_FOUND}")

# Find external packages
find_package(Python COMPONENTS Interpreter Development)
find_package(qasm REQUIRED)
find_package(mpc REQUIRED)
find_package(mpfr REQUIRED)
Expand Down
Loading