Skip to content

Commit

Permalink
Proposal/ev cli pip installation (#15)
Browse files Browse the repository at this point in the history
* initial

Signed-off-by: aw <[email protected]>

---------

Signed-off-by: Kai-Uwe Hermann <[email protected]>
Signed-off-by: aw <[email protected]>
Co-authored-by: aw <[email protected]>
  • Loading branch information
hikinggrass and a-w50 authored Oct 16, 2024
1 parent 3aec8e3 commit 1e22574
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions python-package-helpers.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
function (ev_add_pip_package)
set(one_value_args
NAME
SOURCE_DIRECTORY
)

cmake_parse_arguments(
"args"
"" # no optional arguments
"${one_value_args}"
""
${ARGN}
)

if ("${args_NAME}" STREQUAL "")
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: NAME is required")
endif()

cmake_path(ABSOLUTE_PATH args_SOURCE_DIRECTORY NORMALIZE)

set(TARGET_NAME "ev_pip_package_${args_NAME}")
add_custom_target(${TARGET_NAME})

set_target_properties(${TARGET_NAME}
PROPERTIES
SOURCE_DIRECTORY "${args_SOURCE_DIRECTORY}"
)
endfunction()

function (ev_install_pip_package)
set(options
LOCAL
FORCE
)

set(one_value_args
NAME
)

cmake_parse_arguments(
"args"
"${options}"
"${one_value_args}"
""
${ARGN}
)

set(TARGET_NAME "ev_pip_package_${args_NAME}")

if (NOT TARGET ${TARGET_NAME})
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: target ${TARGET_NAME} for package ${args_NAME} does not exist")
endif()

get_target_property(SOURCE_DIRECTORY ${TARGET_NAME} SOURCE_DIRECTORY)

# NOTE (aw): probably we also want to directly forward arguments
set(PIP_INSTALL_ARGS "")
if (args_LOCAL)
list(APPEND PIP_INSTALL_ARGS --user)
endif()
if (args_FORCE)
list(APPEND PIP_INSTALL_ARGS --force-reinstall)
endif()

# FIXME (aw): check wether a check done file is necessary here
# if so, it should be inside a separate function
# discussion of update behavior is needed before

execute_process(
COMMAND
${Python3_EXECUTABLE} -m pip install ${PIP_INSTALL_ARGS} .
WORKING_DIRECTORY
${SOURCE_DIRECTORY}

)
endfunction()

function (ev_create_pip_install_dist_target)
set(oneValueArgs
PACKAGE_NAME
Expand Down

0 comments on commit 1e22574

Please sign in to comment.