-
Notifications
You must be signed in to change notification settings - Fork 2
/
FindPoetry.cmake
64 lines (52 loc) · 1.87 KB
/
FindPoetry.cmake
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
#[=======================================================================[.rst:
FindPoetry.cmake
---------------
This module is intended for use with ``find_package`` and should not be imported on
its own.
It will download and install the poetry package manager.
Usage
+++++
To use this module, make sure you're setting the cmake module path to this
directory and call
```
find_package(Poetry VERSION version)
```
Output Variables
++++++++++++++++
- ``Poetry_EXECUTABLE`` path to the poetry executable
#]=======================================================================]
include(FetchContent)
string(REPLACE "." "_" "_poetry_archive_version_component" "${Poetry_FIND_VERSION}")
message(STATUS "Checking for installed Python package")
set(Python_FIND_UNVERSIONED_NAMES "FIRST") # Helps find pyenv if installed
find_package(Python COMPONENTS Interpreter Development)
if(NOT ${Python_FOUND})
message(FATAL_ERROR "Could not find installed python version. Cannot install poetry. Exiting...")
else()
message(STATUS "Found Python executable at: ${Python_EXECUTABLE}")
endif()
set(LOCALINSTALL_POETRY_DIR "${CMAKE_SOURCE_DIR}/stm32-tools/poetry")
message(STATUS "Downloading poetry install script to: ${LOCALINSTALL_POETRY_DIR}")
message(STATUS "Installing Poetry")
FetchContent_Declare(
POETRY_LOCALINSTALL
PREFIX ${LOCALINSTALL_POETRY_DIR}
DOWNLOAD_DIR ${LOCALINSTALL_POETRY_DIR}
URL "https://install.python-poetry.org/"
DOWNLOAD_NAME "install_poetry.py"
DOWNLOAD_NO_EXTRACT True
)
FetchContent_MakeAvailable(POETRY_LOCALINSTALL)
set(ENV{POETRY_HOME} ${LOCALINSTALL_POETRY_DIR})
set(ENV{POETRY_VERSION} ${Poetry_FIND_VERSION})
execute_process(COMMAND ${Python_EXECUTABLE} install_poetry.py
WORKING_DIRECTORY ${LOCALINSTALL_POETRY_DIR}
)
unset(Poetry_EXECUTABLE CACHE)
find_program(
Poetry_EXECUTABLE
poetry
PATHS ${CMAKE_SOURCE_DIR}/stm32-tools/poetry/bin
NO_DEFAULT_PATH
REQUIRED
)