Skip to content
Merged
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
26 changes: 20 additions & 6 deletions mo2_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ function(mo2_python_pip_install TARGET)

string(MAKE_C_IDENTIFIER "${MO2_PACKAGES}" PIP_FILE_LOG)
set(pip_log_file "${CMAKE_CURRENT_BINARY_DIR}/${PIP_FILE_LOG}.log")
set(_success_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_requirements_success.log")

# there is no way to guess a file generated by pip except the log file, but the log
# file is always generated (even on failure), so we run a second command after pip
# (only if pip succeeds) to generate a success file that we can depend on
add_custom_command(
OUTPUT "${pip_log_file}"
OUTPUT "${_success_file}"
COMMAND ${PYTHON_EXE}
-I
-m pip
Expand All @@ -64,11 +68,12 @@ function(mo2_python_pip_install TARGET)
--target="${MO2_DIRECTORY}"
--log="${pip_log_file}"
${MO2_PACKAGES}
COMMAND ${PYTHON_EXE} -c "open('${_success_file}', 'w').close()"
)

set(pip_target_name "${TARGET}_pip_${PIP_FILE_LOG}")

add_custom_target(${pip_target_name} ALL DEPENDS "${pip_log_file}")
add_custom_target(${pip_target_name} ALL DEPENDS "${pip_log_file}" "${_success_file}")
set_target_properties(${pip_target_name} PROPERTIES FOLDER autogen)

add_dependencies(${TARGET} ${pip_target_name})
Expand Down Expand Up @@ -154,20 +159,29 @@ endfunction()
function(mo2_python_requirements TARGET)
cmake_parse_arguments(MO2 "" "LIBDIR" "" ${ARGN})

set(_success_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_requirements_success.log")

mo2_find_python_executable(PYTHON_EXE)

# there is no way to guess a file generated by pip except the log file, but the log
# file is always generated (even on failure), so we run a second command after pip
# (only if pip succeeds) to generate a success file that we can depend on
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pip.log"
OUTPUT "${_success_file}"
COMMAND ${PYTHON_EXE}
-I
-m pip
install --force --upgrade --disable-pip-version-check
install
--force
--upgrade
--disable-pip-version-check
--target="${MO2_LIBDIR}"
--log="${CMAKE_CURRENT_BINARY_DIR}/pip.log"
-r "${PROJECT_SOURCE_DIR}/plugin-requirements.txt"
COMMAND ${PYTHON_EXE} -c "open('${_success_file}', 'w').close()"
DEPENDS "${PROJECT_SOURCE_DIR}/plugin-requirements.txt"
)
add_custom_target("${TARGET}_libs"
ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pip.log")
add_custom_target("${TARGET}_libs" ALL DEPENDS "${_success_file}")
set_target_properties("${TARGET}_libs" PROPERTIES FOLDER autogen)

add_dependencies(${TARGET} "${TARGET}_libs")
Expand Down