From 40aa0fcaba42b43d29ccdcce889b7ac456386197 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 7 Oct 2020 00:11:18 +0200 Subject: [PATCH] CMake: add a helper module for finding KPMcore I think we had this (kind of) module a long time ago and it was removed for over-complicating things; re-introduce one now that KPMcore is used in 3 different places and all would benefit from consistent API handling / defines. --- CMakeModules/KPMcoreHelper.cmake | 39 ++++++++++++++++++++++++++++ src/libcalamares/CMakeLists.txt | 21 ++------------- src/modules/fsresizer/CMakeLists.txt | 15 +++-------- src/modules/partition/CMakeLists.txt | 18 +++---------- 4 files changed, 47 insertions(+), 46 deletions(-) create mode 100644 CMakeModules/KPMcoreHelper.cmake diff --git a/CMakeModules/KPMcoreHelper.cmake b/CMakeModules/KPMcoreHelper.cmake new file mode 100644 index 000000000..6aacfc95c --- /dev/null +++ b/CMakeModules/KPMcoreHelper.cmake @@ -0,0 +1,39 @@ +# === This file is part of Calamares - === +# +# SPDX-FileCopyrightText: 2020 Adriaan de Groot +# SPDX-License-Identifier: BSD-2-Clause +# +### +# +# Finds KPMcore and consistently sets API flags based on the version. +# +if ( NOT KPMcore_searched_for ) + set( KPMcore_searched_for TRUE ) + + find_package( KPMcore 3.3 ) + set_package_properties( + KPMcore PROPERTIES + URL "https://invent.kde.org/kde/kpmcore" + DESCRIPTION "KDE Partitioning library" + TYPE RECOMMENDED + PURPOSE "For disk partitioning support" + ) + + if( KPMcore_FOUND ) + set( KPMcore_API_DEFINITIONS "" ) + if( KPMcore_VERSION VERSION_GREATER "3.3.70" AND KPMcore_VERSION VERSION_LESS "4.0" ) + message( FATAL_ERROR "KPMCore beta versions ${KPMcore_VERSION} not supported" ) + endif() + if ( KPMcore_VERSION VERSION_GREATER "3.3.0") + list( APPEND KPMcore_API_DEFINITIONS WITH_KPMCORE331API) # kpmcore > 3.3.0 with deprecations + endif() + if ( KPMcore_VERSION VERSION_GREATER_EQUAL "4.0") + list( APPEND KPMcore_API_DEFINITIONS WITH_KPMCORE4API) # kpmcore 4 with new API + endif() + if( KPMcore_VERSION VERSION_GREATER_EQUAL "4.2" ) + list( APPEND KPMcore_API_DEFINITIONS WITH_KPMCORE42API) # kpmcore 4.2 with new API + endif() + else() + set( KPMcore_API_DEFINITIONS WITHOUT_KPMcore ) + endif() +endif() diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index be5b252f0..1ddcfb5a8 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -114,30 +114,13 @@ endif() ### OPTIONAL KPMcore support # # -find_package( KPMcore 3.3 ) -set_package_properties( - KPMcore PROPERTIES - URL "https://invent.kde.org/kde/kpmcore" - DESCRIPTION "KDE Partitioning library" - TYPE RECOMMENDED - PURPOSE "For partitioning service" -) +include( KPMcoreHelper ) if ( KPMcore_FOUND ) find_package( Qt5 REQUIRED DBus ) # Needed for KPMCore find_package( KF5 REQUIRED I18n WidgetsAddons ) # Needed for KPMCore - if( KPMcore_VERSION VERSION_GREATER_EQUAL "4.2" ) - add_definitions( - -DWITH_KPMCORE42API - -DWITH_KPMCORE4API - ) # kpmcore 4.2 with new API - elseif( KPMcore_VERSION VERSION_GREATER_EQUAL "4.0" ) - add_definitions( -DWITH_KPMCORE4API ) # kpmcore 4 with new API - elseif( KPMcore_VERSION VERSION_GREATER "3.3.70" ) - message( FATAL_ERROR "KPMCore beta versions ${KPMcore_VERSION} not supported" ) - endif() - + add_definitions( ${KPMcore_API_DEFINITIONS} ) include_directories( ${KPMCORE_INCLUDE_DIR} ) list( APPEND libSources partition/FileSystem.cpp diff --git a/src/modules/fsresizer/CMakeLists.txt b/src/modules/fsresizer/CMakeLists.txt index 7fdea1ff2..17b72b68a 100644 --- a/src/modules/fsresizer/CMakeLists.txt +++ b/src/modules/fsresizer/CMakeLists.txt @@ -3,24 +3,15 @@ # SPDX-FileCopyrightText: 2020 Adriaan de Groot # SPDX-License-Identifier: BSD-2-Clause # -find_package( KPMcore 3.3 ) find_package( KF5Config CONFIG ) find_package( KF5I18n CONFIG ) find_package( KF5WidgetsAddons CONFIG ) -set( _partition_defs "" ) +include( KPMcoreHelper ) if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND ) include_directories( ${KPMCORE_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/modules/partition ) - if( KPMcore_VERSION VERSION_GREATER_EQUAL "4.2" ) - list( APPEND _partition_defs WITH_KPMCORE42API WITH_KPMCORE4API ) # kpmcore 4.2 with new API - elseif( KPMcore_VERSION VERSION_GREATER_EQUAL "4.0" ) - list( APPEND _partition_defs WITH_KPMCORE4API ) # kpmcore 4 with new API - elseif( KPMcore_VERSION VERSION_GREATER "3.3.70" ) - message( FATAL_ERROR "KPMCore beta versions ${KPMcore_VERSION} are not supported" ) - endif() - # The PartitionIterator is a small class, and it's easiest -- but also a # gross hack -- to just compile it again from the partition module tree. calamares_add_plugin( fsresizer @@ -31,7 +22,7 @@ if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND LINK_PRIVATE_LIBRARIES kpmcore calamares - COMPILE_DEFINITIONS ${_partition_defs} + COMPILE_DEFINITIONS ${KPMcore_API_DEFINITIONS} SHARED_LIB ) @@ -42,7 +33,7 @@ if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND LIBRARIES calamares_job_fsresizer # From above yamlcpp - DEFINITIONS ${_partition_defs} + DEFINITIONS ${KPMcore_API_DEFINITIONS} ) else() if ( NOT KPMcore_FOUND ) diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 6bfec6bb1..b623309c5 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -31,26 +31,14 @@ endif() find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE) -find_package( KPMcore 3.3 ) -set_package_properties( - KPMcore PROPERTIES - PURPOSE "For partition module" -) +include( KPMcoreHelper ) + find_package( KF5Config CONFIG ) find_package( KF5I18n CONFIG ) find_package( KF5WidgetsAddons CONFIG ) if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND ) - if ( KPMcore_VERSION VERSION_GREATER "3.3.0") - list( APPEND _partition_defs WITH_KPMCORE331API) # kpmcore > 3.3.0 with deprecations - endif() - if ( KPMcore_VERSION VERSION_GREATER_EQUAL "4.0") - list( APPEND _partition_defs WITH_KPMCORE4API) # kpmcore 4 with new API - endif() - if( KPMcore_VERSION VERSION_GREATER_EQUAL "4.2" ) - list( APPEND _partition_defs WITH_KPMCORE42API) # kpmcore 4.2 with new API - endif() - + list( APPEND _partition_defs ${KPMcore_API_DEFINITIONS} ) include_directories( ${KPMCORE_INCLUDE_DIR} ) include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )