Skip to content

Commit

Permalink
NEW/BREAKING: provide general targets JKQTPlotter5/6::JKQTPlotter5/6,…
Browse files Browse the repository at this point in the history
… JKQTPlotter5/6::JKQTMathText5/6, ... which are independent of the type of build (shared/static)

NEW/BREAKING: refactor CMake-Code, so static/dynamic switch is done via <code>BUILD_SHARED_LIBS</code>, which retires <code>JKQtPlotter_BUILD_STATIC_LIBS</code>, <code>JKQtPlotter_BUILD_SHARED_LIBS</code> and removes the capability to build static and shared libraries in one location (fixes issue #104)
NEW: prepareed library for CMake's <a href="https://cmake.org/cmake/help/latest/module/FetchContent.html">FetchContent</a>-API
NEW: the different sub-libraries JKQTPlotter, JKQTFastPlotter (DEPRECATED), JKQTMath, JKQTMathText can be activated/deactivated with CMake options JKQtPlotter_BUILD_LIB_JKQTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTMATHTEXT, JKQtPlotter_BUILD_LIB_JKQTMATH
  • Loading branch information
jkriege2 committed Jan 16, 2024
1 parent 7402343 commit b0df7a1
Show file tree
Hide file tree
Showing 99 changed files with 1,038 additions and 1,659 deletions.
27 changes: 19 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,31 @@ include(jkqtplotter_common_qtsettings)
# additionnal common macros
include(jkqtplotter_macros)

set(jkqtplotter_LIBNAME_VERSION_PART ${QT_VERSION_MAJOR})
# defines the CMake-namespace for all libraries
set(jkqtplotter_namespace JKQTPlotter${jkqtplotter_LIBNAME_VERSION_PART}::)
# defines the subdirectory for CMake-files, when installing
set(jkqtplotter_cmakeSubdir JKQTPlotter${jkqtplotter_LIBNAME_VERSION_PART})



# now add subdirectories with the library code ...
add_subdirectory(lib)
# ... and optionally the examples
if(JKQtPlotter_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if(JKQtPlotter_BUILD_TOOLS)
add_subdirectory(tools)
endif()
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
# We're in the root, define additional targets for developers.
# This prepares the library to be used with CMake's FetchContent

add_subdirectory(doc)
# ... and optionally the examples
if(JKQtPlotter_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if(JKQtPlotter_BUILD_TOOLS)
add_subdirectory(tools)
endif()

add_subdirectory(doc)

endif()

14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,22 @@ JKQTPlotter contains two different build systems: A modern [CMake](https://cmake
With [CMake](https://cmake.org/) you can easily build JKQTPlotter and all its examples, by calling something like:
```
$ mkdir build; cd build
$ cmake .. -G "<cmake_generator>" "-DCMAKE_PREFIX_PATH=<path_to_your_qt_sources>"
$ cmake .. -G "<cmake_generator>" "-DCMAKE_PREFIX_PATH=<path_to_your_qt_sources>" "-DCMAKE_INSTALL_PREFIX=<where_to_install>"
$ cmake --build . --config "Debug"
$ cmake --install . --config "Debug"
```

This will create CMake targets, which you can easily link against. For the main plotter library, the target's name is \c JKQTPlotter5::JKQTPlotter5 or \c JKQTPlotter6::JKQTPlotter6 depending on the Qt-Version you use. You can then simmply link against this via:
```
find_package(JKQTPlotter6 REQUIRED)
target_link_libraries(${PROJECT_NAME} JKQTPlotter6::JKQTPlotter6)
```
or on a Qt-version agnostic way via:
```
find_package(JKQTPlotter${QT_VERSION_MAJOR} REQUIRED)
target_link_libraries(${PROJECT_NAME} JKQTPlotter${QT_VERSION_MAJOR}::JKQTPlotter${QT_VERSION_MAJOR})
```
See http://jkriege2.github.io/JKQtPlotter/page_buildinstructions_cmake.html for details.

## Stargazers over time

Expand Down
44 changes: 42 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,33 @@ for:

build_script:
- cmd: echo == BUILD JKQtPlotter ============================================================================
- cmd: cd %APPVEYOR_BUILD_FOLDER%
- cmd: mkdir build
- cmd: mkdir install
- cmd: cd build
- cmd: if %USE_CMAKE%==true cmake --version
- cmd: if %USE_CMAKE%==true cmake -G "%CMAKE_GENERATOR%" "-DCMAKE_PREFIX_PATH=%QTDIR%;%CIMG_INCLUDE_DIR%" ..
- cmd: if %USE_CMAKE%==true cmake -G "%CMAKE_GENERATOR%" "-DCMAKE_PREFIX_PATH=%QTDIR%;%CIMG_INCLUDE_DIR%" "-DCMAKE_INSTALL_PREFIX=%APPVEYOR_BUILD_FOLDER%\install" ..
- cmd: if %USE_CMAKE%==true cmake --build . --config "%CONFIGURATION%" -j%NUMBER_OF_PROCESSORS% -- %CMAKE_BUILDFLAGS%
- cmd: if %USE_CMAKE%==false qmake.exe -v
- cmd: if %USE_CMAKE%==false qmake.exe CONFIG+=%CONFIGURATION% ..\JKQtPlotterBuildAllExamples.pro
- cmd: if %USE_CMAKE%==false call %MAKETOOL%
- cmd: cd ..

install:
- cmd: echo == INSTALL JKQtPlotter ==========================================================================
- cmd: cd %APPVEYOR_BUILD_FOLDER%
- cmd: cd build
- cmd: if %USE_CMAKE%==true cmake --install . --config "%CONFIGURATION%" -j%NUMBER_OF_PROCESSORS% -- %CMAKE_BUILDFLAGS%

test_usage:
- cmd: echo == TEST: USE JKQtPlotter CMAKE BUILD ============================================================
- cmd: if %USE_CMAKE%==true cd %APPVEYOR_BUILD_FOLDER%
- cmd: if %USE_CMAKE%==true cd examples\cmake_link_example
- cmd: mkdir build
- cmd: cd build
- cmd: if %USE_CMAKE%==true cmake -G "%CMAKE_GENERATOR%" "-DCMAKE_PREFIX_PATH=%QTDIR%;%CIMG_INCLUDE_DIR%;%APPVEYOR_BUILD_FOLDER%\install" ..
- cmd: if %USE_CMAKE%==true cmake --build . --config "%CONFIGURATION%" -j%NUMBER_OF_PROCESSORS% -- %CMAKE_BUILDFLAGS%
- cmd: cd ..


# Linux (Ubuntu2004)
Expand Down Expand Up @@ -185,13 +201,15 @@ for:
build_script:
- sh: echo == BUILD JKQtPlotter ============================================================================
- sh: cd %APPVEYOR_BUILD_FOLDER%
- sh: mkdir build
- sh: mkdir install
- sh: cd build
- sh: |
if [ "$USE_CMAKE" = true ]; then
echo --- Run CMake Configure -----------------------------------------------------------------------------
cmake --version
cmake -G "$CMAKE_GENERATOR" "-DCMAKE_PREFIX_PATH=$QTDIR;$CIMG_INCLUDE_DIR" ..
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
Expand All @@ -204,8 +222,30 @@ for:
make -j$(getconf _NPROCESSORS_ONLN)
fi
install:
- sh: echo == INSTALL JKQtPlotter ==========================================================================
- sh: cd %APPVEYOR_BUILD_FOLDER%
- sh: cd build
- sh: |
if [ "$USE_CMAKE" = true ]; then
echo --- Install using CMake -------------------------------------------------------------------------------
cmake --install . --config "$CONFIGURATION" -j$(getconf _NPROCESSORS_ONLN) -- $CMAKE_BUILDFLAGS
fi
test_usage:
- sh: echo == TEST: USE JKQtPlotter CMAKE BUILD ============================================================
- sh: cd %APPVEYOR_BUILD_FOLDER%
- sh: if %USE_CMAKE%==true cd examples\cmake_link_example
- sh: mkdir build
- sh: cd build
- sh: |
if [ "$USE_CMAKE" = true ]; then
cmake -G "%CMAKE_GENERATOR%" "-DCMAKE_PREFIX_PATH=%QTDIR%;%CIMG_INCLUDE_DIR%;%APPVEYOR_BUILD_FOLDER%\install" ..
cmake --build . --config "%CONFIGURATION%" -j%NUMBER_OF_PROCESSORS% -- %CMAKE_BUILDFLAGS%
fi
- sh: cd ..



# MacOS (Monterey)
Expand Down
32 changes: 26 additions & 6 deletions cmake/jkqtplotter_cmake_options.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
if(NOT DEFINED JKQtPlotter_BUILD_SHARED_LIBS)
option(JKQtPlotter_BUILD_SHARED_LIBS "Build as shared library" ON)
endif()
if(NOT DEFINED JKQtPlotter_BUILD_STATIC_LIBS)
option(JKQtPlotter_BUILD_STATIC_LIBS "Build as static library" OFF)
if(NOT DEFINED BUILD_SHARED_LIBS)
option(BUILD_SHARED_LIBS "Build as shared library" ON)
endif()
if(NOT DEFINED JKQtPlotter_BUILD_INCLUDE_XITS_FONTS)
option(JKQtPlotter_BUILD_INCLUDE_XITS_FONTS "Include XITS fonts (SIL OPEN FONT LICENSE Version 1.1) as resources in library" ON)
Expand All @@ -16,6 +13,18 @@ endif()
if(NOT DEFINED JKQtPlotter_BUILD_EXAMPLES)
option(JKQtPlotter_BUILD_EXAMPLES "Build the examples" ON)
endif()
if(NOT DEFINED JKQtPlotter_BUILD_LIB_JKQTMATH)
option(JKQtPlotter_BUILD_LIB_JKQTMATH "Build the sub-library JKQTMath" ON)
endif()
if(NOT DEFINED JKQtPlotter_BUILD_LIB_JKQTMATHTEXT)
option(JKQtPlotter_BUILD_LIB_JKQTMATHTEXT "Build the sub-library JKQTMathText" ON)
endif()
if(NOT DEFINED JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER)
option(JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER "Build the sub-library JKQTFastPlotter" ON)
endif()
if(NOT DEFINED JKQtPlotter_BUILD_LIB_JKQTPLOTTER)
option(JKQtPlotter_BUILD_LIB_JKQTPLOTTER "Build the sub-library JKQTPlotter" ON)
endif()
if(NOT DEFINED JKQtPlotter_BUILD_TOOLS)
option(JKQtPlotter_BUILD_TOOLS "Build the tools" ON)
endif()
Expand All @@ -35,6 +44,7 @@ if(NOT DEFINED CMAKE_INSTALL_PREFIX)
option(CMAKE_INSTALL_PREFIX "Install directory" ${CMAKE_CURRENT_SOURCE_DIR}/install)
endif()

include(GNUInstallDirs)

#evaluate the settings above
if (NOT CMAKE_INSTALL_LIBDIR)
Expand All @@ -55,8 +65,18 @@ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/output)


if(JKQtPlotter_BUILD_DECORATE_LIBNAMES_WITH_BUILDTYPE)
set(JKQtPlotter_LIBNAME_ADDITION "_$<CONFIG>") #"_${CMAKE_BUILD_TYPE}")
set(JKQtPlotter_LIBNAME_ADDITION "_$<CONFIG>")
else()
set(JKQtPlotter_LIBNAME_ADDITION )
endif()

if (JKQtPlotter_BUILD_FORCE_NO_PRINTER_SUPPORT)
set(JKQtPlotter_BUILD_WITH_PRINTER_SUPPORT "OFF")
else()
set(JKQtPlotter_BUILD_WITH_PRINTER_SUPPORT "ON")
endif()

if(JKQtPlotter_BUILD_LIB_JKQTPLOTTER)
set(JKQtPlotter_BUILD_LIB_JKQTMATH "ON")
set(JKQtPlotter_BUILD_LIB_JKQTMATHTEXT "ON")
endif()
117 changes: 113 additions & 4 deletions cmake/jkqtplotter_macros.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
include(CMakePackageConfigHelpers)

function(jkqtplotter_add_library lib_name)
# create the library (SHARED/STATIC is controlled by the CMake option BUILD_SHARED_LIBS
add_library(${lib_name} )
# ... add an alias with the correct namespace
add_library(${jkqtplotter_namespace}${lib_name} ALIAS ${lib_name})

# set the libraries output name
set_property(TARGET ${lib_name} PROPERTY OUTPUT_NAME "${lib_name}${JKQtPlotter_LIBNAME_ADDITION}")

endfunction()



function(jkqtplotter_setDefaultLibOptions TARGETNAME libBaseName PRECOMPHEADERFILE)
string(TOUPPER ${libBaseName} libBasenameUPPER)

# set library version
set_property(TARGET ${TARGETNAME} PROPERTY VERSION "${PROJECT_VERSION}")
# set required Cxx-Standard
set_property(TARGET ${TARGETNAME} PROPERTY CXX_STANDARD ${JKQtPlotter_QT_CXX_STANDARD})
set_property(TARGET ${TARGETNAME} PROPERTY CXX_STANDARD_REQUIRED ${JKQtPlotter_QT_CXX_STANDARD_REQUIRED})
target_compile_features(${TARGETNAME} PUBLIC ${JKQtPlotter_QT_CXX_COMPILE_FEATURE})
# set options, specific to shared libraries
if (BUILD_SHARED_LIBS)
target_compile_definitions(${TARGETNAME} PUBLIC ${libBasenameUPPER}_LIB_IN_DLL)
target_compile_definitions(${TARGETNAME} PRIVATE ${libBasenameUPPER}_LIB_EXPORT_LIBRARY)
set_target_properties(${TARGETNAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS "ON")
endif(BUILD_SHARED_LIBS)

if(MINGW)
# COMPILER-SETTINGS FOR MINGW
target_compile_options(${TARGETNAME} PUBLIC -fexceptions)
elseif(MSVC)
# COMPILER-SETTINGS FOR MS VISUAL C++
target_compile_options(${TARGETNAME} PUBLIC /EHsc)
target_compile_definitions(${TARGETNAME} PUBLIC NOMINMAX)
endif()

# enable TIMING INFO output (if activated by option JKQtPlotter_BUILD_WITH_TIMING_INFO_OUTPUT)
if(JKQtPlotter_BUILD_WITH_TIMING_INFO_OUTPUT)
target_compile_definitions(${TARGETNAME} PRIVATE JKQTBP_AUTOTIMER)
endif()

# set default include paths
target_include_directories(${TARGETNAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

# precomiled headers to speed up compilation
if (JKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS AND (NOT PRECOMPHEADERFILE EQUAL ""))
target_precompile_headers(${TARGETNAME} PRIVATE ${PRECOMPHEADERFILE})
target_sources(${TARGETNAME} PRIVATE ${PRECOMPHEADERFILE})
endif()

endfunction()




include(GNUInstallDirs)

function(jkqtplotter_installlibrary lib_name libIncludeSubdir BuildTypePart)
install(TARGETS ${lib_name} EXPORT ${lib_name}_TARGETS
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand All @@ -6,19 +70,64 @@ function(jkqtplotter_installlibrary lib_name libIncludeSubdir BuildTypePart)
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${libIncludeSubdir}
)
if(WIN32 AND MSVC AND (NOT MSVC_VERSION LESS 1600) AND (NOT CMAKE_VERSION VERSION_LESS "3.1") AND (NOT BuildTypePart STREQUAL ""))
message(STATUS "?????????????? INSTALL PDF BuildTypePart=${BuildTypePart}")
install(FILES $<TARGET_PDB_FILE:${lib_name}> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
endif()
set(JKQTP_CURRENT_TARGET_SHAREDPART "${BuildTypePart}")
set(JKQTP_CURRENT_TARGET_FILENAME "${lib_name}Targets.cmake")
configure_file(LibTarget.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${lib_name}Config.cmake" @ONLY)
install(EXPORT ${lib_name}_TARGETS
FILE "${JKQTP_CURRENT_TARGET_FILENAME}"
DESTINATION lib/cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${lib_name}Version.cmake"
DESTINATION lib/cmake )
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake )
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${lib_name}Config.cmake"
DESTINATION lib/cmake )
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake )
endfunction(jkqtplotter_installlibrary)



function(jkqtplotter_installlibrary_new lib_name libIncludeSubdir libSrcDir)

# export targets (including headers!)
install(TARGETS ${lib_name}
EXPORT ${lib_name}_TARGETS
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${libIncludeSubdir}
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${libIncludeSubdir}
)
# generate ...Config.cmake
set(JKQTP_CURRENT_TARGET_FILENAME "${lib_name}Targets.cmake")
configure_file(${libSrcDir}/LibTarget.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${lib_name}Config.cmake" @ONLY)
# install export files
install(EXPORT ${lib_name}_TARGETS
FILE "${JKQTP_CURRENT_TARGET_FILENAME}"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${jkqtplotter_cmakeSubdir}
NAMESPACE ${jkqtplotter_namespace}
)

# write CMake version file
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${lib_name}Version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion )

#install PDB-files
if(WIN32 AND MSVC AND (NOT MSVC_VERSION LESS 1600) AND (NOT CMAKE_VERSION VERSION_LESS "3.1") AND BUILD_SHARED_LIBS)
install(FILES $<TARGET_PDB_FILE:${lib_name}> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
endif()

# install ...Version.cmake
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${lib_name}Version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${jkqtplotter_cmakeSubdir} )
# install ...Config.cmake
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${lib_name}Config.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${jkqtplotter_cmakeSubdir} )
# install readme.txt
configure_file(${PROJECT_SOURCE_DIR}/readme.txt.in ${CMAKE_CURRENT_BINARY_DIR}/${lib_name}_Readme.txt @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${lib_name}_Readme.txt" DESTINATION ${CMAKE_INSTALL_DOCDIR} )
# install license
install(FILES "${PROJECT_SOURCE_DIR}/LICENSE" DESTINATION ${CMAKE_INSTALL_DOCDIR}) # RENAME "${lib_name}_LICENSE.txt" )
endfunction(jkqtplotter_installlibrary_new)
Loading

0 comments on commit b0df7a1

Please sign in to comment.