Files
cmake_common/python_module_plugin.cmake
T

99 lines
2.4 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")
2020-11-25 18:18:43 +01:00
add_custom_target(libs ALL
2020-11-23 10:58:17 +01:00
COMMAND ${PYTHON_ROOT}/PCbuild/amd64/python.exe
2020-11-25 18:18:43 +01:00
-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}
DEPENDS "${CMAKE_SOURCE_DIR}/plugin-requirements.txt")
2020-11-23 10:58:17 +01:00
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
2021-12-06 05:19:46 -06:00
file(GLOB_RECURSE resources ${src_dir}/*.ui)
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
2021-12-05 03:42:48 -06:00
-m PyQt6.uic.pyuic
2020-11-06 21:19:46 +01:00
-o "${output}"
"${object}"
WORKING_DIRECTORY ${PYTHON_ROOT})
list(APPEND src_files "${output}")
endif()
endforeach()
2021-12-05 03:42:48 -06:00
file(GLOB_RECURSE src_files RELATIVE ${src_dir} ${src_dir}/*.py)
source_group(TREE ${src_dir}
PREFIX src
FILES ${src_dir}/${src_files})
2021-12-05 03:42:48 -06:00
add_custom_target(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE ${src_dir}/${src_files} ${CMAKE_SOURCE_DIR}/plugin-requirements.txt)
2020-11-06 21:19:46 +01:00
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()