diff --git a/README.md b/README.md index bc2e3e750c..3b9e492c73 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ The [Screenshots-page](./screenshots/) contains several screenshots, partly take [![EXAMPLES-Page](./screenshots/screenshotsbanner.png)](./screenshots/README.md) -## Building +## Building Using CMake [![Lates Release](https://img.shields.io/github/v/release/jkriege2/JKQtPlotter)](https://github.com/jkriege2/JKQtPlotter/releases) @@ -110,6 +110,27 @@ or on a Qt-version agnostic way via: ``` See https://jkriege2.github.io/JKQtPlotter/page_buildinstructions__c_m_a_k_e.html for details. +## Usage via CMake's FetchConten-API + +In addition to the method described above (i.e. build and install the library and then use it), you can also use JKQTPlotter via CMake's [FetchContent-API](https://cmake.org/cmake/help/latest/module/FetchContent.html). + +For this method, you need to add these lines to your CMake project: +``` +include(FetchContent) # once in the project to include the module +# ... now declare JKQTPlotter5/6 +FetchContent_Declare(JKQTPlotter${QT_VERSION_MAJOR} + GIT_REPOSITORY https://github.com/jkriege2/JKQtPlotter.git + # GIT_TAG v5.0.0) +# ... finally make JKQTPlotter5/6 available +FetchContent_MakeAvailable(JKQTPlotter${QT_VERSION_MAJOR}) +``` + +These declare JKQTPlotter and make it available in your project. Afterwards you should be able to link against it, using +``` +target_link_libraries(${PROJECT_NAME} JKQTPlotter${QT_VERSION_MAJOR}::JKQTPlotter${QT_VERSION_MAJOR}) +``` + + ## Stargazers over time [![Stargazers over time](https://starchart.cc/jkriege2/JKQtPlotter.svg)](https://starchart.cc/jkriege2/JKQtPlotter) diff --git a/appveyor.yml b/appveyor.yml index dee66fb1ff..9c4764eff4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -31,6 +31,15 @@ environment: matrix: + + - QTABI: gcc_64 + COMPILER: GCC + QTVER: 6.4 + APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004 + CMAKE_GENERATOR: "Unix Makefiles" + INSTALL_QMAKE5: true + TEST_FETCHCONTENT: true + - QTABI: gcc_64 COMPILER: GCC QTVER: 5.15 @@ -38,6 +47,7 @@ environment: APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004 CMAKE_GENERATOR: "Unix Makefiles" INSTALL_QMAKE5: true + TEST_FETCHCONTENT: false - QTABI: msvc2019_64 COMPILER: MSVC @@ -45,6 +55,7 @@ environment: APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 CMAKE_GENERATOR: "Visual Studio 16 2019" CMAKE_BUILDFLAGS: /verbosity:minimal /maxcpucount + TEST_FETCHCONTENT: false - QTABI: msvc2019_64 COMPILER: MSVC @@ -52,6 +63,7 @@ environment: APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 CMAKE_GENERATOR: "Visual Studio 16 2019" CMAKE_BUILDFLAGS: /verbosity:minimal /maxcpucount + TEST_FETCHCONTENT: false - QTABI: gcc_64 COMPILER: GCC @@ -59,6 +71,7 @@ environment: APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004 CMAKE_GENERATOR: "Unix Makefiles" INSTALL_QMAKE5: true + TEST_FETCHCONTENT: false - QTABI: gcc_64 COMPILER: GCC @@ -66,12 +79,14 @@ environment: APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004 CMAKE_GENERATOR: "Unix Makefiles" INSTALL_QMAKE5: true + TEST_FETCHCONTENT: false - QTABI: macos COMPILER: CLANG QTVER: 6.4 APPVEYOR_BUILD_WORKER_IMAGE: macos-monterey CMAKE_GENERATOR: "Unix Makefiles" + TEST_FETCHCONTENT: false for: @@ -203,37 +218,49 @@ for: - sh: cd $APPVEYOR_BUILD_FOLDER - sh: mkdir build - sh: mkdir install - - sh: cd build - sh: | - if [ "$USE_CMAKE" = true ]; then + if [ "$USE_CMAKE" = true ] && [ "$TEST_FETCHCONTENT" = false ]; then + cd build echo --- Run CMake Configure ----------------------------------------------------------------------------- cmake --version cmake -G "$CMAKE_GENERATOR" "-DCMAKE_PREFIX_PATH=$QTDIR;$CIMG_INCLUDE_DIR" "-DCMAKE_INSTALL_PREFIX=$APPVEYOR_BUILD_FOLDER/install" .. echo --- Build using CMake ------------------------------------------------------------------------------- cmake --build . --config "$CONFIGURATION" -j$(getconf _NPROCESSORS_ONLN) -- $CMAKE_BUILDFLAGS fi + if [ "$USE_CMAKE" = true ] && [ "$TEST_FETCHCONTENT" = true ]; then + cd examples/cmake_fetchcontent_example + mkdir build + cd build + echo --- Run CMake Configure with FetchCOntent ----------------------------------------------------------- + cmake --version + cmake -G "$CMAKE_GENERATOR" "-DCMAKE_PREFIX_PATH=$QTDIR;$CIMG_INCLUDE_DIR" "-DCMAKE_INSTALL_PREFIX=$APPVEYOR_BUILD_FOLDER/install" .. + echo --- Build using CMake with FetchCOntent ------------------------------------------------------------- + cmake --build . --config "$CONFIGURATION" -j$(getconf _NPROCESSORS_ONLN) -- $CMAKE_BUILDFLAGS + fi - sh: | if [ "$USE_CMAKE" = false ]; then + cd build echo --- Run QMake Configure ----------------------------------------------------------------------------- $QTDIR/bin/qmake -v $QTDIR/bin/qmake -makefile -o Makefile "CONFIG+=%CONFIGURATION%" ../JKQtPlotterAppveyorBuild.pro echo --- Build for QMake --------------------------------------------------------------------------------- make -j$(getconf _NPROCESSORS_ONLN) fi - - sh: echo == INSTALL JKQtPlotter ========================================================================== - - sh: cd $APPVEYOR_BUILD_FOLDER - - sh: cd build + - sh: - sh: | - if [ "$USE_CMAKE" = true ]; then + if [ "$USE_CMAKE" = true ] && [ "$TEST_FETCHCONTENT" = false ]; then + echo == INSTALL JKQtPlotter ========================================================================== + cd $APPVEYOR_BUILD_FOLDER + cd build echo --- Install using CMake ------------------------------------------------------------------------------- cmake --install . --config "$CONFIGURATION" fi after_build: - - sh: echo == TEST USE JKQtPlotter CMAKE BUILD ============================================================ - sh: | - if [ "$USE_CMAKE" = true ]; then + if [ "$USE_CMAKE" = true ] && [ "$TEST_FETCHCONTENT" = false ]; then + echo == TEST USE JKQtPlotter CMAKE BUILD ============================================================ cd $APPVEYOR_BUILD_FOLDER cd examples/cmake_link_example mkdir build diff --git a/doc/dox/buildinstructions_cmake.dox b/doc/dox/buildinstructions_cmake.dox index 58ae400988..ef78e51e34 100644 --- a/doc/dox/buildinstructions_cmake.dox +++ b/doc/dox/buildinstructions_cmake.dox @@ -179,4 +179,25 @@ Then you can again build the example either using the generated builf files (e.g $ cmake --build . --config "Debug" --target install \endcode + +\section page_buildinstructions_CMAKE_FETCHCONTENT Using JKQTPlotter with CMake's FetchContent-API + +In addition to the method described above (i.e. build and install the library and then use it), you can also use JKQTPlotter via CMake's FetchContent-API. Also have a look at this blog post for a detailed explanation. Also see \ref JKQTCMakeFetchContentExample for a detailed example. + +For this method, you need to add these lines to your CMake project: +\code{.cmake} +include(FetchContent) # once in the project to include the module +# ... now declare JKQTPlotter5/6 +FetchContent_Declare(JKQTPlotter${QT_VERSION_MAJOR} + GIT_REPOSITORY https://github.com/jkriege2/JKQtPlotter.git + # GIT_TAG v5.0.0) +# ... finally make JKQTPlotter5/6 available +FetchContent_MakeAvailable(JKQTPlotter${QT_VERSION_MAJOR}) +\endcode + +These declare JKQTPlotter and make it available in your project. Afterwards you should be able to link against it, using +\code{.cmake} +target_link_libraries(${PROJECT_NAME} JKQTPlotter${QT_VERSION_MAJOR}::JKQTPlotter${QT_VERSION_MAJOR}) +\endcode + */ \ No newline at end of file diff --git a/doc/dox/examples_and_tutorials.dox b/doc/dox/examples_and_tutorials.dox index 094f8b7459..69d6f81aac 100644 --- a/doc/dox/examples_and_tutorials.dox +++ b/doc/dox/examples_and_tutorials.dox @@ -288,7 +288,7 @@ All test-projects are Qt-projects that use qmake to build. You can load them int -\section jkqtp_extut_jkqtfastplotter Examples for JKQTFastPlotter +\section jkqtp_extut_jkqtfastplotter DEPRECATED: Examples for JKQTFastPlotter
Screenshot | Description | Notes
diff --git a/doc/dox/jkqtfastplotter.dox b/doc/dox/jkqtfastplotter.dox
index 4e8d73bf87..6bf62f34f8 100644
--- a/doc/dox/jkqtfastplotter.dox
+++ b/doc/dox/jkqtfastplotter.dox
@@ -1,6 +1,6 @@
/*!
-\defgroup jkqtfastplotter JKQTFastPlotter: Speed-Optimized Plotter class
+\defgroup jkqtfastplotter DEPRECATED: JKQTFastPlotter: Speed-Optimized Plotter class
\deprecated The class JKQTFastPlotter and all its support classes are deprecated and will be removed in future versions.
diff --git a/examples/cmake_fetchcontent_example/CMakeLists.txt b/examples/cmake_fetchcontent_example/CMakeLists.txt
new file mode 100644
index 0000000000..91b8e6a3f4
--- /dev/null
+++ b/examples/cmake_fetchcontent_example/CMakeLists.txt
@@ -0,0 +1,54 @@
+# set minimum required CMake-Version
+cmake_minimum_required(VERSION 3.23)
+
+# set Project name
+project(simpletest_cmake LANGUAGES CXX)
+
+# some basic configurations
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+# Configure project for usage of Qt5/Qt6
+find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui Widgets PrintSupport Svg Xml OpenGl REQUIRED)
+find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets PrintSupport Svg Xml OpenGL REQUIRED)
+
+
+# include JKQTPlotter via FetchContent-API:
+# ... first load the FetchContent-API:
+include(FetchContent) # once in the project to include the module
+# ... now declare JKQTPlotter5/6
+FetchContent_Declare(JKQTPlotter${QT_VERSION_MAJOR}
+ GIT_REPOSITORY https://github.com/jkriege2/JKQtPlotter.git
+ # GIT_TAG v5.0.0)
+# ... finally make JKQTPlotter5/6 available
+FetchContent_MakeAvailable(JKQTPlotter${QT_VERSION_MAJOR})
+
+# For Visual Studio, we need to set some additional compiler options
+if(MSVC)
+ add_compile_options(/EHsc)
+ # To enable M_PI, M_E,...
+ add_definitions(/D_USE_MATH_DEFINES)
+ # To Prevent Errors with min() and max()
+ add_definitions(/DNOMINMAX)
+ # To fix error: C2338: va_start argument must not
+ # have reference type and must not be parenthesized
+ add_definitions(/D_CRT_NO_VA_START_VALIDATION)
+endif()
+
+# add the example executable
+add_executable(${PROJECT_NAME} WIN32 simpletest.cpp)
+# ... link against Qt5/6 and JKQTPlotterLib
+# (you could use JKQTPlotterSharedLib if you don't want to link againast the
+# static version, but against the shared/DLL version).
+target_link_libraries(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::PrintSupport Qt${QT_VERSION_MAJOR}::Svg Qt${QT_VERSION_MAJOR}::Xml)
+# ... link against JKQTPlotter: As the Targets contain the Qt-Version-Number in their names, we can
+# link against 'JKQTPlotter${QT_VERSION_MAJOR}::JKQTPlotter${QT_VERSION_MAJOR}' and it works
+# for Qt5 AND Qt6 ...
+# if you have a speific Qt-Version, you can also write e.g. 'JKQTPlotter6::JKQTPlotter6'
+target_link_libraries(${PROJECT_NAME} PUBLIC JKQTPlotter${QT_VERSION_MAJOR}::JKQTPlotter${QT_VERSION_MAJOR})
+
+
+# Installation
+install(TARGETS ${PROJECT_NAME}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+)
diff --git a/examples/cmake_fetchcontent_example/README.md b/examples/cmake_fetchcontent_example/README.md
new file mode 100644
index 0000000000..bd43ebfa3c
--- /dev/null
+++ b/examples/cmake_fetchcontent_example/README.md
@@ -0,0 +1,87 @@
+# Example (JKQTPlotter): CMake FetchContent Example {#JKQTCMakeFetchContentExample}
+
+This project (see [`cmake_fetchcontent_example`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/cmake_fetchcontent_example) demonstrates how to link against JKQTPlotter using CMake's [FetchContent-API](https://cmake.org/cmake/help/latest/module/FetchContent.html). Also have a look at [this blog post](https://www.foonathan.net/2022/06/cmake-fetchcontent/) for a detailed explanation. See https://jkriege2.github.io/JKQtPlotter/page_buildinstructions__c_m_a_k_e.html for details on how to build JKQTPlotter with CMake
+
+This example uses very simple code, which simply displays a plotter and shows some data. The important part of this example is the ´CMakeLists.txt`-file:
+```
+# set minimum required CMake-Version
+cmake_minimum_required(VERSION 3.23)
+
+# set Project name
+project(simpletest_cmake LANGUAGES CXX)
+
+# some basic configurations
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+# Configure project for usage of Qt5/Qt6
+find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui Widgets PrintSupport Svg Xml OpenGl REQUIRED)
+find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets PrintSupport Svg Xml OpenGL REQUIRED)
+
+
+# include JKQTPlotter via FetchContent-API:
+# ... first load the FetchContent-API:
+include(FetchContent) # once in the project to include the module
+# ... now declare JKQTPlotter5/6
+FetchContent_Declare(JKQTPlotter${QT_VERSION_MAJOR}
+ GIT_REPOSITORY https://github.com/jkriege2/JKQtPlotter.git
+ # GIT_TAG v5.0.0)
+# ... finally make JKQTPlotter5/6 available
+FetchContent_MakeAvailable(JKQTPlotter${QT_VERSION_MAJOR})
+
+# For Visual Studio, we need to set some additional compiler options
+if(MSVC)
+ add_compile_options(/EHsc)
+ # To enable M_PI, M_E,...
+ add_definitions(/D_USE_MATH_DEFINES)
+ # To Prevent Errors with min() and max()
+ add_definitions(/DNOMINMAX)
+ # To fix error: C2338: va_start argument must not
+ # have reference type and must not be parenthesized
+ add_definitions(/D_CRT_NO_VA_START_VALIDATION)
+endif()
+
+# add the example executable
+add_executable(${PROJECT_NAME} WIN32 simpletest.cpp)
+# ... link against Qt5/6 and JKQTPlotterLib
+# (you could use JKQTPlotterSharedLib if you don't want to link againast the
+# static version, but against the shared/DLL version).
+target_link_libraries(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::PrintSupport Qt${QT_VERSION_MAJOR}::Svg Qt${QT_VERSION_MAJOR}::Xml)
+# ... link against JKQTPlotter: As the Targets contain the Qt-Version-Number in their names, we can
+# link against 'JKQTPlotter${QT_VERSION_MAJOR}::JKQTPlotter${QT_VERSION_MAJOR}' and it works
+# for Qt5 AND Qt6 ...
+# if you have a speific Qt-Version, you can also write e.g. 'JKQTPlotter6::JKQTPlotter6'
+target_link_libraries(${PROJECT_NAME} PUBLIC JKQTPlotter${QT_VERSION_MAJOR}::JKQTPlotter${QT_VERSION_MAJOR})
+
+
+# Installation
+install(TARGETS ${PROJECT_NAME}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+)
+
+
+```
+
+The important steps here are
+```
+include(FetchContent) # once in the project to include the module
+# ... now declare JKQTPlotter5/6
+FetchContent_Declare(JKQTPlotter${QT_VERSION_MAJOR}
+ GIT_REPOSITORY https://github.com/jkriege2/JKQtPlotter.git
+ # GIT_TAG v5.0.0)
+# ... finally make JKQTPlotter5/6 available
+FetchContent_MakeAvailable(JKQTPlotter${QT_VERSION_MAJOR})
+```
+
+where JKQTPlotter is first declared to the FetchContent-API and then loaded.
+
+
+To build this example, you first need to make a subdirectory `build` and then call CMake form that subdirectory:
+```.sh
+ $ mkdir build
+ $ cd build
+ $ cmake .. -G " |
---|