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.
This commit is contained in:
Adriaan de Groot 2020-10-07 00:11:18 +02:00
parent db537535ee
commit 40aa0fcaba
4 changed files with 47 additions and 46 deletions

View File

@ -0,0 +1,39 @@
# === This file is part of Calamares - <https://calamares.io> ===
#
# SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
# 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()

View File

@ -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

View File

@ -3,24 +3,15 @@
# SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
# 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 )

View File

@ -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 )