Skip to content

Commit

Permalink
Move to VCPKG.
Browse files Browse the repository at this point in the history
* Minor cleaning of CMakeLists.txt. Fix C++ warnings and Qt deprecation.
* Avoid using Python from virtual environment.
  • Loading branch information
Holt59 committed Aug 9, 2024
1 parent e11d5ec commit 7cca701
Show file tree
Hide file tree
Showing 45 changed files with 536 additions and 231 deletions.
50 changes: 40 additions & 10 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,50 @@ on:
pull_request:
types: [opened, synchronize, reopened]

env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"

jobs:
build:
runs-on: windows-2022
steps:
- name: Build Plugin Python
id: build-plugin-python
uses: ModOrganizer2/build-with-mob-action@master
# https://learn.microsoft.com/en-us/vcpkg/consume/binary-caching-github-actions-cache
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
mo2-third-parties: gtest python spdlog boost sip pyqt pybind11
mo2-dependencies: cmake_common uibase
mo2-cmake-command: -DPLUGIN_PYTHON_TESTS=1 ..
- name: Build Plugin Python Tests
run: cmake --build vsbuild --config RelWithDebInfo -j4 --target python-tests --target runner-tests
working-directory: ${{ steps.build-plugin-python.outputs.working-directory }}
setup-python: false
version: 6.7.1
modules:
cache: true

- uses: actions/checkout@v4

