Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QML Support using Qt6 #236

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 16 additions & 119 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
cmake_minimum_required(VERSION 3.16)

set(QTKEYCHAIN_VERSION 0.14.0)
set(QTKEYCHAIN_VERSION 0.14.99)
set(QTKEYCHAIN_SOVERSION 1)

project(qtkeychain VERSION ${QTKEYCHAIN_VERSION} LANGUAGES CXX)

# Enable C++11
SET(CMAKE_CXX_STANDARD 11)

SET(CMAKE_AUTOMOC ON)
include(FindPkgConfig)

###

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${PROJECT_SOURCE_DIR}/cmake/Modules")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules")
include(GNUInstallDirs)
include(GenerateExportHeader)
include(CMakePackageConfigHelpers)
Expand All @@ -21,6 +21,7 @@ include(ECMGeneratePriFile)
include(CMakeDependentOption)

option(BUILD_WITH_QT6 "Build qtkeychain with Qt 6" OFF)
option(QTKEYCHAIN_BUILD_WITH_QML "Build qtkeychain with Qt 6 and QML module support" OFF)
option(BUILD_TEST_APPLICATION "Build test application" OFF)
option(BUILD_TRANSLATIONS "Build translations" ON)
option(BUILD_SHARED_LIBS "Build dynamic library" ON)
Expand Down Expand Up @@ -92,6 +93,9 @@ if (Qt5Core_FOUND AND NOT BUILD_WITH_QT6)
include_directories(${Qt5Core_INCLUDE_DIRS})
else()
find_package(Qt6 COMPONENTS Core REQUIRED)
if(QTKEYCHAIN_BUILD_WITH_QML)
find_package(Qt6 COMPONENTS QML REQUIRED)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit unsure how this dependency fits in with distro packages and the like, one can either disable the dependency to not have the qtkeychain package depend on QML, or enable it, and add the dependency. I guess it's maximally annoying for application developers if then some distros enable QML support and some ignore the flag and thus don't.
I'm leaning to enable QML support by default, and let those who want a minimal build do custom builds with the flag set to OFF.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a developer of an offscreen library depending on Qt Keychain I'd rather be happy not to drag the dependency on QML. As for the CMake part, I think there's a way to introduce this dependency down the line in *Config.cmake file instead and that can even be conditional, but I didn't try it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you relying on distro packages, or are pulling in qtkeychain directly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In CI, I pull Qt Keychain from a tag and build it directly because it's the only way to have one unified logic across 3 platforms; but distros packaging my library have all reasons to link it externally.

endif()
set(QTKEYCHAIN_VERSION_INFIX 6)


Expand Down Expand Up @@ -121,92 +125,15 @@ else()
set(QTCORE_LIBRARIES ${Qt6Core_LIBRARIES})
endif()

set(QTKEYCHAIN_TARGET_NAME qt${QTKEYCHAIN_VERSION_INFIX}keychain)

include_directories(${CMAKE_CURRENT_BINARY_DIR})

list(APPEND qtkeychain_LIBRARIES ${QTCORE_LIBRARIES})
set(qtkeychain_SOURCES
keychain.cpp
qkeychain_export.h
keychain.h
)

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# CMake < 3.15 sneaks in /W# flags for us, so we need a replacement,
# or we'll get a warning (cf. CMP0092)
if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
else()
# MSVC's STL / Qt headers are not MSVC -Wall clean, so don't enable it there
add_definitions( -Wall -Werror=return-type )
endif()

if(WIN32)
list(APPEND qtkeychain_SOURCES keychain_win.cpp)
if (NOT USE_CREDENTIAL_STORE)
list(APPEND qtkeychain_LIBRARIES crypt32)
list(APPEND qtkeychain_SOURCES plaintextstore.cpp)
endif()
#FIXME: mingw bug; otherwise getting undefined refs to RtlSecureZeroMemory there
if(MINGW)
add_definitions( -O2 )
endif()
endif()

if(APPLE)
list(APPEND qtkeychain_SOURCES keychain_apple.mm)
list(APPEND qtkeychain_LIBRARIES "-framework Foundation" "-framework Security")
endif()

if(HAIKU)
list(APPEND qtkeychain_SOURCES keychain_haiku.cpp)

find_library(BE_LIBRARY be REQUIRED)
list(APPEND qtkeychain_LIBRARIES ${BE_LIBRARY})
endif()

