Skip to content

Commit

Permalink
Merge branch 'dll-export'
Browse files Browse the repository at this point in the history
  • Loading branch information
dlyr committed Jun 9, 2022
2 parents c493cc9 + a85d8ce commit 4743322
Show file tree
Hide file tree
Showing 13 changed files with 553 additions and 296 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,5 @@ installed-*
# Scripts
*.bat

# Json
# Json
*.json


9 changes: 9 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.yaml
default: true
MD002: false
MD033: false

MD013:
line_length: 120
MD034: false
MD041: false
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
ci:
skip: [clang-format]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: trailing-whitespace
exclude: ^tests/.*/data/.*$
- id: end-of-file-fixer
exclude: ^tests/.*/data/.*$
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
# - id: cmake-lint
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
args: [--style=file, -i]
# - id: clang-tidy
# args: [-checks=clang-diagnostic-return-type]
# - id: oclint
# args: [-enable-clang-static-analyzer, -enable-global-analysis]
# - id: uncrustify
# - id: cppcheck
# args: [--enable=all]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.31.1
hooks:
- id: markdownlint
args: [-f]
149 changes: 67 additions & 82 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,124 +1,109 @@
cmake_minimum_required(VERSION 3.12)
cmake_policy(SET CMP0077 NEW)

project(PowerSlider)

option(BUILD_DESIGNER_PLUGIN "Build Qt Designer Plugin" ON)
option(BUILD_EXAMPLE_APP "Build example app" ON)

#
# Qt5 and Qt6 can be retrieved using versionless targets introduced in Qt5.15:
# https://doc.qt.io/qt-6/cmake-qt5-and-qt6-compatibility.html#versionless-targets
macro(find_qt_package)
set(options REQUIRED)
set(oneValueArgs "")
set(multiValueArgs COMPONENTS)

cmake_parse_arguments(MY_OPTIONS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(NOT MY_OPTIONS_COMPONENTS) # User didn't enter any component
set(MY_OPTIONS_COMPONENTS "")
endif()

find_package(Qt6 COMPONENTS ${MY_OPTIONS_COMPONENTS} QUIET)
if(NOT Qt6_FOUND)
if(${MY_OPTIONS_REQUIRED})
find_package(Qt5 5.15 COMPONENTS ${MY_OPTIONS_COMPONENTS} REQUIRED)
else()
find_package(Qt5 5.15 COMPONENTS ${MY_OPTIONS_COMPONENTS})
endif()
endif()
endmacro()

include(cmake/findQtPackage.cmake)
find_qt_package(COMPONENTS Core Widgets REQUIRED)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()

set(BUNDLE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Bundle-${CMAKE_CXX_COMPILER_ID}-${CMAKE_BUILD_TYPE}")
set(BUNDLE_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/Bundle-${CMAKE_CXX_COMPILER_ID}-${CMAKE_BUILD_TYPE}"
)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX
"${BUNDLE_DIRECTORY}"
CACHE PATH "Install path prefix, prepended onto install directories." FORCE
)
message("Set install prefix to ${CMAKE_INSTALL_PREFIX}")
set(CMAKE_INSTALL_PREFIX
"${BUNDLE_DIRECTORY}"
CACHE PATH "Install path prefix, prepended onto install directories."
FORCE)
message("Set install prefix to ${CMAKE_INSTALL_PREFIX}")
endif()

set(lib_SOURCES
./src/PowerSlider.cpp
)
add_library(PowerSlider SHARED ./src/PowerSlider.cpp)

add_library(${PROJECT_NAME} SHARED ${lib_SOURCES} )
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_compile_definitions(PowerSlider PRIVATE POWERSLIDER_EXPORT)

target_link_libraries(${PROJECT_NAME} Qt::Widgets )
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER src/PowerSlider.hpp)
target_link_libraries(PowerSlider Qt::Widgets)
set_target_properties(PowerSlider PROPERTIES PUBLIC_HEADER src/PowerSlider.hpp)
target_include_directories(
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)
PowerSlider PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include/PowerSlider>)

if(BUILD_DESIGNER_PLUGIN)
target_compile_definitions(${PROJECT_NAME} PRIVATE "POWERSLIDER_DESIGNER_PLUGIN")

find_qt_package( COMPONENTS Core Widgets UiTools REQUIRED)
set(plugin_SOURCES
./src/PowerSlider.cpp
./src/PowerSliderPlugin.cpp
)

add_library(${PROJECT_NAME}Plugin SHARED ${plugin_SOURCES})
target_link_libraries(${PROJECT_NAME}Plugin Qt::UiTools Qt::Widgets )
target_compile_definitions(PowerSlider PRIVATE "POWERSLIDER_DESIGNER_PLUGIN")

find_qt_package(COMPONENTS Core Widgets UiTools REQUIRED)

add_library(PowerSliderPlugin SHARED ./src/PowerSlider.cpp
./src/PowerSliderPlugin.cpp)
target_link_libraries(PowerSliderPlugin Qt::UiTools Qt::Widgets)
target_compile_definitions(PowerSliderPlugin PRIVATE POWERSLIDER_EXPORT)
endif(BUILD_DESIGNER_PLUGIN)

# manage installation
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

# configure the package config file
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake @ONLY
)
add_library(PowerSlider::PowerSlider ALIAS PowerSlider)

# export targets file in buildtree and install targets file and package config file
export(TARGETS ${PROJECT_NAME}
FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake
)
install(EXPORT ${PROJECT_NAME}Targets NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
# configure the package config file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/PowerSliderConfig.cmake @ONLY)

# export targets file in buildtree and install targets file and package config
# file
export(TARGETS PowerSlider
FILE ${CMAKE_CURRENT_BINARY_DIR}/PowerSliderTargets.cmake)
install(
EXPORT PowerSliderTargets
NAMESPACE PowerSlider::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PowerSlider)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/PowerSliderConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PowerSlider)

# install target
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
CONFIGURATIONS ${CMAKE_BUILD_TYPE}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)
install(
TARGETS PowerSlider
EXPORT PowerSliderTargets
CONFIGURATIONS ${CMAKE_BUILD_TYPE}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/PowerSlider)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(MSVC OR MSVC_IDE)
install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(MSVC OR MSVC_IDE)
install(FILES $<TARGET_PDB_FILE:PowerSlider>
DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
endif()

if(BUILD_DESIGNER_PLUGIN)
install(TARGETS ${PROJECT_NAME}Plugin DESTINATION plugins/designer)
install(TARGETS PowerSliderPlugin DESTINATION plugins/designer)
endif(BUILD_DESIGNER_PLUGIN)

# find_package will find PowerSlider package config in the buildtree
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR})

if(NOT CMAKE_PROJECT_NAME STREQUAL ${PROJECT_NAME})
set(CMAKE_PREFIX_PATH
"${CMAKE_PREFIX_PATH};${CMAKE_CURRENT_BINARY_DIR}"
PARENT_SCOPE)
endif()

# manage example
if(BUILD_EXAMPLE_APP)
# find_package will find PowerSlider package config in the buildtree
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(example)
add_subdirectory(example)
endif(BUILD_EXAMPLE_APP)
63 changes: 28 additions & 35 deletions FindPowerSlider.cmake
Original file line number Diff line number Diff line change
@@ -1,47 +1,40 @@
# Distributed under the Apache License, Version 2.0
# see LICENCE file for details.
# Distributed under the Apache License, Version 2.0 see LICENCE file for
# details.

#.rst:
# FindPowerSlider
# .rst: FindPowerSlider
# -------
# This package provides necessary information to use PowerSlider.
# PowerSlider is a Qt Widget that join a HorizontalSlider and a DoubleSpinBox
#


# This package provides necessary information to use PowerSlider. PowerSlider is
# a Qt Widget that join a HorizontalSlider and a DoubleSpinBox
#

# This will define the following variables::
#
# PowerSlider_FOUND - True if the system has the PowerSlider library
# PowerSlider_VERSION - The version of the PowerSlider library which was found
# PowerSlider_FOUND - True if the system has the PowerSlider library
# PowerSlider_VERSION - The version of the PowerSlider library which was found
#
# and the following imported targets::
#
# PowerSlider::PowerSlider - The PowerSlider library
if( NOT PowerSlider_INCLUDE_DIR)
find_path(PowerSlider_INCLUDE_DIR
NAMES PowerSlider/PowerSlider.hpp
HINTS
"${POWER_SLIDER_INSTALL_DIR}/include"
)
# PowerSlider::PowerSlider - The PowerSlider library
if(NOT PowerSlider_INCLUDE_DIR)
find_path(
PowerSlider_INCLUDE_DIR
NAMES PowerSlider/PowerSlider.hpp
HINTS "${POWER_SLIDER_INSTALL_DIR}/include")
endif()

if( NOT PowerSlider_LIBRARY)
find_library(PowerSlider_LIBRARY
NAMES PowerSlider
HINTS
"${POWER_SLIDER_INSTALL_DIR}/lib"
)
if(NOT PowerSlider_LIBRARY)
find_library(
PowerSlider_LIBRARY
NAMES PowerSlider
HINTS "${POWER_SLIDER_INSTALL_DIR}/lib")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PowerSlider
find_package_handle_standard_args(
PowerSlider
FOUND_VAR PowerSlider_FOUND
REQUIRED_VARS
PowerSlider_LIBRARY
PowerSlider_INCLUDE_DIR
VERSION_VAR PowerSlider_VERSION
)
REQUIRED_VARS PowerSlider_LIBRARY PowerSlider_INCLUDE_DIR
VERSION_VAR PowerSlider_VERSION)

if(PowerSlider_FOUND)
set(PowerSlider_LIBRARIES ${PowerSlider_LIBRARY})
Expand All @@ -51,9 +44,9 @@ endif()

if(PowerSlider_FOUND AND NOT TARGET PowerSlider::PowerSlider)
add_library(PowerSlider::PowerSlider UNKNOWN IMPORTED)
set_target_properties(PowerSlider::PowerSlider PROPERTIES
IMPORTED_LOCATION "${PowerSlider_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PowerSlider_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${PowerSlider_INCLUDE_DIR}"
)
set_target_properties(
PowerSlider::PowerSlider
PROPERTIES IMPORTED_LOCATION "${PowerSlider_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PowerSlider_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${PowerSlider_INCLUDE_DIR}")
endif()
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
![alt text][logo]

# PowerSlider Qt Widget

## Presentation

Qt Widget, a slider and a double spinbox !

This small piece of code can ease the setup of GUI when you have to control floating point values.
Expand All @@ -10,18 +13,23 @@ A designer plugin is provided to design interface with "PowerSlider" directly in
Manual comming soon (well, or not, expect if someone ask :D )

## compile and install
Pre install compilation results are copied to `Bundle-*` directory depending on compiler and build type.

designer plugin need Qt5 UiTools package (debian pkg `qttools5-dev`), to skip designer plugin build add `-DBUILD_DESIGNER_PLUGIN=Off` to `cmake` call.
Default installation is `PowerSlider/Bundle-*` directory depending on compiler and build type.

Designer plugin need Qt5 UiTools package (debian pkg `qttools5-dev`),
to skip designer plugin build add `-DBUILD_DESIGNER_PLUGIN=Off` to `cmake` call.

Installation is done under `lib` and `include` directory of `CMAKE_INSTALL_PREFIX`

So a typical build looks like
So a typical build looks like

```sh
cmake -B build -DCMAKE_INSTALL_PREFIX=somewhere
cmake --build build --target install
```
Then copy the QtDesigner plugin where appropriate, and run designer

Then copy the QtDesigner plugin to the appropriate place, and run designer

```sh
cp somehere/plugins/designer/libPowerSliderPlugin.so ~/.qt/plugins/designer/
QT_PLUGIN_PATH=~/.qt/plugins/ designer
Expand All @@ -33,3 +41,14 @@ designer should have the new widget in his list as in the screen shot here :

[designer]: ./doc/designer.png "designer screenshot"
[logo]: ./assets/icon.svg "PowerSlider logo"

## use in you project

We use `example` as an example for this case.
Configure package find in your `CMakeLists.txt` (e.g. `(find_package PowerSlider)`)
and give `PowerSlider_DIR` to `cmake` invocation

```sh
cmake example -B build-example -DPowerSlider_DIR=`pwd`/PowerSlider/Bundle-GNU-Release/lib/cmake/PowerSlider
cmake --build build-example
```
Loading

0 comments on commit 4743322

Please sign in to comment.