From 4a2a34cc6b11c5e63ccae3aa9ce0d6bf489149ee Mon Sep 17 00:00:00 2001 From: przemek83 <4788832+przemek83@users.noreply.github.com> Date: Wed, 27 Nov 2024 09:36:23 +0100 Subject: [PATCH] Rework CMake files. --- CMakeLists.txt | 80 ++++++++++++++++++++++------------------ examples/CMakeLists.txt | 19 ++++------ examples/example.cpp | 17 +++++---- qwtble.pc.in | 12 ++++++ test/GroupPlotUITest.cpp | 3 +- test/QuantilesTest.cpp | 3 +- test/UtilitiesTest.cpp | 2 +- 7 files changed, 78 insertions(+), 58 deletions(-) create mode 100644 qwtble.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a9c6f7..e632bca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,45 +22,59 @@ qt_standard_project_setup() include(qwt_setup.cmake) -set(SOURCES +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +set(${PROJECT_NAME}_SOURCES + src/qwtble_global.h + src/BasicDataPlot.h src/BasicDataPlot.cpp + src/YAxisNumberPicker.h src/YAxisNumberPicker.cpp + src/GroupPlot.h src/GroupPlot.cpp + src/HistogramPlot.h src/HistogramPlot.cpp + src/XYAxisNumberPicker.h src/XYAxisNumberPicker.cpp + src/XDateYAxisNumberPicker.h src/XDateYAxisNumberPicker.cpp + src/NotchedMarker.h src/NotchedMarker.cpp + src/Picker.h src/Picker.cpp + src/PlotBase.h src/PlotBase.cpp + src/PlotMagnifier.h src/PlotMagnifier.cpp + src/QuantilesPlot.h src/QuantilesPlot.cpp + src/StringsScaleDraw.h src/StringsScaleDraw.cpp + src/Quantiles.h src/Quantiles.cpp + src/QwtBleUtilities.h src/QwtBleUtilities.cpp + src/GroupPlotUI.h src/GroupPlotUI.cpp + src/HistogramPlotUI.h src/HistogramPlotUI.cpp + src/Utilities.h src/Utilities.cpp ) -set(HEADERS +set(PUBLIC_HEADERS src/qwtble_global.h src/BasicDataPlot.h - src/YAxisNumberPicker.h src/GroupPlot.h src/HistogramPlot.h - src/XYAxisNumberPicker.h - src/XDateYAxisNumberPicker.h - src/NotchedMarker.h - src/Picker.h src/PlotBase.h - src/PlotMagnifier.h src/QuantilesPlot.h - src/StringsScaleDraw.h src/Quantiles.h src/QwtBleUtilities.h + src/NotchedMarker.h src/GroupPlotUI.h src/HistogramPlotUI.h - src/Utilities.h ) set(UI @@ -69,29 +83,32 @@ set(UI ) source_group("UI Files" FILES ${UI}) -add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS} ${UI}) +add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SOURCES} ${UI}) -set(PUBLIC_HEADERS - src/qwtble_global.h - src/BasicDataPlot.h - src/GroupPlot.h - src/HistogramPlot.h - src/PlotBase.h - src/QuantilesPlot.h - src/Quantiles.h - src/QwtBleUtilities.h - src/NotchedMarker.h - src/GroupPlotUI.h - src/HistogramPlotUI.h -) +target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $ + PRIVATE + $) set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} - SOVERSION 1 - PUBLIC_HEADER "${PUBLIC_HEADERS}" -) + SOVERSION ${PROJECT_VERSION_MAJOR} + PUBLIC_HEADER "${PUBLIC_HEADERS}") + +configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -target_include_directories(${PROJECT_NAME} PUBLIC src) +target_compile_definitions(${PROJECT_NAME} PRIVATE QWTBLE_LIBRARY) + +install(TARGETS ${PROJECT_NAME} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) + +install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Widgets) if (WIN32) @@ -100,13 +117,6 @@ else() target_link_libraries(${PROJECT_NAME} PRIVATE qwt) endif() -target_compile_definitions(${PROJECT_NAME} PRIVATE QWTBLE_LIBRARY) - -include(GNUInstallDirs) -install(TARGETS ${PROJECT_NAME} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) - add_subdirectory(examples) enable_testing() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 0ae51b0..0e68fef 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,17 +1,12 @@ -project(examples) +SET(PROJECT_TEST ${PROJECT_NAME}-example) -set(SOURCES +include_directories(${CMAKE_SOURCE_DIR}) + +set(${PROJECT_TEST}_SOURCES example.cpp ) -add_executable(examples ${SOURCES}) - -target_link_libraries(examples PRIVATE Qt6::Core Qt6::Widgets qwtble) - -if (WIN32) - target_link_libraries(${PROJECT_NAME} PRIVATE optimized qwt debug qwtd) -else() - target_link_libraries(${PROJECT_NAME} PRIVATE qwt) -endif() - +add_executable(${PROJECT_TEST} ${${PROJECT_TEST}_SOURCES}) +target_link_libraries(${PROJECT_TEST} PRIVATE qwtble Qt6::Test Qt6::Widgets) +add_test(NAME ${PROJECT_TEST} COMMAND ${PROJECT_TEST}) diff --git a/examples/example.cpp b/examples/example.cpp index 207b8d4..f3eaca7 100644 --- a/examples/example.cpp +++ b/examples/example.cpp @@ -6,14 +6,15 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include static QVector> exampleValues{ {3.5, 6.7, 4.7, 6.6, 3., 4.9}, diff --git a/qwtble.pc.in b/qwtble.pc.in new file mode 100644 index 0000000..5fa8600 --- /dev/null +++ b/qwtble.pc.in @@ -0,0 +1,12 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ + +Name: @PROJECT_NAME@ +Description: @PROJECT_DESCRIPTION@ +Version: @PROJECT_VERSION@ + +Requires: +Libs: -L${libdir} -l@PROJECT_NAME@ +Cflags: -I${includedir} \ No newline at end of file diff --git a/test/GroupPlotUITest.cpp b/test/GroupPlotUITest.cpp index 3b1c184..e961fb4 100644 --- a/test/GroupPlotUITest.cpp +++ b/test/GroupPlotUITest.cpp @@ -1,10 +1,11 @@ #include "GroupPlotUITest.h" -#include #include #include #include +#include + void GroupPlotUITest::testTraitChange() { const GroupPlotUI groupPlotUI({{"a", 0}, {"b", 1}, {"c", 2}}); diff --git a/test/QuantilesTest.cpp b/test/QuantilesTest.cpp index 0993730..89b5233 100644 --- a/test/QuantilesTest.cpp +++ b/test/QuantilesTest.cpp @@ -1,9 +1,10 @@ #include "QuantilesTest.h" -#include #include #include +#include + void QuantilesTest::testToolTip() { Quantiles quantiles; diff --git a/test/UtilitiesTest.cpp b/test/UtilitiesTest.cpp index 57da31b..bdc8257 100644 --- a/test/UtilitiesTest.cpp +++ b/test/UtilitiesTest.cpp @@ -2,7 +2,7 @@ #include -#include "QwtBleUtilities.h" +#include void UtilitiesTest::testStringFromDays() {