if(UNIX AND NOT APPLE AND NOT ANDROID AND NOT HAIKU)
option(LIBSECRET_SUPPORT "Build with libsecret support" ON)

if(LIBSECRET_SUPPORT)
pkg_check_modules(LIBSECRET REQUIRED libsecret-1)
add_definitions(-DHAVE_LIBSECRET=1)
INCLUDE_DIRECTORIES(${LIBSECRET_INCLUDE_DIRS})
LINK_DIRECTORIES(${LIBSECRET_LIBRARY_DIRS})
list(APPEND qtkeychain_LIBRARIES_PRIVATE ${LIBSECRET_LIBRARIES})
endif()

add_definitions(-DKEYCHAIN_DBUS=1)
list(APPEND qtkeychain_SOURCES keychain_unix.cpp gnomekeyring.cpp libsecret.cpp plaintextstore.cpp)
qt_add_dbus_interface(qtkeychain_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/org.kde.KWallet.xml kwallet_interface KWalletInterface)
list(APPEND qtkeychain_LIBRARIES ${QTDBUS_LIBRARIES} )
endif()

if(ANDROID)
list(APPEND qtkeychain_SOURCES keychain_android.cpp androidkeystore.cpp plaintextstore.cpp)
list(APPEND qtkeychain_LIBRARIES_PRIVATE ${QTANDROIDEXTRAS_LIBRARIES} )
endif()

QT_WRAP_CPP(qtkeychain_MOC_OUTFILES keychain.h keychain_p.h gnomekeyring_p.h)

set(qtkeychain_TR_FILES
translations/qtkeychain_de.ts
translations/qtkeychain_fr.ts
translations/qtkeychain_ro.ts
translations/qtkeychain_ru.ts
translations/qtkeychain_zh.ts
)
add_subdirectory(qtkeychain)

set(QTKEYCHAIN_TARGET_NAME qt${QTKEYCHAIN_VERSION_INFIX}keychain)
add_library(${QTKEYCHAIN_TARGET_NAME} ${qtkeychain_SOURCES} ${qtkeychain_MOC_OUTFILES} ${qtkeychain_QM_FILES})
if(WIN32)
set_target_properties( ${QTKEYCHAIN_TARGET_NAME} PROPERTIES DEBUG_POSTFIX "d" )
endif()
###
### Translations
###

