Skip to content

Commit abfe5b0

Browse files
committed
NEW Added CMake option JKQtPlotter_ENABLED_STD_FORMAT which allows to explicitly switch std::format on/off, even if C++20-support is enabled!
1 parent 45c8561 commit abfe5b0

12 files changed

Lines changed: 27 additions & 20 deletions

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ jobs:
187187
cd build
188188
cmake --version
189189
echo "now: QT_QPA_PLATFORM='$QT_QPA_PLATFORM'"
190-
cmake -G "${{ env.GENERATOR }}" "-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}" "-DCMAKE_PREFIX_PATH=${{ env.CMAKE_PREFIX_PATH }}" "-DCMAKE_INSTALL_PREFIX=../install" "-DJKQtPlotter_ENABLED_CXX20=${{ env.USE_CXX20 }}" ..
190+
cmake -G "${{ env.GENERATOR }}" "-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}" "-DCMAKE_PREFIX_PATH=${{ env.CMAKE_PREFIX_PATH }}" "-DCMAKE_INSTALL_PREFIX=../install" "-DJKQtPlotter_ENABLED_STD_FORMAT=${{ env.USE_CXX20 }}" "-DJKQtPlotter_ENABLED_CXX20=${{ env.USE_CXX20 }}" ..
191191
shell: bash
192192

193193

@@ -239,7 +239,7 @@ jobs:
239239
mkdir -p build
240240
cd build
241241
cmake --version
242-
cmake -G "${{ env.GENERATOR }}" "-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}" "-DCMAKE_PREFIX_PATH=${{ env.CMAKE_PREFIX_PATH }}" "-DCMAKE_INSTALL_PREFIX=../install" "-DJKQtPlotter_ENABLED_CXX20=${{ env.USE_CXX20 }}-DJKQtPlotter_ENABLED_CXX20=${{ env.USE_CXX20 }}" ..
242+
cmake -G "${{ env.GENERATOR }}" "-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}" "-DCMAKE_PREFIX_PATH=${{ env.CMAKE_PREFIX_PATH }}" "-DCMAKE_INSTALL_PREFIX=../install" "-DJKQtPlotter_ENABLED_CXX20=${{ env.USE_CXX20 }}" "- "-DJKQtPlotter_ENABLED_STD_FORMAT=${{ env.USE_CXX20 }}" ..
243243
cmake --build . --config ${{ env.BUILD_TYPE }} -j${{ env.NUM_PROC }} -- ${{ env.CMAKE_BUILDFLAGS }}
244244
shell: bash
245245

@@ -251,7 +251,7 @@ jobs:
251251
mkdir -p build
252252
cd build
253253
cmake --version
254-
cmake -G "${{ env.GENERATOR }}" "-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}" "-DCMAKE_PREFIX_PATH=${{ env.CMAKE_PREFIX_PATH }}" "-DCMAKE_INSTALL_PREFIX=../install" "-DJKQtPlotter_ENABLED_CXX20=${{ env.USE_CXX20 }}-DJKQtPlotter_ENABLED_CXX20=${{ env.USE_CXX20 }}" ..
254+
cmake -G "${{ env.GENERATOR }}" "-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}" "-DCMAKE_PREFIX_PATH=${{ env.CMAKE_PREFIX_PATH }}" "-DCMAKE_INSTALL_PREFIX=../install" "-DJKQtPlotter_ENABLED_CXX20=${{ env.USE_CXX20 }}" "-DJKQtPlotter_ENABLED_STD_FORMAT=${{ env.USE_CXX20 }}" ..
255255
cmake --build . --config ${{ env.BUILD_TYPE }} -j${{ env.NUM_PROC }} -- ${{ env.CMAKE_BUILDFLAGS }}
256256
shell: bash
257257

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
mkdir build
6666
cd build
6767
cmake --version
68-
cmake -G "Unix Makefiles" "-DCMAKE_BUILD_TYPE=Release" "-DJKQtPlotter_BUILD_EXAMPLES:BOOL=OFF" ..
68+
cmake -G "Unix Makefiles" "-DCMAKE_BUILD_TYPE=Release" "-DJKQtPlotter_BUILD_EXAMPLES:BOOL=OFF" "-DJKQtPlotter_ENABLED_STD_FORMAT=ON" "-DJKQtPlotter_ENABLED_CXX20=ON" ..
6969
cmake --build . --config "Release"
7070
cd ..
7171

.github/workflows/msvc-codeanalysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
uses: ilammy/msvc-dev-cmd@v1
3131

3232
- name: Configure CMake
33-
run: cmake -B "${{ env.build }}" -DCMAKE_BUILD_TYPE=${{ env.config }} -DJKQtPlotter_BUILD_EXAMPLES=OFF -DJKQtPlotter_BUILD_TOOLS=OFF -DJKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS=OFF
33+
run: cmake -B "${{ env.build }}" -DCMAKE_BUILD_TYPE=${{ env.config }} -DJKQtPlotter_BUILD_EXAMPLES=OFF -DJKQtPlotter_BUILD_TOOLS=OFF -DJKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS=OFF -DJKQtPlotter_ENABLED_STD_FORMAT=ON -DJKQtPlotter_ENABLED_CXX20=ON
3434

3535
- name: Build CMake
3636
run: cmake --build "${{ env.build }}" --config "${{ env.config }}"

cmake/jkqtplotter_cmake_options.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ endif()
4343
if(NOT DEFINED JKQtPlotter_ENABLED_CXX20)
4444
option(JKQtPlotter_ENABLED_CXX20 "Build the library using C++20" OFF)
4545
endif()
46+
if(NOT DEFINED JKQtPlotter_ENABLED_STD_FORMAT)
47+
option(JKQtPlotter_ENABLED_STD_FORMAT "Build the library with support for std::format from C++20 (i.e. JKQtPlotter_ENABLED_CXX20=ON is required!)" ON)
48+
endif()
4649
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
4750
option(CMAKE_INSTALL_PREFIX "Install directory" ${CMAKE_CURRENT_SOURCE_DIR}/install)
4851
endif()

cmake/jkqtplotter_macros.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ function(jkqtplotter_setDefaultLibOptions TARGETNAME libBaseName PRECOMPHEADERFI
2222
if(JKQtPlotter_ENABLED_CXX20)
2323
set_property(TARGET ${TARGETNAME} PROPERTY CXX_STANDARD ${JKQtPlotter_QT_CXX_STANDARD})
2424
set_property(TARGET ${TARGETNAME} PROPERTY CXX_STANDARD_REQUIRED ${JKQtPlotter_QT_CXX_STANDARD_REQUIRED})
25-
target_compile_features(${TARGETNAME} PUBLIC ${JKQtPlotter_QT_CXX_COMPILE_FEATURE})
25+
target_compile_features(${TARGETNAME} PUBLIC ${JKQtPlotter_QT_CXX_COMPILE_FEATURE})
26+
if(JKQtPlotter_ENABLED_STD_FORMAT)
27+
target_compile_definitions(${TARGETNAME} PUBLIC JKQtPlotter_USE_STD_FORMAT)
28+
endif()
2629
endif()
2730
# set options, specific to shared libraries
2831
if (BUILD_SHARED_LIBS)

doc/dox/buildinstructions_cmake.dox

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ The CMake build system offers several configuration variables that you may set/c
5858
- \c JKQtPlotter_BUILD_FORCE_NO_PRINTER_SUPPORT : switches off print-support (when set to \c ON ), even if the current platform supports it (default: \c OFF )
5959
- \c JKQtPlotter_BUILD_DECORATE_LIBNAMES_WITH_BUILDTYPE : If set, the build-type is appended to the library name (default: \c ON )
6060
- \c JKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS : If set, the build uses precompiled headers to speed up (a bit) (default: \c ON )
61-
- \c JKQtPlotter_ENABLED_CXX20 : Build using C++20 (requires a compiler that supports this! (default: \c OFF )
61+
- \c JKQtPlotter_ENABLED_CXX20 : Build using C++20 (requires a compiler that supports this and \c JKQtPlotter_ENABLED_CXX20=ON!, default: \c ON ). This option was added as sometimes there were compatibility issues with std::format
62+
- \c JKQtPlotter_ENABLED_STD_FORMAT : Build using std::format from C++20 (requires a compiler that supports this! (default: \c OFF )
6263
- \c JKQtPlotter_BUILD_WITH_TIMING_INFO_OUTPUT : If enabled (\c ON ), additional tiing code is activated (and built into the library), which outputs timming information for several functions of the library into \c qDebug() . This is intended for development putposes only, NOT for productive builds! (default: \c OFF )
6364
- \c JKQtPlotter_BUILD_EXAMPLES : Build examples (default: \c ON )
6465
- \c JKQtPlotter_BUILD_TOOLS : Build tools (default: \c ON )

lib/jkqtplotter/jkqtpcoordinateaxes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <QApplication>
2929
#if __cplusplus >= 202002L
3030
# include <version>
31-
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
31+
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) && defined(JKQtPlotter_USE_STD_FORMAT)
3232
# include <format>
3333
# endif
3434
#endif
@@ -482,7 +482,7 @@ QString JKQTPCoordinateAxis::floattolabel(double data, int past_comma) const {
482482
return QString::asprintf(axisStyle.tickPrintfFormat.toLatin1().data(), data, tickUnitName.toStdString().c_str());
483483
}; break;
484484
#if __cplusplus >= 202002L
485-
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
485+
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) && defined(JKQtPlotter_USE_STD_FORMAT)
486486
case JKQTPCALTformat: {
487487
const std::string tickUName=tickUnitName.toStdString();
488488
return QString::fromStdString(std::vformat(axisStyle.tickFormatFormat.toStdString(), std::make_format_args(data, tickUName)));
@@ -873,7 +873,7 @@ void JKQTPCoordinateAxis::setTickPrintfFormat(const QString& __value) {
873873
redrawPlot();
874874
}
875875
#if __cplusplus >= 202002L
876-
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
876+
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) && defined(JKQtPlotter_USE_STD_FORMAT)
877877
void JKQTPCoordinateAxis::setTickFormatFormat(const QString &__value)
878878
{
879879
this->axisStyle.tickFormatFormat = __value;

lib/jkqtplotter/jkqtpcoordinateaxes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
371371
/** \copydoc JKQTPCoordinateAxisStyle::tickMode */
372372
inline JKQTPLabelTickMode getTickMode() const { return this->axisStyle.tickMode; }
373373
#if __cplusplus >= 202002L || DOXYGEN
374-
# if (defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))) || DOXYGEN
374+
# if (defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) && defined(JKQtPlotter_USE_STD_FORMAT)) || DOXYGEN
375375
/** \copydoc JKQTPCoordinateAxisStyle::tickFormatFormat */
376376
inline QString getTickFormatfFormat() const { return this->axisStyle.tickFormatFormat; }
377377
# endif
@@ -619,7 +619,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
619619
/** \copydoc JKQTPCoordinateAxisStyle::tickPrintfFormat */
620620
void setTickPrintfFormat(const QString& __value);
621621
#if __cplusplus >= 202002L || DOXYGEN
622-
# if (defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))) || DOXYGEN
622+
# if (defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) && defined(JKQtPlotter_USE_STD_FORMAT)) || DOXYGEN
623623
/** \copydoc JKQTPCoordinateAxisStyle::tickFormatFormat */
624624
void setTickFormatFormat(const QString& __value);
625625
# endif

lib/jkqtplotter/jkqtpcoordinateaxesstyle.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ JKQTPCoordinateAxisStyle::JKQTPCoordinateAxisStyle():
6060
tickDateTimeFormat(QLocale().dateTimeFormat(QLocale::NarrowFormat)),
6161
tickPrintfFormat("%f %s"),
6262
#if __cplusplus >= 202002L
63-
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
63+
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) && defined(JKQtPlotter_USE_STD_FORMAT)
6464
tickFormatFormat("{}{}"),
6565
# endif
6666
#endif
@@ -111,7 +111,7 @@ void JKQTPCoordinateAxisStyle::loadSettings(const QSettings &settings, const QSt
111111
tickDateTimeFormat = settings.value(group+"ticks/datetime_format", defaultStyle.tickDateTimeFormat).toString();
112112
tickPrintfFormat = settings.value(group+"ticks/printf_format", defaultStyle.tickPrintfFormat).toString();
113113
#if __cplusplus >= 202002L
114-
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
114+
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) && defined(JKQtPlotter_USE_STD_FORMAT)
115115
tickFormatFormat = settings.value(group+"ticks/format_format", defaultStyle.tickFormatFormat).toString();
116116
# endif
117117
#endif
@@ -170,7 +170,7 @@ void JKQTPCoordinateAxisStyle::saveSettings(QSettings &settings, const QString &
170170
settings.setValue(group+"ticks/datetime_format", tickDateTimeFormat);
171171
settings.setValue(group+"ticks/printf_format", tickPrintfFormat);
172172
#if __cplusplus >= 202002L
173-
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
173+
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) && defined(JKQtPlotter_USE_STD_FORMAT)
174174
settings.setValue(group+"ticks/format_format", tickFormatFormat);
175175
# endif
176176
#endif

lib/jkqtplotter/jkqtpcoordinateaxesstyle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "jkqtplotter/jkqtplotter_configmacros.h"
2929
#if __cplusplus >= 202002L
3030
# include <version>
31-
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
31+
# if defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) && defined(JKQtPlotter_USE_STD_FORMAT)
3232
# include <format>
3333
# endif
3434
#endif
@@ -176,7 +176,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxisStyle {
176176
/** \brief format string for printf tick labels, see https://en.wikipedia.org/wiki/Printf_format_string documentation for details on format strings The first data parameter is the tick value as \c double an the second is tickUnitName as string. The following image shows an example for \c "y=%+.2f": \image html axisstyle/JKQTPCALTprintf.png */
177177
QString tickPrintfFormat;
178178
#if __cplusplus >= 202002L || DOXYGEN
179-
# if (defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))) || DOXYGEN
179+
# if (defined(__cpp_lib_format) && (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) && defined(JKQtPlotter_USE_STD_FORMAT)) || DOXYGEN
180180
/** \brief format string for std::format tick labels, (see e.g. https://en.cppreference.com/w/cpp/utility/format/formatter#Standard_format_specification ). The first data parameter is the tick value as \c double an the second is tickUnitName as string. The following image shows an example for \c "\\texttt{{ y={:*^+8.1f}}}": \image html axisstyle/JKQTPCALTformat.png
181181
\note This option is only available for C++20 and above and Qt>=6.0.0, use the CMake option \c JKQtPlotter_ENABLED_CXX20=ON if your compiler supports this.*/
182182
QString tickFormatFormat;

0 commit comments

Comments
 (0)