From 8a52c42e08c0ed578eebc25522172ec8dc1c815a Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sun, 26 Apr 2020 00:44:58 -0400 Subject: [PATCH] python plugin now handles .ui, .qrc and installing subdirectories set_project_to_run_from_install() was called too early, couldn't use OUTPUT_NAME added libbsarch to requires_library() --- cpp.cmake | 6 ++++ exe.cmake | 7 +++- project.cmake | 1 + python_plugin.cmake | 85 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 97 insertions(+), 2 deletions(-) diff --git a/cpp.cmake b/cpp.cmake index 102ee7f..bf4eb78 100644 --- a/cpp.cmake +++ b/cpp.cmake @@ -79,6 +79,7 @@ macro(cpp_pre_target) ${LZ4_ROOT}/bin ${ZLIB_ROOT}/lib ${LOOT_PATH} + ${LIBBSARCH_ROOT} ) endmacro() @@ -229,6 +230,11 @@ function(requires_library) elseif(${name} STREQUAL "python") target_include_directories(${PROJECT_NAME} PRIVATE ${PYTHON_ROOT}/Include) + elseif(${name} STREQUAL "libbsarch") + target_include_directories(${PROJECT_NAME} PRIVATE + ${LIBBSARCH_ROOT}) + + target_link_libraries(${PROJECT_NAME} libbsarch libbsarch_OOP) else() message(FATAL_ERROR "unknown library ${name}") endif() diff --git a/exe.cmake b/exe.cmake index 0e285f2..01ecc13 100644 --- a/exe.cmake +++ b/exe.cmake @@ -7,7 +7,11 @@ endif() function(set_project_to_run_from_install) set(vcxproj_user_file "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.vcxproj.user") + get_target_property(output_name ${PROJECT_NAME} OUTPUT_NAME) + if("${output_name}" STREQUAL "output_name-NOTFOUND") + set(output_name ${PROJECT_NAME}) + endif() if(NOT EXISTS ${vcxproj_user_file}) file(WRITE ${vcxproj_user_file} @@ -81,13 +85,14 @@ macro(do_src) cpp_pre_target() add_executable(${PROJECT_NAME} WIN32 ${input_files}) - set_project_to_run_from_install() if(DEFINED executable_name) set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${executable_name}) endif() + set_project_to_run_from_install() + cpp_post_target() install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${install_dir}) diff --git a/project.cmake b/project.cmake index c0a4a33..35688d4 100644 --- a/project.cmake +++ b/project.cmake @@ -58,6 +58,7 @@ required_variable(LZ4_ROOT) required_variable(ZLIB_ROOT) required_variable(PYTHON_ROOT) required_variable(SEVENZ_ROOT) +required_variable(LIBBSARCH_ROOT) required_variable(CMAKE_INSTALL_PREFIX) get_real_path(modorganizer_build_path "${CMAKE_CURRENT_LIST_DIR}/../..") diff --git a/python_plugin.cmake b/python_plugin.cmake index 09b47e3..5e2fade 100644 --- a/python_plugin.cmake +++ b/python_plugin.cmake @@ -11,6 +11,89 @@ macro(do_project) endmacro() +# sets `var` to TRUE if the given directory should be installed +# +function(is_interesting_python_dir var dir) + file(GLOB_RECURSE dir_content "${dir}/*.py") + + if("X${dir_content}" STREQUAL "X") + set(${var} FALSE PARENT_SCOPE) + else() + set(${var} TRUE PARENT_SCOPE) + endif() +endfunction() + + macro(do_src) - install(FILES ${source_files} DESTINATION ${install_dir}) + # this copies all the .py files that are directly in src/ into + # ${install_dir}/ + # + # any folder that contains at least one .py file (recursive) is copied in + # bin/plugins/data + + + # everything in the src directory + file(GLOB everything ${CMAKE_SOURCE_DIR}/src/*) + + foreach(object ${everything}) + if(IS_DIRECTORY "${object}") + # only copy interesting directories + is_interesting_python_dir(is_interesting "${object}") + if (${is_interesting}) + list(APPEND data_dirs "${object}") + endif() + else() + get_filename_component(ext "${object}" LAST_EXT) + + if("${ext}" STREQUAL ".py") + # copy .py files directly + list(APPEND src_files "${object}") + elseif("${ext}" STREQUAL ".ui") + # process .ui files and copy the resulting .py in data + get_filename_component(name "${object}" NAME_WLE) + set(output "${CMAKE_CURRENT_BINARY_DIR}/${name}.py") + + execute_process( + COMMAND ${PYTHON_ROOT}/PCbuild/amd64/python.exe + -m PyQt5.uic.pyuic + -o "${output}" + "${object}" + WORKING_DIRECTORY ${PYTHON_ROOT}) + + list(APPEND data_files "${output}") + elseif("${ext}" STREQUAL ".qrc") + # process .qrc files and copy the resulting .py in data + get_filename_component(name "${object}" NAME_WLE) + set(output "${CMAKE_CURRENT_BINARY_DIR}/${name}_rc.py") + + execute_process( + COMMAND ${PYTHON_ROOT}/PCbuild/amd64/python.exe + -m PyQt5.pyrcc_main + -o "${output}" + "${object}" + WORKING_DIRECTORY ${PYTHON_ROOT}) + + list(APPEND data_files "${output}") + elseif("${ext}" STREQUAL ".json") + # copy .json files in data + list(APPEND data_files "${object}") + endif() + endif() + endforeach() + + # files that go directly in bin/plugins + install( + FILES ${src_files} + DESTINATION ${install_dir}) + + # files that go in bin/plugins/data + install( + FILES ${data_files} + DESTINATION ${install_dir}/data) + + # directories that go in bin/plugins/data + install( + DIRECTORY ${data_dirs} + DESTINATION ${install_dir}/data + FILES_MATCHING PATTERN ".py") endmacro()