Skip to content

Commit

Permalink
Merge pull request #11 from ahmadsamir/work/ahmad/port
Browse files Browse the repository at this point in the history
Support building with Qt6
  • Loading branch information
DamirPorobic authored Jan 9, 2024
2 parents 15e1637 + e62b362 commit cddaa83
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 46 deletions.
58 changes: 34 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ set(CMAKE_AUTORCC ON)
option(BUILD_TESTS "Build Unit Tests" OFF)
option(BUILD_EXAMPLE "Build Example Application" ON)

find_package(Qt5 ${QT_MIN_VERSION} REQUIRED Widgets)
option(BUILD_WITH_QT6 "Build with Qt6" OFF)
if(BUILD_WITH_QT6)
set(CMAKE_CXX_STANDARD 17)
set(QT_MAJOR_VERSION 6)
set(kColorPicker_LIB_NAME "kColorPicker-Qt6")
else()
set(QT_MAJOR_VERSION 5)
set(kColorPicker_LIB_NAME "kColorPicker-Qt5")
endif()

find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} REQUIRED Widgets)

include(GNUInstallDirs)
include(FeatureSummary)
Expand All @@ -27,33 +37,33 @@ if (BUILD_EXAMPLE)
endif (BUILD_EXAMPLE)

if (BUILD_TESTS)
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED Test)
find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} REQUIRED Test)
enable_testing()
add_subdirectory(tests)
endif (BUILD_TESTS)

include(CMakePackageConfigHelpers)

