JKQtExtras
a library of useful Qt widgets and tools
Build Instructions

This page explains how to build JKQtExtras and to use the results in your own Projects.

Build using CMake

Running a Build with CMake

The preferred way to build JKQtExtras is using CMake. 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 ./lib/ and ./examples/ .

You can build JKQtExtras (and also the examples) by either opening the file CMakeLists.txt in QTCreator (which has CMake integration), or by calling CMake by hand. How to do this depends on your local system und build environment.

Building with MinGW/GNU/... Makefiles

You can use (MinGW) Makefiles by calling:

$ mkdir build
$ cd build
$ cmake .. -G "MinGW Makefiles" "-DCMAKE_PREFIX_PATH=<path_to_your_qt_sources>"
$ cmake --build . --config "Debug"
$ cmake --build . --config "Debug" --target install

Building with Visual Studio

For Visual Studio it could look like this:

$ mkdir build
$ cd build
$ cmake .. -G "Visual Studio 15 2017 Win64" "-DCMAKE_PREFIX_PATH=<path_to_your_qt_sources>"

Where <path_to_your_qt_sources> could be e.g. C:/development/Qt5/5.12.0/msvc2017_64 . This call results in a Visual Studio solution build/JKQtExtras.sln that you can load and compile from the Visual Studio IDE. Alternatively you can also build the solution directly calling:

$ cmake --build . --config "Debug"

Afterwards you can install the library by

$ cmake --build . --config "Debug" --target install

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:

  • CMAKE_PREFIX_PATH : add the path to your Qt installatrion to this variable, so the find_package(Qt5...) commands find the libraries you want to use
  • JKQtExtras_BUILD_SHARED_LIBS : Build as shared library (default: ON )
  • JKQtExtras_BUILD_STATIC_LIBS : Build as static library (default: ON )
  • JKQtExtras_BUILD_DECORATE_LIBNAMES_WITH_BUILDTYPE : If set, the build-type is appended to the library name (default: ON )
  • JKQtExtras_BUILD_EXAMPLES : Build examples (default: ON )
  • CMAKE_INSTALL_PREFIX : Install directory for the library

Using a built, generated with CMake

After building and installing JKQtExtras you have all files that you need inside the instal directory:

  • <INSTALLDIR>/include contains all required header files
  • <INSTALLDIR>/bin contains the shared libraries
  • <INSTALLDIR>/lib contains the link libraries
  • <INSTALLDIR>/lib/cmake contains files necessary for CMake's find_package() to work

