The preferred way to build JKQTPlotter is using <a href="https://cmake.org/">CMake</a>. You can find a detailed explanation of CMake at https://cliutils.gitlab.io/modern-cmake/. The CMake-build is defined in `CMakeLists.txt` files, found in many of the directories of the code repository. Especially in the root directory and the two subdirectories \c ./lib/ and \c ./examples/ .
You can build JKQTPlotter (and also the examples) by either opening the file <a href="https://github.com/jkriege2/JKQtPlotter/blob/master/CMakeLists.txt">CMakeLists.txt</a> in QTCreator (which has CMake integration), or by calling \c CMake by hand. How to do this depends on your local system und build environment.
\subsubsection page_buildinstructions_CMAKE_MAKEFILE Building with MinGW/GNU/... Makefiles
\subsubsection page_buildinstructions_CMAKE_VSTUDIO Building with Visual Studio
For Visual Studio it could look like this:
\code{.sh}
$ mkdir build
$ cd build
$ cmake .. -G "Visual Studio 15 2017 Win64" "-DCMAKE_PREFIX_PATH=<path_to_your_qt_sources>"
\endcode
Where \c <path_to_your_qt_sources> could be e.g. \c C:/development/Qt5/5.12.0/msvc2017_64 . This call results in a Visual Studio solution \c build/JKQTPlotter.sln that you can load and compile from the Visual Studio IDE. Alternatively you can also build the solution directly calling:
\subsection page_buildinstructions_CMAKE_CONFIG Configuring a Build with CMake
The CMake build system offers several configuration variables that you may set/change to modify the outcome of the build:
- \c CMAKE_PREFIX_PATH : add the path to your Qt installatrion to this variable, so the \c find_package(Qt5...) commands find the libraries you want to use
- \c BUILD_SHARED_LIBS : Build as shared library (default: \c ON )
- \c BUILD_STATIC_LIBS : Build as static library (default: \c ON )
- \c BUILD_INCLUDE_XITS_FONTS : Include XITS fonts as resources in library (default: \c ON )
- \c BUILD_DECORATE_LIBNAMES_WITH_BUILDTYPE : If set, the build-type is appended to the library name (default: \c ON )
- \c BUILD_HIGH_COMPILE_WARNING_LEVEL : Set Compiler Warning level to high (default: \c OFF )
- \c BUILD_EXAMPLES : Build examples (default: \c ON )
- \c BUILD_HAS_OPENCV : OpenCV available? If yes, OpenCV examples are built when BUILD_EXAMPLES=ON (default: \c OFF )
- \c LIB_INSTALL : Install library (default: \c ON )
You can find an example project that uses a complete cmake-build here: \ref JKQTCMakeLinkExample (online: <a href="https://github.com/jkriege2/JKQtPlotter/blob/master/examples/cmake_link_example">https://github.com/jkriege2/JKQtPlotter/blob/master/examples/cmake_link_example</a>).
Here is the \c CMakeLists.txt from that directory:
\code
# set minimum required CMake-Version
cmake_minimum_required(VERSION 3.0)
# set Project name
set(EXAMPLE_NAME simpletest)
set(EXENAME jkqtptest_${EXAMPLE_NAME})
project(${EXAMPLE_NAME} LANGUAGES CXX)
# some basic configurations
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Configure project for usage of Qt5
find_package(Qt5 5.12 REQUIRED Core Gui Widgets PrintSupport Svg Xml OpenGl)
# include JKQTPlotter
find_package(JKQTCommonLib)
find_package(JKQTMathTextLib)
find_package(JKQTPlotterLib)
# 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(${EXENAME} WIN32 simpletest.cpp)
# ... and link against JKQTPlotterLib
# (you could use JKQTPlotterSharedLib if you don't want to link againast the
# static version, but against the shared/DLL version).
The you can use the generated makefiles (e.g. load them in an editor, or build them jsing \c make ). In the last line above, you need to specify two directories:
- \c <path_to_your_qt_sources> points to you Qt installation
- \c <path_to_lib/cmake_dir_of_JKQTPLOTTER> points to the directory containing the \c XYZ.cmake -files from the JKQTPlotter build. Typically this is \c <JKQTPLOTTER_INSTALL_DIR>/lib/cmake , where \c <JKQTPLOTTER_INSTALL_DIR> is the directory into which you installed JKQTPlotter.
If you want to simply include the JKQTPlotter Source code into your projects, without build a shared or static library and linking against it, you can use one of these QMake-Include files:
- <a href="https://github.com/jkriege2/JKQtPlotter/blob/master/lib/jkqtplotter.pri">lib/jkqtplotter.pri</a> includes the complete library (JKQTPlotter, JKQTFastPlotter, JKQTMathText)
- <a href="https://github.com/jkriege2/JKQtPlotter/blob/master/lib/jkqtmathtext.pri">lib/jkqtmathtext.pri</a> includes only JKQTMathText
- <a href="https://github.com/jkriege2/JKQtPlotter/blob/master/lib/jkqtfastplotter.pri">lib/jkqtfastplotter.pri</a> includes only JKQTFastPlotter
.
In your QMake-projects it is then sufficient to add a line like:
- <a href="https://github.com/jkriege2/JKQtPlotter/blob/master/qmake/staticlib/jkqtplotterlib/jkqtplotterlib.pro">qmake/staticlib/jkqtplotterlib/jkqtplotterlib.pro</a> builds the complete library (JKQTPlotter, JKQTFastPlotter, JKQTMathText) as static link library
- <a href="https://github.com/jkriege2/JKQtPlotter/blob/master/qmake/staticlib/jkqtmathtextlib/jkqtmathtextlib.pro">qmake/staticlib/jkqtmathtextlib/jkqtmathtextlib.pro</a> builds only JKQTMathText as static link library
- <a href="https://github.com/jkriege2/JKQtPlotter/blob/master/qmake/staticlib/jkqtfastplotterlib/jkqtfastplotterlib.pro">qmake/staticlib/jkqtfastplotterlib/jkqtfastplotterlib.pro</a> builds only JKQTFastPlotter as static link library
This snippet assumes that you built the libraries with the provided `.PRO`-files. You can also add a second `.pro`-file to your projects, which integrates both as subdirs. Such files are used for all examples in this project. Here is an example:
- <a href="https://github.com/jkriege2/JKQtPlotter/blob/master/qmake/sharedlib/jkqtplotterlib/jkqtplotterlib.pro">qmake/sharedlib/jkqtplotterlib/jkqtplotterlib.pro</a> builds the complete library (JKQTPlotter, JKQTFastPlotter, JKQTMathText) as shared library
- <a href="https://github.com/jkriege2/JKQtPlotter/blob/master/qmake/sharedlib/jkqtmathtextlib/jkqtmathtextlib.pro">qmake/sharedlib/jkqtmathtextlib/jkqtmathtextlib.pro</a> builds only JKQTMathText as shared library
- <a href="https://github.com/jkriege2/JKQtPlotter/blob/master/qmake/sharedlib/jkqtfastplotterlib/jkqtfastplotterlib.pro">qmake/sharedlib/jkqtfastplotterlib/jkqtfastplotterlib.pro</a> builds only JKQTFastPlotter as shared library
This snippet assumes that you built the libraries with the provided `.PRO`-files. You can also add a second `.pro`-file to your projects, which integrates both as subdirs. Such files are used for all examples in this project. Here is an example:
# your project file, with declared dependencies on jkqtplotterlib_shared
test_styling.file=$$PWD/test_styling.pro
test_styling.depends = jkqtplotterlib_shared
# add the two entries to SUBDIRS
SUBDIRS += jkqtplotterlib_shared test_styling
\endcode
\note You will have to run a deployment step `make install` before running your executable, so the shared libararies are actually copied to the output directory (see `INSTALLS + ...` above).