add_library(kColorPicker
add_library(${kColorPicker_LIB_NAME}
${KCOLORPICKER_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/include/kColorPicker/KColorPicker.h
${CMAKE_CURRENT_SOURCE_DIR}/icons/kColorPicker_icons.qrc
)

add_library(kColorPicker::kColorPicker ALIAS kColorPicker)
#add_library(kColorPicker::kColorPicker ALIAS kColorPicker)

target_include_directories(kColorPicker
target_include_directories(${kColorPicker_LIB_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>/${kColorPicker_LIB_NAME}
)

target_link_libraries(kColorPicker PUBLIC Qt5::Widgets)
target_link_libraries(${kColorPicker_LIB_NAME} PUBLIC Qt${QT_MAJOR_VERSION}::Widgets)

target_compile_definitions(kColorPicker PRIVATE KIMAGEANNOTATOR_LIB)
target_compile_definitions(${kColorPicker_LIB_NAME} PRIVATE KIMAGEANNOTATOR_LIB)

set_target_properties(kColorPicker
set_target_properties(${kColorPicker_LIB_NAME}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
Expand All @@ -62,43 +72,43 @@ set_target_properties(kColorPicker
SOVERSION 0
)

install(TARGETS kColorPicker
EXPORT kColorPicker-targets
install(TARGETS ${kColorPicker_LIB_NAME}
EXPORT ${kColorPicker_LIB_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/kColorPicker
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${kColorPicker_LIB_NAME}
)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/kColorPickerConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/kColorPickerConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kColorPicker
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${kColorPicker_LIB_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/${kColorPicker_LIB_NAME}Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${kColorPicker_LIB_NAME}
)

write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/cmake/kColorPickerConfig-version.cmake
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/cmake/${kColorPicker_LIB_NAME}Config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/cmake/kColorPickerConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/kColorPickerConfig-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kColorPicker
${CMAKE_CURRENT_BINARY_DIR}/cmake/${kColorPicker_LIB_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/${kColorPicker_LIB_NAME}Config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${kColorPicker_LIB_NAME}
)


export(EXPORT kColorPicker-targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/kColorPicker-targets.cmake
export(EXPORT ${kColorPicker_LIB_NAME}-targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/${kColorPicker_LIB_NAME}-targets.cmake
NAMESPACE kColorPicker::
)

install(EXPORT kColorPicker-targets
FILE kColorPicker-targets.cmake
install(EXPORT ${kColorPicker_LIB_NAME}-targets
FILE ${kColorPicker_LIB_NAME}-targets.cmake
NAMESPACE kColorPicker::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kColorPicker
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${kColorPicker_LIB_NAME}
)

# uninstall target
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Version 0.2.0
`$ mkdir build && cd build`
4. Create the makefile and build the project:
`$ cmake .. && make`
to build with Qt6, pass `-DBUILD_WITH_QT6=true` to the `cmake` command
5. Install shared library (not required when only using the example):
`$ sudo make install`
6. Run the example application:
Expand All @@ -30,11 +31,17 @@ only build as static library.

1. Let cmake find the shared library, optionally with version
`set(KCOLORPICKER_MIN_VERSION "0.x.x")`
`find_package(kColorPicker ${KCOLORPICKER_MIN_VERSION} REQUIRED)`
to build with Qt5:
`find_package(kColorPicker-Qt5 ${KCOLORPICKER_MIN_VERSION} REQUIRED)`
to build with Qt6:
`find_package(kColorPicker-Qt6 ${KCOLORPICKER_MIN_VERSION} REQUIRED)`

2. Link the library with your application
`target_link_libraries(myApp kColorPicker)`
if you built with Qt5:
`target_link_libraries(myApp kColorPicker-Qt5)`
if you built with Qt6:
`target_link_libraries(myApp kColorPicker-Qt6)`


[github-badge]: https://github.com/ksnip/kColorPicker/actions/workflows/build.yml/badge.svg
[github-url]: https://github.com/ksnip/kColorPicker/actions
[github-url]: https://github.com/ksnip/kColorPicker/actions
9 changes: 9 additions & 0 deletions cmake/kColorPicker-Qt5Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include(CMakeFindDependencyMacro)

@PACKAGE_INIT@

find_dependency(Qt5 @QT_MIN_VERSION@ COMPONENTS Widgets)

if(NOT TARGET kColorPicker::kColorPicker-Qt5)
include("${CMAKE_CURRENT_LIST_DIR}/kColorPicker-Qt5-targets.cmake")
endif()
9 changes: 9 additions & 0 deletions cmake/kColorPicker-Qt6Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include(CMakeFindDependencyMacro)

@PACKAGE_INIT@

find_dependency(Qt6 @QT_MIN_VERSION@ COMPONENTS Widgets)

if(NOT TARGET kColorPicker::kColorPicker-Qt6)
include("${CMAKE_CURRENT_LIST_DIR}/kColorPicker-Qt6-targets.cmake")
endif()
9 changes: 0 additions & 9 deletions cmake/kColorPickerConfig.cmake.in

This file was deleted.

2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_executable(kColorPicker-example main.cpp)

target_link_libraries(kColorPicker-example kColorPicker)
target_link_libraries(kColorPicker-example ${kColorPicker_LIB_NAME})
4 changes: 2 additions & 2 deletions example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <QApplication>
#include <QVBoxLayout>
#include <kColorPicker/KColorPicker.h>
#include "kColorPicker/KColorPicker.h"

using kColorPicker::KColorPicker;

Expand All @@ -37,4 +37,4 @@ int main(int argc, char **argv)
widget->show();

return app.exec();
}
}
2 changes: 1 addition & 1 deletion include/kColorPicker/KColorPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <QColor>
#include <QList>

#include <kColorPicker/KColorPickerExport.h>
#include "kColorPicker/KColorPickerExport.h"

namespace kColorPicker {

Expand Down
2 changes: 1 addition & 1 deletion src/KColorPicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Boston, MA 02110-1301, USA.
*/

#include <kColorPicker/KColorPicker.h>
#include "kColorPicker/KColorPicker.h"

#include "IconCreator.h"
#include "PopupMenu.h"
Expand Down
4 changes: 2 additions & 2 deletions src/PopupMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PopupMenu::PopupMenu(bool showAlphaChannel, QWidget *parent) :
mColorDialogButton(new ColorDialogButton(QIcon(QLatin1String(":/icons/ellipsis")), showAlphaChannel))
{
mLayout->setSpacing(0);
mLayout->setMargin(5);
mLayout->setContentsMargins(5, 5, 5, 5);
setLayout(mLayout);

connect(mColorDialogButton, &AbstractPopupMenuButton::colorSelected, this, &PopupMenu::colorSelected);
Expand Down Expand Up @@ -136,4 +136,4 @@ QSize PopupMenu::sizeHint() const
return mLayout->sizeHint();
}

} // namespace kColorPicker
} // namespace kColorPicker
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ set(UNITTEST_SRC

add_library(KCOLORPICKER_STATIC STATIC ${KCOLORPICKER_SRCS})

target_link_libraries(KCOLORPICKER_STATIC Qt5::Widgets kColorPicker)
target_link_libraries(KCOLORPICKER_STATIC Qt${QT_MAJOR_VERSION}::Widgets ${kColorPicker_LIB_NAME})

foreach (UnitTest ${UNITTEST_SRC})
get_filename_component(UnitTestName ${UnitTest} NAME_WE)
add_executable(${UnitTestName} ${UnitTest})
target_link_libraries(${UnitTestName} KCOLORPICKER_STATIC Qt5::Test)
target_link_libraries(${UnitTestName} KCOLORPICKER_STATIC Qt${QT_MAJOR_VERSION}::Test)
add_test(${UnitTestName} ${UnitTestName})
endforeach (UnitTest)
endforeach (UnitTest)

0 comments on commit cddaa83

Please sign in to comment.