CMake: modernize optional parts of libcalamares

This commit is contained in:
Adriaan de Groot 2022-04-25 15:23:27 +02:00
parent 53926b8bbe
commit d7459e2bfe

View File

@ -17,10 +17,9 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CalamaresConfig.h.in ${CMAKE_CURRENT_
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CalamaresVersion.h.in ${CMAKE_CURRENT_BINARY_DIR}/CalamaresVersion.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CalamaresVersion.h.in ${CMAKE_CURRENT_BINARY_DIR}/CalamaresVersion.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CalamaresVersionX.h.in ${CMAKE_CURRENT_BINARY_DIR}/CalamaresVersionX.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CalamaresVersionX.h.in ${CMAKE_CURRENT_BINARY_DIR}/CalamaresVersionX.h)
set(OPTIONAL_PRIVATE_LIBRARIES "") add_library(
set(OPTIONAL_PUBLIC_LIBRARIES "") calamares
SHARED
set(libSources
CppJob.cpp CppJob.cpp
GlobalStorage.cpp GlobalStorage.cpp
Job.cpp Job.cpp
@ -75,20 +74,29 @@ set(libSources
utils/Yaml.cpp utils/Yaml.cpp
) )
set_target_properties(
calamares
PROPERTIES
VERSION ${CALAMARES_VERSION_SHORT}
SOVERSION ${CALAMARES_VERSION_SHORT}
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_INSTALL_FULL_INCLUDEDIR}/libcalamares
)
target_link_libraries(calamares LINK_PUBLIC yamlcpp::yamlcpp Qt5::Core KF5::CoreAddons)
### OPTIONAL Automount support (requires dbus) ### OPTIONAL Automount support (requires dbus)
# #
# #
if(Qt5DBus_FOUND) if(Qt5DBus_FOUND)
list(APPEND libSources partition/AutoMount.cpp) target_sources(calamares PRIVATE partition/AutoMount.cpp)
list(APPEND OPTIONAL_PRIVATE_LIBRARIES Qt5::DBus) target_link_libraries(calamares PRIVATE Qt5::DBus)
endif() endif()
### OPTIONAL Python support ### OPTIONAL Python support
# #
# #
if(WITH_PYTHON) if(WITH_PYTHON)
list(APPEND libSources PythonHelper.cpp PythonJob.cpp PythonJobApi.cpp) target_sources(calamares PRIVATE PythonHelper.cpp PythonJob.cpp PythonJobApi.cpp)
list(APPEND OPTIONAL_PRIVATE_LIBRARIES Python::Python Boost::python) target_link_libraries(calamares PRIVATE Python::Python Boost::python)
endif() endif()
### OPTIONAL GeoIP XML support ### OPTIONAL GeoIP XML support
@ -96,8 +104,8 @@ endif()
# #
find_package(Qt5 COMPONENTS Xml) find_package(Qt5 COMPONENTS Xml)
if(Qt5Xml_FOUND) if(Qt5Xml_FOUND)
list(APPEND libSources geoip/GeoIPXML.cpp) target_sources(calamares PRIVATE geoip/GeoIPXML.cpp)
list(APPEND OPTIONAL_PUBLIC_LIBRARIES Qt5::Network Qt5::Xml) target_link_libraries(calamares PRIVATE Qt5::Network Qt5::Xml)
endif() endif()
### OPTIONAL KPMcore support ### OPTIONAL KPMcore support
@ -113,36 +121,21 @@ if(KPMcore_FOUND)
add_definitions(-D${d}) add_definitions(-D${d})
endforeach() endforeach()
include_directories(${KPMCORE_INCLUDE_DIR}) include_directories(${KPMCORE_INCLUDE_DIR})
list( target_sources(
APPEND calamares
libSources PRIVATE
partition/FileSystem.cpp partition/FileSystem.cpp
partition/KPMManager.cpp partition/KPMManager.cpp
partition/PartitionIterator.cpp partition/PartitionIterator.cpp
partition/PartitionQuery.cpp partition/PartitionQuery.cpp
) )
list(APPEND OPTIONAL_PRIVATE_LIBRARIES kpmcore) target_link_libraries(calamares PRIVATE kpmcore)
endif() endif()
### LIBRARY ### LIBRARY
# #
# #
add_library(calamares SHARED ${libSources})
set_target_properties(
calamares
PROPERTIES
VERSION ${CALAMARES_VERSION_SHORT}
SOVERSION ${CALAMARES_VERSION_SHORT}
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_INSTALL_FULL_INCLUDEDIR}/libcalamares
)
calamares_automoc( calamares ) calamares_automoc( calamares )
target_link_libraries(
calamares
LINK_PRIVATE ${OPTIONAL_PRIVATE_LIBRARIES}
LINK_PUBLIC yamlcpp::yamlcpp Qt5::Core KF5::CoreAddons ${OPTIONAL_PUBLIC_LIBRARIES}
)
add_library(Calamares::calamares ALIAS calamares) add_library(Calamares::calamares ALIAS calamares)
### Installation ### Installation
@ -181,13 +174,9 @@ foreach(subdir geoip locale modulesystem network partition utils)
install(FILES ${subdir_headers} DESTINATION include/libcalamares/${subdir}) install(FILES ${subdir_headers} DESTINATION include/libcalamares/${subdir})
endforeach() endforeach()
### TESTING ### TRANSLATION TESTING
# #
# # This is a support function, used just once, to help out the localetest
calamares_add_test(libcalamarestest SOURCES Tests.cpp)
calamares_add_test(libcalamaresgeoiptest SOURCES geoip/GeoIPTests.cpp ${geoip_src})
function(calamares_qrc_translations basename) function(calamares_qrc_translations basename)
set(NAME ${ARGV0}) set(NAME ${ARGV0})
set(options "") set(options "")
@ -238,6 +227,14 @@ function(calamares_qrc_translations basename)
endfunction() endfunction()
calamares_qrc_translations( localetest OUTPUT_VARIABLE localetest_qrc SUBDIRECTORY testdata LANGUAGES nl ) calamares_qrc_translations( localetest OUTPUT_VARIABLE localetest_qrc SUBDIRECTORY testdata LANGUAGES nl )
### TESTING
#
#
calamares_add_test(libcalamarestest SOURCES Tests.cpp)
calamares_add_test(libcalamaresgeoiptest SOURCES geoip/GeoIPTests.cpp ${geoip_src})
calamares_add_test(libcalamareslocaletest SOURCES locale/Tests.cpp ${localetest_qrc}) calamares_add_test(libcalamareslocaletest SOURCES locale/Tests.cpp ${localetest_qrc})
calamares_add_test(libcalamaresmodulesystemtest SOURCES modulesystem/Tests.cpp) calamares_add_test(libcalamaresmodulesystemtest SOURCES modulesystem/Tests.cpp)
@ -246,18 +243,9 @@ calamares_add_test(libcalamaresnetworktest SOURCES network/Tests.cpp)
calamares_add_test(libcalamarespackagestest SOURCES packages/Tests.cpp) calamares_add_test(libcalamarespackagestest SOURCES packages/Tests.cpp)
calamares_add_test(
libcalamarespartitiontest
SOURCES partition/Global.cpp partition/Tests.cpp
LIBRARIES ${OPTIONAL_PRIVATE_LIBRARIES}
)
if(KPMcore_FOUND) if(KPMcore_FOUND)
calamares_add_test( calamares_add_test(libcalamarespartitiontest SOURCES partition/Global.cpp partition/Tests.cpp LIBRARIES kpmcore)
libcalamarespartitionkpmtest calamares_add_test(libcalamarespartitionkpmtest SOURCES partition/KPMTests.cpp LIBRARIES kpmcore)
SOURCES partition/KPMTests.cpp
LIBRARIES ${OPTIONAL_PRIVATE_LIBRARIES}
)
endif() endif()
calamares_add_test(libcalamaresutilstest SOURCES utils/Tests.cpp utils/Runner.cpp) calamares_add_test(libcalamaresutilstest SOURCES utils/Tests.cpp utils/Runner.cpp)