Files
cmake_common/python_module_plugin.cmake
T

108 lines
2.7 KiB
CMake
Raw Normal View History

2020-11-06 21:19:46 +01:00
cmake_minimum_required(VERSION 3.16)
include(${CMAKE_CURRENT_LIST_DIR}/python.cmake)
if(NOT DEFINED install_dir)
2020-11-23 10:58:17 +01:00
set(install_dir "bin/plugins/${CMAKE_PROJECT_NAME}")
2020-11-06 21:19:46 +01:00
endif()
2020-11-23 10:58:17 +01:00
if(NOT DEFINED res_dir)
set(res_dir res)
endif()
if(NOT DEFINED lib_dir)
set(lib_dir lib)
endif()
2020-11-06 21:19:46 +01:00
macro(do_project)
do_python_project()
2020-11-23 10:58:17 +01:00
# install requirements if there are any
if(EXISTS "${CMAKE_SOURCE_DIR}/plugin-requirements.txt")
add_custom_command(
OUTPUT "${CMAKE_SOURCE_DIR}/${lib_dir}/"
COMMAND ${PYTHON_ROOT}/PCbuild/amd64/python.exe
-I
-m pip
install --force --disable-pip-version-check
--target="${CMAKE_SOURCE_DIR}/${lib_dir}"
-r "${CMAKE_SOURCE_DIR}/plugin-requirements.txt"
WORKING_DIRECTORY ${PYTHON_ROOT})
add_custom_target(libs ALL DEPENDS "${CMAKE_SOURCE_DIR}/${lib_dir}")
endif()
2020-11-06 21:19:46 +01:00
endmacro()
macro(do_src)
# this copies all the .py files into ${install_dir}/${PROJECT_NAME}
2020-11-23 10:58:17 +01:00
if(EXISTS "${CMAKE_SOURCE_DIR}/__init__.py")
set(src_dir ${CMAKE_SOURCE_DIR})
else()
set(src_dir ${CMAKE_SOURCE_DIR}/src)
endif()
2020-11-06 21:19:46 +01:00
# resources in the src directory
2020-11-23 10:58:17 +01:00
file(GLOB_RECURSE resources ${src_dir}/*.ui ${src_dir}/*.qrc)
2020-11-06 21:19:46 +01:00
foreach(object ${resources})
get_filename_component(ext "${object}" LAST_EXT)
if("${ext}" STREQUAL ".ui")
# process .ui files and copy the resulting .py in data
get_filename_component(name "${object}" NAME_WLE)
get_filename_component(folder "${object}" DIRECTORY)
set(output "${folder}/${name}.py")
execute_process(
COMMAND ${PYTHON_ROOT}/PCbuild/amd64/python.exe
-I
-m PyQt5.uic.pyuic
-o "${output}"
"${object}"
WORKING_DIRECTORY ${PYTHON_ROOT})
list(APPEND src_files "${output}")
elseif("${ext}" STREQUAL ".qrc")
# process .qrc files and copy the resulting .py in data
get_filename_component(name "${object}" NAME_WLE)
get_filename_component(folder "${object}" DIRECTORY)
set(output "${folder}/${name}.py")
execute_process(
COMMAND ${PYTHON_ROOT}/PCbuild/amd64/python.exe
-I
-m PyQt5.pyrcc_main
-o "${output}"
"${object}"
WORKING_DIRECTORY ${PYTHON_ROOT})
list(APPEND src_files "${output}")
endif()
endforeach()
file(GLOB_RECURSE src_files RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/*.py)
2020-11-23 10:58:17 +01:00
# directories that go in bin/plugins/${name}
2020-11-06 21:19:46 +01:00
install(
2020-11-23 10:58:17 +01:00
DIRECTORY "${src_dir}/"
2020-11-06 21:19:46 +01:00
DESTINATION ${install_dir}
FILES_MATCHING PATTERN "*.py"
PATTERN ".git*" EXCLUDE
PATTERN "vsbuild" EXCLUDE)
2020-11-23 10:58:17 +01:00
# copy the resource directory if it exists
if(EXISTS "${CMAKE_SOURCE_DIR}/${res_dir}")
install(
DIRECTORY "${CMAKE_SOURCE_DIR}/${res_dir}"
DESTINATION ${install_dir}
)
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/plugin-requirements.txt")
install(
DIRECTORY "${CMAKE_SOURCE_DIR}/${lib_dir}"
DESTINATION ${install_dir}
)
endif()
2020-11-06 21:19:46 +01:00
endmacro()