From dc5a38e61c7cfad62c5930177bc3f95ecfebbf88 Mon Sep 17 00:00:00 2001 From: Scott Furry Date: Fri, 17 May 2019 02:17:51 -0600 Subject: [PATCH] Modify Qt5 CMake and include Qt Charts Option (#1837) Update CMake search for Qt5 componets to be consistent with recommended practice from Kitware. (see https://blog.kitware.com/cmake-finding-qt5-the-right-way/) Incorporate ability to build cppcheck-gui with Qt Charts via CMake switch. Option "WITH_QCHARTS" will enable search for Qt Charts to Qt5 component search and add build flag "HAVE_QCHART". --- cmake/findDependencies.cmake | 10 +++++----- cmake/options.cmake | 1 + cmake/printInfo.cmake | 1 + gui/CMakeLists.txt | 4 ++++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmake/findDependencies.cmake b/cmake/findDependencies.cmake index 3ad351089..8599e1b81 100644 --- a/cmake/findDependencies.cmake +++ b/cmake/findDependencies.cmake @@ -1,9 +1,9 @@ if (BUILD_GUI) - find_package(Qt5Core) - find_package(Qt5Gui) - find_package(Qt5Widgets) - find_package(Qt5PrintSupport) - find_package(Qt5LinguistTools) + if (NOT WITH_QCHART) + find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools REQUIRED) + else() + find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Charts REQUIRED) + endif() endif() if (HAVE_RULES) diff --git a/cmake/options.cmake b/cmake/options.cmake index 3c96ca811..3926a5d53 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -37,6 +37,7 @@ endif() option(BUILD_TESTS "Build tests" OFF) option(BUILD_GUI "Build the qt application" OFF) +option(WITH_QCHART "When building GUI(need BUILD_GUI=ON), use Qt5 Charts" OFF) option(HAVE_RULES "Usage of rules (needs PCRE library and headers)" OFF) diff --git a/cmake/printInfo.cmake b/cmake/printInfo.cmake index 7f1fb5b96..6cc345f66 100644 --- a/cmake/printInfo.cmake +++ b/cmake/printInfo.cmake @@ -29,6 +29,7 @@ message( STATUS ) message( STATUS "BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}" ) message( STATUS "BUILD_TESTS = ${BUILD_TESTS}" ) message( STATUS "BUILD_GUI = ${BUILD_GUI}" ) +message( STATUS "WITH_QCHART = ${WITH_QCHART}" ) message( STATUS ) message( STATUS "HAVE_RULES = ${HAVE_RULES}" ) message( STATUS ) diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 8d2009202..1678dbbe1 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -25,6 +25,10 @@ if (BUILD_GUI) target_link_libraries(cppcheck-gui pcre) endif() target_link_libraries(cppcheck-gui Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport) + if(WITH_QCHART) + target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART ) + target_link_libraries(cppcheck-gui Qt5::Charts) + endif() install(TARGETS cppcheck-gui RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT applications) install(FILES ${qms} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT applications)