file(GLOB qtkeychain_TR_SOURCES *.cpp *.h *.ui)
file(GLOB qtkeychain_TR_SOURCES qtkeychain/*.cpp qtkeychain/*.h qtkeychain/*.ui)
if ( BUILD_TRANSLATIONS )
qt_create_translation(qtkeychain_MESSAGES ${qtkeychain_TR_SOURCES} ${qtkeychain_TR_FILES})
qt_add_translation(qtkeychain_QM_FILES ${qtkeychain_TR_FILES})
Expand Down Expand Up @@ -239,39 +166,10 @@ if ( BUILD_TRANSLATIONS )
endif()
endif( BUILD_TRANSLATIONS )

target_link_libraries(${QTKEYCHAIN_TARGET_NAME} PUBLIC ${qtkeychain_LIBRARIES} PRIVATE ${qtkeychain_LIBRARIES_PRIVATE})
if(NOT INTERFACE_INCLUDE_SUFFIX)
set(INTERFACE_INCLUDE_SUFFIX include)
endif()
target_include_directories(${QTKEYCHAIN_TARGET_NAME} PUBLIC $<INSTALL_INTERFACE:${INTERFACE_INCLUDE_SUFFIX}/>)

generate_export_header(${QTKEYCHAIN_TARGET_NAME}
EXPORT_FILE_NAME qkeychain_export.h
EXPORT_MACRO_NAME QKEYCHAIN_EXPORT
)

set_target_properties(${QTKEYCHAIN_TARGET_NAME} PROPERTIES
VERSION ${QTKEYCHAIN_VERSION}
SOVERSION ${QTKEYCHAIN_SOVERSION}
INSTALL_RPATH_USE_LINK_PATH TRUE
)

if (NOT APPLE)
set_target_properties(${QTKEYCHAIN_TARGET_NAME} PROPERTIES
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
)
endif()

install(FILES keychain.h ${CMAKE_CURRENT_BINARY_DIR}/qkeychain_export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/qt${QTKEYCHAIN_VERSION_INFIX}keychain/
)

install(TARGETS ${QTKEYCHAIN_TARGET_NAME}
EXPORT Qt${QTKEYCHAIN_VERSION_INFIX}KeychainLibraryDepends
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
###
### Test application ("testclient")
###

if(BUILD_TEST_APPLICATION)
set( testclient_LIBRARIES ${QTKEYCHAIN_TARGET_NAME} )
Expand Down Expand Up @@ -325,4 +223,3 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Qt${QTKEYCHAIN_VERSION_INFIX}KeychainC
${CMAKE_CURRENT_BINARY_DIR}/Qt${QTKEYCHAIN_VERSION_INFIX}KeychainConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Qt${QTKEYCHAIN_VERSION_INFIX}Keychain
)

13 changes: 13 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
ChangeLog
=========

version 0.14.3 (release 2024-05-03)

- Fix Android build for Qt 6.7 (Volker Krause <[email protected]>)

version 0.14.2 (release 2023-12-17)

- Add support for KWallet 6 (Volker Krause <[email protected]>)

version 0.14.1 (release 2023-06-01)

- Export QKeychain::isAvailable() to make it usable in a shared build (Volker Krause <[email protected]>)
- Protect against creating the QtKeychain::QtKeychain alias target twice (Volker Krause <[email protected]>)

version 0.14.0 (release 2023-05-12)

- Add Qt 6 Android support (Igor Bugaev <[email protected]>)
Expand Down
2 changes: 1 addition & 1 deletion QtKeychainConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ endif()
set(QTKEYCHAIN_LIBRARIES "@QTKEYCHAIN_TARGET_NAME@")
get_target_property(QTKEYCHAIN_INCLUDE_DIRS "@QTKEYCHAIN_TARGET_NAME@" INTERFACE_INCLUDE_DIRECTORIES)

if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.18.0)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.18.0 AND NOT TARGET Qt@QTKEYCHAIN_VERSION_INFIX@Keychain::Qt@QTKEYCHAIN_VERSION_INFIX@Keychain)
add_library(Qt@QTKEYCHAIN_VERSION_INFIX@Keychain::Qt@QTKEYCHAIN_VERSION_INFIX@Keychain ALIAS qt@QTKEYCHAIN_VERSION_INFIX@keychain)
endif()

Expand Down
42 changes: 42 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,45 @@ License
-------

QtKeychain is available under the [Modified BSD License](http://www.gnu.org/licenses/license-list.html#ModifiedBSD). See the file COPYING for details.


**New:**
==========
Added QML support on Qt6 using cmake
To activate set the qt6 and qml flags

```CMAKE
-DBUILD_WITH_QT6=ON -DQTKEYCHAIN_BUILD_WITH_QML=ON
```

```QML
import QtKeychain 1.0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to think about versioning here. Should it follow the qtkeychain versioning (then this would be 0.15), or not?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna set it to
VERSION "${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}
Becaue the entire QML implementation is in fact the LIbrary so can track the library version.

```

```QML
WritePasswordJob{
id: storeJobObject
service: ""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe set something here for demonstration? Or remove the line

onFinished: {
console.debug("Store password complete")
}
}
ReadPasswordJob{
id: readJobObject
service: ""

}
```

```javascript
storeJobObject.key = "username";
storeJobObject.setTextData("password");
storeJobObject.start();

readJobObject.key = "username"
readJobObject.finished.connect(function (returnedPassword){
console.debug("Password is: "+returnedPassword.textData())
})
readJobObject.start();

```
4 changes: 2 additions & 2 deletions qtkeychain.pri
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ lessThan(QT_MAJOR_VERSION, 5) {
error("qtkeychain requires Qt 5 or later")
}

QTKEYCHAIN_PWD = $$PWD
QTKEYCHAIN_PWD = $$PWD/qtkeychain

CONFIG += depend_includepath
DEFINES += QTKEYCHAIN_NO_EXPORT
Expand Down Expand Up @@ -43,7 +43,7 @@ unix:!android:!macx:!ios {
# Generate D-Bus interface:
DEFINES += KEYCHAIN_DBUS
QT += dbus
kwallet_interface.files = $$PWD/org.kde.KWallet.xml
kwallet_interface.files = $$QTKEYCHAIN_PWD/org.kde.KWallet.xml
DBUS_INTERFACES += kwallet_interface

HEADERS += \
Expand Down
Loading