You can find an example project that uses a complete cmake-build here: JKQTCMakeLinkExample (online: https://github.com/jkriege2/JKQtExtras/blob/master/examples/cmake_link_example).

Here is the CMakeLists.txt from that directory:

# set minimum required CMake-Version
cmake_minimum_required(VERSION 3.10)
# set Project name
set(EXAMPLE_NAME simpletest)
set(EXENAME jkqtetest_${EXAMPLE_NAME})
project(${EXAMPLE_NAME} LANGUAGES CXX)
# some basic configurations
set(CMAKE_AUTOMOC 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 COMPONENTS Core Gui Widgets PrintSupport Svg Xml OpenGl REQUIRED)
# include JKQtExtras
find_package(JKQtExtrasLib REQUIRED)
# 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)
# ... link against Qt5 and JKQtExtrasLib
# (you could use JKQtExtrasSharedLib if you don't want to link againast the
# static version, but against the shared/DLL version).
target_link_libraries(${EXENAME} Qt5::Core Qt5::Widgets Qt5::Gui Qt5::PrintSupport Qt5::Svg Qt5::Xml JKQtExtrasLib)
# Installation
install(TARGETS ${EXENAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

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 "<GENERATOR>" "-DCMAKE_PREFIX_PATH=<path_to_your_qt_sources> -DCMAKE_MODULE_PATH=<path_to_lib/cmake_dir_of_JKQtExtras>"

The you can use the generated makefiles (e.g. load them in an editor, or build them jsing make ). In the last line above, you need to specify two directories:

  • <path_to_your_qt_sources> points to you Qt installation
  • <path_to_lib/cmake_dir_of_JKQtExtras> points to the directory containing the XYZ.cmake -files from the JKQtExtras build. Typically this is <JKQtExtras_INSTALL_DIR>/lib/cmake , where <JKQtExtras_INSTALL_DIR> is the directory into which you installed JKQtExtras.

Build using QMake

QMake Include Project

If you want to simply include the JKQtExtras 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:

  • lib/JKQtExtras.pri includes the complete library (JKQtExtras, JKQTFastPlotter, JKQTMathText)

In your QMake-projects it is then sufficient to add a line like:

include(<PATHTOJKQtExtrasDIR>/lib/JKQtExtras.pri)

QMake Static Library

There is a single .PRO-file, that can be used to build the full library:

This will produce a static link library that you can include into your projects, e.g. with the following QMake-snippet:

# include JKQtExtras library
DEPENDPATH += \
<PATHTOJKQtExtrasDIR>/lib \
<PATHTOJKQtExtrasDIR>/qmake/staticlib/JKQtExtraslib
INCLUDEPATH += <PATHTOJKQtExtrasDIR>/lib
CONFIG (debug, debug|release) {
DEPENDPATH += <PATHTOJKQtExtrasDIR>/qmake/staticlib/JKQtExtraslib/debug
LIBS += -L<PATHTOJKQtExtrasDIR>/qmake/staticlib/JKQtExtraslib/debug -lJKQtExtraslib_debug
} else {
DEPENDPATH += <PATHTOJKQtExtrasDIR>/qmake/staticlib/JKQtExtraslib/release
LIBS += -L<PATHTOJKQtExtrasDIR>/qmake/staticlib/JKQtExtraslib/release -lJKQtExtraslib
}

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:

TEMPLATE = subdirs
# the (static library version) of JKQtExtras
JKQtExtraslib_static.file = ../../qmake/staticlib/JKQtExtraslib/JKQtExtraslib.pro
# your project file, with declared dependencies on JKQtExtraslib_static
test_styling.file=$$PWD/test_styling.pro
test_styling.depends = JKQtExtraslib_static
# add the two entries to SUBDIRS
SUBDIRS += JKQtExtraslib_static test_styling

QMake Dynamic Library

There is a single .PRO-files, that can be used to build the full library:

This will produce a dynamic link library that you can include into your projects, e.g. with the following QMake-snippet:

# include JKQtExtras library
DEPENDPATH += \
<PATHTOJKQtExtrasDIR>/lib \
<PATHTOJKQtExtrasDIR>/qmake/sharedlib/JKQtExtraslib
INCLUDEPATH += <PATHTOJKQtExtrasDIR>/lib
DEFINES += JKQTCOMMON_LIB_IN_DLL JKQTFASTPLOTTER_LIB_IN_DLL JKQTMATHTEXT_LIB_IN_DLL JKQtExtras_LIB_IN_DLL
CONFIG (debug, debug|release) {
# ensure that DLLs are copied to the output directory
install_JKQtExtras_dll.files = <PATHTOJKQtExtrasDIR>/qmake/sharedlib/JKQtExtraslib/debug/JKQtExtraslib_debug.*
install_JKQtExtras_dll.path = $$OUT_PWD
INSTALLS += install_JKQtExtras_dll
# link agains DLLs
DEPENDPATH += <PATHTOJKQtExtrasDIR>/qmake/sharedlib/JKQtExtraslib/debug
LIBS += -L<PATHTOJKQtExtrasDIR>/qmake/sharedlib/JKQtExtraslib/debug -lJKQtExtraslib_debug
} else {
# ensure that DLLs are copied to the output directory
install_JKQtExtras_dll.files = <PATHTOJKQtExtrasDIR>/qmake/sharedlib/JKQtExtraslib/release/JKQtExtraslib.*
install_JKQtExtras_dll.path = $$OUT_PWD
INSTALLS += install_JKQtExtras_dll
# link agains DLLs
DEPENDPATH += <PATHTOJKQtExtrasDIR>/qmake/sharedlib/JKQtExtraslib/release
LIBS += -L<PATHTOJKQtExtrasDIR>/qmake/sharedlib/JKQtExtraslib/release -lJKQtExtraslib
}

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:

TEMPLATE = subdirs
# the (shared library version) of JKQtExtras
JKQtExtraslib_shared.file = ../../qmake/sharedlib/JKQtExtraslib.pro
# your project file, with declared dependencies on JKQtExtraslib_shared
test_styling.file=$$PWD/test_styling.pro
test_styling.depends = JKQtExtraslib_shared
# add the two entries to SUBDIRS
SUBDIRS += JKQtExtraslib_shared test_styling
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).