Skip to content

Commit

Permalink
refactor(cmake): improve cmake and add new feature
Browse files Browse the repository at this point in the history
 * remove redundant "dtkwidget" in include directory;
 * improve cmake, modify some variable names, use file() to collect
 source files for scalability;
 * add full target_link_libraries support.

Log: add full target_link_libraries support
Influence: all projects who include headers directly by path
  • Loading branch information
asterwyx committed Jan 18, 2023
1 parent 0386852 commit d6b55d4
Show file tree
Hide file tree
Showing 637 changed files with 559 additions and 726 deletions.
6 changes: 3 additions & 3 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Copyright: None
License: CC0-1.0

#interface
Files: include/dtkwidget/DWidget/*
Files: include/DWidget/*
Copyright: None
License: CC0-1.0

Expand Down Expand Up @@ -69,12 +69,12 @@ Copyright: UnionTech Software Technology Co., Ltd.
License: LGPL-3.0-or-later

# svg
Files: examples/dwidget-examples/collections/icons/texts/* plugin/dtkuidemo/logo_icon.svg
Files: examples/collections/icons/texts/* plugin/dtkuidemo/logo_icon.svg
Copyright: UnionTech Software Technology Co., Ltd.
License: LGPL-3.0-or-later

#example png
Files: examples/dwidget-examples/collections/images/*
Files: examples/collections/images/*
Copyright: UnionTech Software Technology Co., Ltd.
License: LGPL-3.0-or-later

Expand Down
163 changes: 119 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,81 +1,156 @@
cmake_minimum_required (VERSION 3.10)

set (DVERSION "5.6.2" CACHE STRING "define project version")
project (DtkWidget
VERSION ${DVERSION}
DESCRIPTION "DTK Widget module"
HOMEPAGE_URL "https://github.com/linuxdeepin/dtkwidget"
LANGUAGES CXX C
cmake_minimum_required(VERSION 3.10)

set(VERSION
"5.6.4"
CACHE STRING "define project version"
)

project(DtkWidget
VERSION ${VERSION}
DESCRIPTION "DTK Widget module"
HOMEPAGE_URL "https://github.com/linuxdeepin/dtkwidget"
LANGUAGES CXX C
)
#set(BREAKVERSION "5")

set(LIB_NAME dtkwidget)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()

# Set build option
set (BUILD_PLUGINS ON CACHE BOOL "BUILD PLUGIN EXAMPLES")
set(BUILD_PLUGINS
ON
CACHE BOOL "Build plugin and plugin example"
)

# Set install path
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX /usr)
endif ()
set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/libdtk-${CMAKE_PROJECT_VERSION}/DWidget")
set (TOOL_INSTALL_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/libdtk-${CMAKE_PROJECT_VERSION}/DWidget/bin")
set (LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_FULL_LIBDIR}")
set (MKSPECS_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/qt5/mkspecs/modules" CACHE STRING "INSTALL DIR FOR qt pri files")
endif()

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

set(INCLUDE_INSTALL_DIR
"${CMAKE_INSTALL_INCLUDEDIR}/dtk${PROJECT_VERSION_MAJOR}/DWidget"
)
set(TOOL_INSTALL_DIR
"${CMAKE_INSTALL_LIBDIR}/dtk${PROJECT_VERSION_MAJOR}/DWidget/bin"
)
set(LIBRARY_INSTALL_DIR
"${CMAKE_INSTALL_LIBDIR}"
)
set(MKSPECS_INSTALL_DIR
"${CMAKE_INSTALL_LIBDIR}/qt5/mkspecs/modules"
CACHE STRING "Install dir for qt pri files"
)
set(CONFIG_INSTALL_DIR
"${CMAKE_INSTALL_LIBDIR}/cmake/DtkWidget"
CACHE STRING "Install directory for cmake files"
)
set(PKGCONFIG_INSTALL_DIR
"${CMAKE_INSTALL_LIBDIR}/pkgconfig"
CACHE STRING "Install directory for pkgconfig files"
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wextra")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(BUILD_TESTING ON)
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast")
endif ()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(BUILD_TESTING ON)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast")
endif()
# find_package
find_package(Dtk REQUIRED COMPONENTS Core Gui)
find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core)
find_package(Qt5 REQUIRED COMPONENTS
Core
Network
Concurrent
Widgets
PrintSupport
LinguistTools
X11Extras
DBus
)
find_package(PkgConfig REQUIRED)

file(GLOB D_HEADERS "${PROJECT_SOURCE_DIR}/include/DWidget/*")

add_subdirectory(src)
set(AUTOCONFIG ${CMAKE_CURRENT_BINARY_DIR}/dtkwidget_config.h)
get_filename_component(CONFIG_INCLUDE ${AUTOCONFIG} DIRECTORY)
set(CONFIG_CONTENT)
string(APPEND CONFIG_CONTENT "// This is an auto-generated config\n")

foreach(header ${D_HEADERS})
get_filename_component(thename ${header} NAME)
string(APPEND CONFIG_CONTENT "#define DTKWIDGET_CLASS_${thename}\n")
endforeach()

file(WRITE ${AUTOCONFIG} ${CONFIG_CONTENT})

file(GLOB_RECURSE PUBLIC_HEADERS "${PROJECT_SOURCE_DIR}/include/*.h")
list(APPEND PUBLIC_HEADERS ${D_HEADERS} ${AUTOCONFIG})

add_subdirectory(src)
add_subdirectory(examples)
add_subdirectory(tools)

if(BUILD_TESTING)
message("==================================")
message(" Now Testing is enabled ")
message("==================================")
enable_testing()
add_subdirectory(tests)
message("==================================")
message(" Now Testing is enabled ")
message("==================================")
enable_testing()
add_subdirectory(tests)
endif()

if(BUILD_PLUGINS)
message("===================================")
message(" You can build and run plugins now ")
message("===================================")
add_subdirectory(plugin)
message("===================================")
message(" You can build and run plugins now ")
message("===================================")
add_subdirectory(plugin)
endif()
find_package (Qt5 CONFIG REQUIRED COMPONENTS DBus Xml)

set (BUILD_DOCS ON CACHE BOOL "Generate doxygen-based documentation")
set(BUILD_DOCS
ON
CACHE BOOL "Generate doxygen-based documentation"
)

if (BUILD_DOCS)
add_subdirectory(docs)
endif ()
if(BUILD_DOCS)
add_subdirectory(docs)
endif()

configure_package_config_file(misc/DtkWidgetConfig.cmake.in
configure_package_config_file(
misc/DtkWidgetConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/DtkWidgetConfig.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/DtkWidget"
PATH_VARS INCLUDE_INSTALL_DIR LIBRARY_INSTALL_DIR TOOL_INSTALL_DIR
INSTALL_DESTINATION ${CONFIG_INSTALL_DIR}
PATH_VARS TOOL_INSTALL_DIR
)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/DtkWidgetConfigVersion.cmake"
VERSION ${DVERSION}
${CMAKE_CURRENT_BINARY_DIR}/DtkWidgetConfigVersion.cmake
VERSION ${VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/DtkWidgetConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/DtkWidgetConfigVersion.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/DtkWidget"
DESTINATION ${CONFIG_INSTALL_DIR}
)

configure_file(misc/dtkwidget.pc.in dtkwidget.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dtkwidget.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dtkwidget.pc DESTINATION ${PKGCONFIG_INSTALL_DIR})

configure_file(misc/qt_lib_dtkwidget.pri.in qt_lib_dtkwidget.pri @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qt_lib_dtkwidget.pri DESTINATION "${MKSPECS_INSTALL_DIR}")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qt_lib_dtkwidget.pri DESTINATION ${MKSPECS_INSTALL_DIR})
6 changes: 3 additions & 3 deletions archlinux/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ build() {
cd $deepin_source_name
cmake -GNinja \
-DHUNTER_ENABLED=OFF \
-DMKSPECS_INSTALL_DIR=/usr/lib/qt/mkspecs/modules/\
-DMKSPECS_INSTALL_DIR=lib/qt/mkspecs/modules/\
-DBUILD_PLUGINS=OFF \
-DBUILD_DOCS=ON \
-DQCH_INSTALL_DESTINATION=/usr/share/doc/qt \
-DCMAKE_INSTALL_LIBDIR=/usr/lib \
-DQCH_INSTALL_DESTINATION=share/doc/qt \
-DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=Release
ninja
Expand Down
1 change: 0 additions & 1 deletion debian/compat

This file was deleted.

2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Source: dtkwidget
Section: libdevel
Priority: optional
Maintainer: Deepin Packages Builder <[email protected]>
Build-Depends: debhelper (>= 9), pkg-config, libudev-dev,
Build-Depends: debhelper-compat (= 12), pkg-config, libudev-dev,
libqt5x11extras5-dev, libxext-dev, qttools5-dev-tools, qttools5-dev,
x11proto-xext-dev, libxcb-util0-dev, libstartup-notification0-dev,
libmtdev-dev, qtbase5-private-dev, libegl1-mesa-dev, libudev-dev,
Expand Down
1 change: 1 addition & 0 deletions debian/dtkwidget5-examples.install
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
usr/lib/*/*/*/examples/*
usr/share/dsg/configs/overrides/dtk-example/*
1 change: 1 addition & 0 deletions debian/libdtkwidget5.install
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
usr/lib/*/lib*.so.*
usr/share/*/*/translations/*
usr/share/dsg/configs/org.deepin.dtkwidget.feature-display.json
1 change: 1 addition & 0 deletions debian/libdtkwidget5.install.amd64
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
usr/lib/*/lib*.so.*
#usr/lib/*/libmsc.so
usr/share/*/*/translations/*
usr/share/dsg/configs/org.deepin.dtkwidget.feature-display.json
1 change: 1 addition & 0 deletions debian/libdtkwidget5.install.i386
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
usr/lib/*/lib*.so.*
#usr/lib/*/libmsc.so
usr/share/*/*/translations/*
usr/share/dsg/configs/org.deepin.dtkwidget.feature-display.json
5 changes: 2 additions & 3 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ else
endif

%:
dh $@ --parallel
dh $@

override_dh_auto_configure:
dh_auto_configure -- -DBUILD_PLUGINS=OFF -DBUILD_DOCS=OFF -DDVERSION=$(_PACK_VER)
dh_auto_configure -- -DBUILD_PLUGINS=OFF -DBUILD_DOCS=OFF -DVERSION=$(_PACK_VER)
#override_dh_auto_configure:
# dh_auto_configure -- LIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH)
#override_dh_makeshlibs:
Expand All @@ -33,4 +33,3 @@ override_dh_auto_configure:

override_dh_makeshlibs:
dh_makeshlibs -V "libdtkwidget5 (>= $(shell echo $(VERSION) | cut -d '.' -f 1,2))"

12 changes: 6 additions & 6 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ set (DOXYGEN_TAGFILES "qtcore.tags=qthelp://org.qt-project.qtcore/qtcore/" CACHE

set (DOXYGEN_PREDEFINED
"D_DECL_DEPRECATED_X(x)="
"\"DCORE_BEGIN_NAMESPACE=namespace Dtk { namespace Core {\""
"\"DCORE_END_NAMESPACE=}}\""
"\"DCORE_USE_NAMESPACE=using namespace Dtk::Core\;\""
"\"DWIDGET_BEGIN_NAMESPACE=namespace Dtk { namespace Widget {\""
"\"DWIDGET_END_NAMESPACE=}}\""
"\"DWIDGET_USE_NAMESPACE=using namespace Dtk::Widget\;\""
"DCORE_BEGIN_NAMESPACE=namespace Dtk { namespace Core {"
"DCORE_END_NAMESPACE=}}"
"DCORE_USE_NAMESPACE=using namespace Dtk::Core;"
"DWIDGET_BEGIN_NAMESPACE=namespace Dtk { namespace Widget {"
"DWIDGET_END_NAMESPACE=}}"
"DWIDGET_USE_NAMESPACE=using namespace Dtk::Widget;"
)

set (BUILD_THEME OFF CACHE BOOL "Build doxgen theme")
Expand Down
4 changes: 2 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_subdirectory(dwidget-examples/collections)
add_subdirectory(dwidget-examples/PrintPreviewSettingsPlugin)
add_subdirectory(collections)
add_subdirectory(PrintPreviewSettingsPlugin)
12 changes: 12 additions & 0 deletions examples/PrintPreviewSettingsPlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(PLUGIN_NAME PrintPreviewSettingsPlugin)

find_package(Qt5 REQUIRED COMPONENTS Core)

add_library(${PLUGIN_NAME} SHARED
settingsplugin.h
settingsplugin.cpp
)

target_link_libraries(${PLUGIN_NAME} PRIVATE
${LIB_NAME}
)
62 changes: 62 additions & 0 deletions examples/collections/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
set(BIN_NAME collections)
set(CMAKE_AUTOUIC ON)

find_package(Qt5 REQUIRED COMPONENTS Gui Widgets)

add_executable(${BIN_NAME}
images.qrc
resources.qrc
icons/theme-icons.qrc
cameraform.ui
mainwindow.h
buttonexample.h
examplewindowinterface.h
pagewindowinterface.h
editexample.h
sliderexample.h
listviewexample.h
windowexample.h
tooltipexample.h
spinnerexample.h
dialogexample.h
progressbarexample.h
layoutexample.h
scrollbarexample.h
rubberbandexample.h
widgetexample.h
lcdnumberexample.h
menuexample.h
imageviewerexample.h
main.cpp
mainwindow.cpp
buttonexample.cpp
examplewindowinterface.cpp
pagewindowinterface.cpp
editexample.cpp
sliderexample.cpp
listviewexample.cpp
windowexample.cpp
tooltipexample.cpp
spinnerexample.cpp
dialogexample.cpp
progressbarexample.cpp
layoutexample.cpp
scrollbarexample.cpp
rubberbandexample.cpp
widgetexample.cpp
lcdnumberexample.cpp
menuexample.cpp
imageviewerexample.cpp
)

target_link_libraries(${BIN_NAME} PRIVATE
Qt5::Widgets
Qt5::GuiPrivate
${LIB_NAME}
)
install(
TARGETS ${BIN_NAME}
DESTINATION "${CMAKE_INSTALL_LIBDIR}/dtk${PROJECT_VERSION_MAJOR}/DWidget/examples/"
)

dconfig_override_files(APPID dtk-example META_NAME org.deepin.dtkwidget.feature-display FILES ${CMAKE_CURRENT_LIST_DIR}/org.deepin.dtkwiget.feature-display.json)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
Loading

0 comments on commit d6b55d4

Please sign in to comment.