Skip to content

Commit a839d36

Browse files
authored
Switch from fmtlib to std::format. (#124)
* Fix issue with latest pybind11. * Switch from fmtlib to std::format. * Set CMake policy CMP0144.
1 parent bb0a24a commit a839d36

8 files changed

Lines changed: 17 additions & 95 deletions

File tree

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
id: build-plugin-python
1515
uses: ModOrganizer2/build-with-mob-action@master
1616
with:
17-
mo2-third-parties: fmt gtest python spdlog boost sip pyqt pybind11
17+
mo2-third-parties: gtest python spdlog boost sip pyqt pybind11
1818
mo2-dependencies: cmake_common uibase
1919
mo2-cmake-command: -DPLUGIN_PYTHON_TESTS=1 ..
2020
- name: Build Plugin Python Tests

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
cmake_minimum_required(VERSION 3.16)
22

3+
cmake_policy(SET CMP0144 NEW)
4+
35
if(DEFINED DEPENDENCIES_DIR)
46
include(${DEPENDENCIES_DIR}/modorganizer_super/cmake_common/mo2.cmake)
57
else()
@@ -14,9 +16,14 @@ set(PYTHON_BUILD_PATH ${PYTHON_ROOT}/PCBuild/amd64)
1416
set(Python_USE_STATIC_LIBS False)
1517
set(Python_INCLUDE_DIR ${PYTHON_ROOT}/Include)
1618
set(Python_EXECUTABLE ${PYTHON_BUILD_PATH}/python.exe)
17-
file(GLOB Python_LIBRARY ${PYTHON_BUILD_PATH}/python[0-9]+.lib)
19+
file(GLOB Python_LIBRARY ${PYTHON_BUILD_PATH}/python[0-9][0-9]*.lib)
1820
find_package(Python COMPONENTS Interpreter Development REQUIRED)
1921

22+
# pybind11 needs uppercase (at least EXECUTABLE and LIBRARY)
23+
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
24+
set(PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIR})
25+
set(PYTHON_LIBRARY ${Python_LIBRARY})
26+
2027
# useful for naming DLL, zip, etc. (3.10 -> 310)
2128
set(Python_VERSION_SHORT ${Python_VERSION_MAJOR}${Python_VERSION_MINOR})
2229

src/mobase/mobase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma warning(disable : 4100)
22
#pragma warning(disable : 4996)
33

4+
#include <format>
45
#include <tuple>
56
#include <variant>
67

@@ -15,7 +16,6 @@
1516
#include <QDir>
1617
#include <QFile>
1718
#include <QWidget>
18-
#include <fmt/format.h>
1919
#include <iplugin.h>
2020
#include <iplugindiagnose.h>
2121
#include <ipluginfilemapper.h>

src/mobase/wrappers/basic_classes.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
#include "../pybind11_all.h"
44

5-
#pragma warning(push)
6-
#pragma warning(disable : 4459)
7-
#include <fmt/format.h>
8-
#include <fmt/xchar.h>
9-
#pragma warning(pop)
5+
#include <format>
106

117
#include <executableinfo.h>
128
#include <filemapping.h>
@@ -763,7 +759,7 @@ namespace mo2::python {
763759
.def_readwrite("isDirectory", &Mapping::isDirectory)
764760
.def_readwrite("createTarget", &Mapping::createTarget)
765761
.def("__str__", [](Mapping const& m) {
766-
return fmt::format(L"Mapping({}, {}, {}, {})", m.source.toStdWString(),
762+
return std::format(L"Mapping({}, {}, {}, {})", m.source.toStdWString(),
767763
m.destination.toStdWString(), m.isDirectory,
768764
m.createTarget);
769765
});

src/plugin_python_en.ts

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/runner/error.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#ifndef ERROR_H
22
#define ERROR_H
33

4+
#include <format>
5+
46
#include <QString>
57

6-
#include <fmt/format.h>
78
#include <pybind11/pybind11.h>
89

910
#include <utility.h>
@@ -19,7 +20,7 @@ namespace pyexcept {
1920
MissingImplementation(std::string const& className,
2021
std::string const& methodName)
2122
: Exception(QString::fromStdString(
22-
fmt::format("Python class implementing \"{}\" has no "
23+
std::format("Python class implementing \"{}\" has no "
2324
"implementation of method \"{}\".",
2425
className, methodName)))
2526
{

src/runner/pythonutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace mo2::python {
2525
buffer_ << message;
2626
if (buffer_.tellp() != 0 && buffer_.str().back() == '\n') {
2727
const auto full_message = buffer_.str();
28-
MOBase::log::log(level_,
28+
MOBase::log::log(level_, "{}",
2929
full_message.substr(0, full_message.length() - 1));
3030
buffer_ = std::stringstream{};
3131
}

tests/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cmake_minimum_required(VERSION 3.16)
22

33
# pytest
4+
cmake_policy(SET CMP0144 NEW)
45
find_package(GTest REQUIRED)
56

67
set(PYLIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/pylibs)

0 commit comments

Comments
 (0)