- name: "Set environmental variables"
shell: bash
run: |
echo "VCPKG_ROOT=$VCPKG_INSTALLATION_ROOT" >> $GITHUB_ENV
- name: Configure Plugin Python build
shell: pwsh
run: |
cmake --preset vs2022-windows-standalone `
"-DCMAKE_PREFIX_PATH=${env:QT_ROOT_DIR}\msvc2019_64" `
-DPLUGIN_PYTHON_TESTING=ON
- name: Build Plugin Python
run: cmake --build vsbuild --config RelWithDebInfo --verbose `
--target python-tests --target runner-tests --target proxy

- name: Test Plugin Python
run: ctest --test-dir vsbuild -C RelWithDebInfo --output-on-failure
working-directory: ${{ steps.build-plugin-python.outputs.working-directory }}
40 changes: 14 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,32 @@ cmake_minimum_required(VERSION 3.16)

cmake_policy(SET CMP0144 NEW)

if(DEFINED DEPENDENCIES_DIR)
include(${DEPENDENCIES_DIR}/modorganizer_super/cmake_common/mo2.cmake)
else()
include(${CMAKE_CURRENT_LIST_DIR}/../cmake_common/mo2.cmake)
endif()

project(plugin_python CXX)

set(PYTHON_BUILD_PATH ${PYTHON_ROOT}/PCBuild/amd64)
set(Python_FIND_VIRTUALENV STANDARD)

# find Python - lots of "Hints" since we have a weird setup
set(Python_USE_STATIC_LIBS False)
set(Python_INCLUDE_DIR ${PYTHON_ROOT}/Include)
set(Python_EXECUTABLE ${PYTHON_BUILD_PATH}/python.exe)
if (EXISTS "${PYTHON_BUILD_PATH}/python_d.exe")
set(Python_EXECUTABLE ${PYTHON_BUILD_PATH}/python_d.exe)
endif()
file(GLOB Python_LIBRARY ${PYTHON_BUILD_PATH}/python[0-9][0-9]*.lib)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
# find Python before include mo2-cmake, otherwise this will trigger a bunch of CMP0111
# due to the imported configuration mapping variables defined in mo2.cmake
find_package(Python ${MO2_PYTHON_VERSION} COMPONENTS Interpreter Development REQUIRED)
find_package(pybind11 CONFIG REQUIRED)

# pybind11 needs uppercase (at least EXECUTABLE and LIBRARY)
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
set(PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIR})
set(PYTHON_LIBRARY ${Python_LIBRARY})
find_package(mo2-cmake CONFIG REQUIRED)

get_filename_component(Python_HOME ${Python_EXECUTABLE} PATH)
set(Python_DLL_DIR "${Python_HOME}/DLLs")
set(Python_LIB_DIR "${Python_HOME}/Lib")

mo2_python_install_pyqt()

# useful for naming DLL, zip, etc. (3.10 -> 310)
set(Python_VERSION_SHORT ${Python_VERSION_MAJOR}${Python_VERSION_MINOR})

# pybind11
add_subdirectory(${MO2_BUILD_PATH}/pybind11 ${CMAKE_CURRENT_BINARY_DIR}/pybind11)

# projects
add_subdirectory(src)
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT proxy)

# tests (if requested)
set(PLUGIN_PYTHON_TESTS ${PLUGIN_PYTHON_TESTS} CACHE BOOL "build tests for plugin_python")
if (PLUGIN_PYTHON_TESTS)
set(PLUGIN_PYTHON_TESTING ${BUILD_TESTING} CACHE BOOL "build tests for plugin_python")
if (PLUGIN_PYTHON_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
73 changes: 73 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"configurePresets": [
{
"errors": {
"deprecated": true
},
"hidden": true,
"name": "cmake-dev",
"warnings": {
"deprecated": true,
"dev": true
}
},
{
"cacheVariables": {
"VCPKG_MANIFEST_NO_DEFAULT_FEATURES": {
"type": "BOOL",
"value": "ON"
}
},
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"hidden": true,
"name": "vcpkg"
},
{
"cacheVariables": {
"VCPKG_MANIFEST_FEATURES": {
"type": "STRING",
"value": "testing"
}
},
"hidden": true,
"inherits": ["vcpkg"],
"name": "vcpkg-dev"
},
{
"binaryDir": "${sourceDir}/vsbuild",
"architecture": {
"strategy": "set",
"value": "x64"
},
"cacheVariables": {
"CMAKE_CXX_FLAGS": "/EHsc /MP /W4",
"VCPKG_TARGET_TRIPLET": {
"type": "STRING",
"value": "x64-windows-static-md"
}
},
"generator": "Visual Studio 17 2022",
"inherits": ["cmake-dev", "vcpkg-dev"],
"name": "vs2022-windows",
"toolset": "v143"
},
{
"cacheVariables": {
"VCPKG_MANIFEST_FEATURES": {
"type": "STRING",
"value": "standalone;testing"
}
},
"inherits": "vs2022-windows",
"name": "vs2022-windows-standalone"
}
],
"buildPresets": [
{
"name": "vs2022-windows",
"resolvePackageReferences": "on",
"configurePreset": "vs2022-windows"
}
],
"version": 4
}
34 changes: 30 additions & 4 deletions src/mobase/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
cmake_minimum_required(VERSION 3.16)

find_package(Qt6 COMPONENTS Core)
find_package(mo2-uibase CONFIG REQUIRED)

pybind11_add_module(mobase MODULE)
mo2_configure_library(mobase
SOURCE_TREE
mo2_default_source_group()
mo2_configure_target(mobase
NO_SOURCES
WARNINGS 4
EXTERNAL_WARNINGS 4
AUTOMOC ON
TRANSLATIONS OFF
PRIVATE_DEPENDS uibase Qt::Core
)
target_link_libraries(mobase PRIVATE pybind11::qt pybind11::utils)
mo2_target_sources(mobase
FOLDER src
PRIVATE
deprecation.cpp
deprecation.h
mobase.cpp
pybind11_all.h
)
mo2_target_sources(mobase
FOLDER src/wrappers
PRIVATE
./wrappers/basic_classes.cpp
./wrappers/game_features.cpp
./wrappers/known_folders.h
./wrappers/pyfiletree.cpp
./wrappers/pyfiletree.h
./wrappers/pyplugins.cpp
./wrappers/pyplugins.h
./wrappers/utils.cpp
./wrappers/widgets.cpp
./wrappers/wrappers.cpp
./wrappers/wrappers.h
)
target_link_libraries(mobase PRIVATE pybind11::qt pybind11::utils mo2::uibase Qt6::Core)
2 changes: 1 addition & 1 deletion src/mobase/deprecation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <QCoreApplication>

#include "log.h"
#include <uibase/log.h>

namespace py = pybind11;

Expand Down
17 changes: 0 additions & 17 deletions src/mobase/mobase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,6 @@
#include "wrappers/pyfiletree.h"
#include "wrappers/wrappers.h"

// TODO: remove these include (only for testing)
#include <QDir>
#include <QFile>
#include <QWidget>
#include <iplugin.h>
#include <iplugindiagnose.h>
#include <ipluginfilemapper.h>
#include <iplugingame.h>
#include <iplugininstaller.h>
#include <iplugininstallersimple.h>
#include <ipluginlist.h>
#include <ipluginmodpage.h>
#include <ipluginpreview.h>
#include <iplugintool.h>
#include <isavegame.h>
#include <isavegameinfowidget.h>

using namespace MOBase;
namespace py = pybind11;

Expand Down
6 changes: 3 additions & 3 deletions src/mobase/pybind11_all.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include "pybind11_utils/shared_cpp_owner.h"
#include "pybind11_utils/smart_variant_wrapper.h"

#include <game_feature.h>
#include <isavegame.h>
#include <pluginrequirements.h>
#include <uibase/game_features/game_feature.h>
#include <uibase/isavegame.h>
#include <uibase/pluginrequirements.h>

namespace mo2::python {

Expand Down
30 changes: 15 additions & 15 deletions src/mobase/wrappers/basic_classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

#include <format>

#include <executableinfo.h>
#include <filemapping.h>
#include <guessedvalue.h>
#include <idownloadmanager.h>
#include <igamefeatures.h>
#include <iinstallationmanager.h>
#include <imodinterface.h>
#include <imodrepositorybridge.h>
#include <imoinfo.h>
#include <iplugin.h>
#include <iplugindiagnose.h>
#include <iplugingame.h>
#include <ipluginlist.h>
#include <pluginsetting.h>
#include <versioninfo.h>
#include <uibase/executableinfo.h>
#include <uibase/filemapping.h>
#include <uibase/game_features/igamefeatures.h>
#include <uibase/guessedvalue.h>
#include <uibase/idownloadmanager.h>
#include <uibase/iinstallationmanager.h>
#include <uibase/imodinterface.h>
#include <uibase/imodrepositorybridge.h>
#include <uibase/imoinfo.h>
#include <uibase/iplugin.h>
#include <uibase/iplugindiagnose.h>
#include <uibase/iplugingame.h>
#include <uibase/ipluginlist.h>
#include <uibase/pluginsetting.h>
#include <uibase/versioninfo.h>

#include "../deprecation.h"
#include "pyfiletree.h"
Expand Down
26 changes: 13 additions & 13 deletions src/mobase/wrappers/game_features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

#include "../pybind11_all.h"

#include <ipluginlist.h>
#include <isavegameinfowidget.h>

#include <bsainvalidation.h>
#include <dataarchives.h>
#include <gameplugins.h>
#include <igamefeatures.h>
#include <localsavegames.h>
#include <moddatachecker.h>
#include <moddatacontent.h>
#include <savegameinfo.h>
#include <scriptextender.h>
#include <unmanagedmods.h>
#include <uibase/ipluginlist.h>
#include <uibase/isavegameinfowidget.h>

#include <uibase/game_features/bsainvalidation.h>
#include <uibase/game_features/dataarchives.h>
#include <uibase/game_features/gameplugins.h>
#include <uibase/game_features/igamefeatures.h>
#include <uibase/game_features/localsavegames.h>
#include <uibase/game_features/moddatachecker.h>
#include <uibase/game_features/moddatacontent.h>
#include <uibase/game_features/savegameinfo.h>
#include <uibase/game_features/scriptextender.h>
#include <uibase/game_features/unmanagedmods.h>

#include "pyfiletree.h"

Expand Down
4 changes: 2 additions & 2 deletions src/mobase/wrappers/pyfiletree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#include "../pybind11_all.h"

#include <ifiletree.h>
#include <log.h>
#include <uibase/ifiletree.h>
#include <uibase/log.h>

namespace py = pybind11;
using namespace MOBase;
Expand Down
2 changes: 1 addition & 1 deletion src/mobase/wrappers/pyfiletree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "../pybind11_all.h"

#include <ifiletree.h>
#include <uibase/ifiletree.h>

namespace pybind11 {
template <>
Expand Down
Loading

0 comments on commit 7cca701

Please sign in to comment.