mirror of
https://github.com/ModOrganizer2/cmake_common.git
synced 2026-07-27 14:06:46 -07:00
Improve Python module installation.
This commit is contained in:
@@ -2,19 +2,46 @@ cmake_minimum_required(VERSION 3.16)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/python.cmake)
|
||||
|
||||
if(NOT DEFINED install_dir)
|
||||
set(install_dir bin/plugins)
|
||||
set(install_dir "bin/plugins/${CMAKE_PROJECT_NAME}")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED res_dir)
|
||||
set(res_dir res)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED lib_dir)
|
||||
set(lib_dir lib)
|
||||
endif()
|
||||
|
||||
macro(do_project)
|
||||
do_python_project()
|
||||
|
||||
# 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()
|
||||
endmacro()
|
||||
|
||||
macro(do_src)
|
||||
# this copies all the .py files into ${install_dir}/${PROJECT_NAME}
|
||||
|
||||
if(EXISTS "${CMAKE_SOURCE_DIR}/__init__.py")
|
||||
set(src_dir ${CMAKE_SOURCE_DIR})
|
||||
else()
|
||||
set(src_dir ${CMAKE_SOURCE_DIR}/src)
|
||||
endif()
|
||||
|
||||
# resources in the src directory
|
||||
file(GLOB_RECURSE resources ${CMAKE_SOURCE_DIR}/*.ui ${CMAKE_SOURCE_DIR}/*.qrc)
|
||||
file(GLOB_RECURSE resources ${src_dir}/*.ui ${src_dir}/*.qrc)
|
||||
|
||||
foreach(object ${resources})
|
||||
get_filename_component(ext "${object}" LAST_EXT)
|
||||
@@ -54,11 +81,27 @@ macro(do_src)
|
||||
|
||||
file(GLOB_RECURSE src_files RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/*.py)
|
||||
|
||||
# # directories that go in bin/plugins/${name}
|
||||
# directories that go in bin/plugins/${name}
|
||||
install(
|
||||
DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
DIRECTORY "${src_dir}/"
|
||||
DESTINATION ${install_dir}
|
||||
FILES_MATCHING PATTERN "*.py"
|
||||
PATTERN ".git*" EXCLUDE
|
||||
PATTERN "vsbuild" EXCLUDE)
|
||||
|
||||
# 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()
|
||||
|
||||
endmacro()
|
||||
|
||||
Reference in New Issue
Block a user