Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
chore: add cmake-format pre-commmit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
gikari committed Mar 20, 2022
1 parent 1902f11 commit 38712f6
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 181 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ repos:
hooks:
- id: clang-format
exclude: "^.*external/.*$"
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
exclude: "^.*external/.*$"
- repo: local
hooks:
- id: qmlformat
Expand Down
46 changes: 16 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,33 @@ option(
using esbuild. This could be useful, if you know, that the \
code is correct and you want to speed up building times. \
For example - you are a packager."
ON
)
ON)

option(
USE_NPM
"Use npm installed packages during the build. You might \
want to disable this option, if you want to use natively \
installed tools. In particular build systems won't use \
\"npx\" prefix before commands."
ON
)
ON)

set(QT_MIN_VERSION "5.15.0")
set(KF5_MIN_VERSION "5.78.0")

# HACK: Use git to get the recent version
# We could explicitly set the version via project declaration
# But this would conflict with package.json and would
# HACK: Use git to get the recent version We could explicitly set the version
# via project declaration But this would conflict with package.json and would
# Require automatic change via Release Please time CI
execute_process(COMMAND "git" "describe" "--tags" "--abbrev=0" OUTPUT_VARIABLE CMAKE_PROJECT_VERSION)
execute_process(COMMAND "git" "describe" "--tags" "--abbrev=0"
OUTPUT_VARIABLE CMAKE_PROJECT_VERSION)
string(REPLACE "\n" "" CMAKE_PROJECT_VERSION "${CMAKE_PROJECT_VERSION}")
string(REPLACE "v" "" CMAKE_PROJECT_VERSION "${CMAKE_PROJECT_VERSION}")

# TODO: Less hacky solution, however it requires CMake 3.19
# which is not so common across distros as of now.
# Uncomment when cmake_minimum_required >= 3.19.
# TODO: Less hacky solution, however it requires CMake 3.19 which is not so
# common across distros as of now. Uncomment when cmake_minimum_required >=
# 3.19.
#
# # Set the project version
# file(READ ${CMAKE_CURRENT_SOURCE_DIR}/package.json PACKAGE_JSON)
# string(JSON CMAKE_PROJECT_VERSION GET ${PACKAGE_JSON} version)
# # Set the project version file(READ ${CMAKE_CURRENT_SOURCE_DIR}/package.json
# PACKAGE_JSON) string(JSON CMAKE_PROJECT_VERSION GET ${PACKAGE_JSON} version)
# unset(PACKAGE_JSON)

find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
Expand All @@ -56,22 +53,11 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(
Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
DBus
Quick
Svg
Test
)

find_package(
KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
I18n
KCMUtils
Declarative
GlobalAccel
Config
)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS DBus Quick Svg
Test)

find_package(KF5 ${KF5_MIN_VERSION} REQUIRED
COMPONENTS I18n KCMUtils Declarative GlobalAccel Config)

include_directories("${PROJECT_SOURCE_DIR}/external")

Expand Down
16 changes: 4 additions & 12 deletions src/config/kconf_update/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <[email protected]>
# SPDX-License-Identifier: MIT

install(
FILES
bismuth_old_conf_ui.upd
bismuth_shortcuts_category.upd
bismuth_new_logger.upd
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR}
)
install(
PROGRAMS
bismuth_old_conf_ui.sh
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR}
)
install(FILES bismuth_old_conf_ui.upd bismuth_shortcuts_category.upd
bismuth_new_logger.upd DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR})
install(PROGRAMS bismuth_old_conf_ui.sh
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR})
67 changes: 28 additions & 39 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,41 @@ add_library(Bismuth::Core ALIAS bismuth_core)

ecm_qt_declare_logging_category(
BISMUTH_LOG
HEADER logger.hpp
IDENTIFIER Bi
CATEGORY_NAME org.kde.bismuth
DEFAULT_SEVERITY Debug
EXPORT Bismuth
DESCRIPTION "Bismuth Plasma Tiling Extension"
)
HEADER
logger.hpp
IDENTIFIER
Bi
CATEGORY_NAME
org.kde.bismuth
DEFAULT_SEVERITY
Debug
EXPORT
Bismuth
DESCRIPTION
"Bismuth Plasma Tiling Extension")

add_subdirectory(plasma-api)

target_sources(
bismuth_core
PRIVATE
qml-plugin.cpp
ts-proxy.cpp
controller.cpp
qmldir
${BISMUTH_LOG}
)
target_sources(bismuth_core PRIVATE qml-plugin.cpp ts-proxy.cpp controller.cpp
qmldir ${BISMUTH_LOG})

target_link_libraries(
bismuth_core
PRIVATE
Qt5::Core
Qt5::Quick
Qt5::Qml
KF5::ConfigCore
KF5::ConfigGui
KF5::GlobalAccel
KF5::I18n
)
PRIVATE Qt5::Core
Qt5::Quick
Qt5::Qml
KF5::ConfigCore
KF5::ConfigGui
KF5::GlobalAccel
KF5::I18n)

kconfig_add_kcfg_files(bismuth_core GENERATE_MOC "config.kcfgc")

ecm_qt_install_logging_categories(
EXPORT Bismuth
FILE bismuth.categories
DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}
)

install(
FILES "qmldir"
DESTINATION "${KDE_INSTALL_QMLDIR}/org/kde/bismuth/core"
)

install(
TARGETS bismuth_core
DESTINATION "${KDE_INSTALL_QMLDIR}/org/kde/bismuth/core"
)
EXPORT Bismuth FILE bismuth.categories DESTINATION
${KDE_INSTALL_LOGGINGCATEGORIESDIR})

install(FILES "qmldir" DESTINATION "${KDE_INSTALL_QMLDIR}/org/kde/bismuth/core")

install(TARGETS bismuth_core
DESTINATION "${KDE_INSTALL_QMLDIR}/org/kde/bismuth/core")
10 changes: 2 additions & 8 deletions src/core/plasma-api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# SPDX-FileCopyrightText: 2022 Mikhail Zolotukhin <[email protected]>
# SPDX-License-Identifier: MIT

target_sources(
bismuth_core
PRIVATE
plasma-api.cpp
client.cpp
toplevel.cpp
workspace.cpp
)
target_sources(bismuth_core PRIVATE plasma-api.cpp client.cpp toplevel.cpp
workspace.cpp)
28 changes: 12 additions & 16 deletions src/kcm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,26 @@ add_library(kcm_bismuth MODULE)

qt_add_dbus_interface(kwin_dbus_srcs org.kde.KWin.xml kwin_interface)

target_sources(
kcm_bismuth
PRIVATE
bismuth.cpp
${kwin_dbus_srcs}
)
target_sources(kcm_bismuth PRIVATE bismuth.cpp ${kwin_dbus_srcs})

target_link_libraries(
kcm_bismuth
PRIVATE
Qt5::Core
Qt5::DBus
KF5::CoreAddons
KF5::I18n
KF5::QuickAddons
KF5::ConfigCore
KF5::ConfigGui
)
PRIVATE Qt5::Core
Qt5::DBus
KF5::CoreAddons
KF5::I18n
KF5::QuickAddons
KF5::ConfigCore
KF5::ConfigGui)

kconfig_add_kcfg_files(kcm_bismuth GENERATE_MOC "bismuth_config.kcfgc")
kcoreaddons_desktop_to_json(kcm_bismuth "package/metadata.desktop")

install(TARGETS kcm_bismuth DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms)
install(FILES package/metadata.desktop RENAME kcm_bismuth.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(
FILES package/metadata.desktop
RENAME kcm_bismuth.desktop
DESTINATION ${KDE_INSTALL_KSERVICES5DIR})

kpackage_install_package(package kcm_bismuth kcms)

Expand Down
8 changes: 2 additions & 6 deletions src/kcm/icons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@
# SPDX-License-Identifier: MIT

ecm_install_icons(
ICONS
sc-apps-bismuth.svg
22-categories-bismuth-kcm.svg
64-categories-bismuth-kcm.svg
DESTINATION ${KDE_INSTALL_ICONDIR}
)
ICONS sc-apps-bismuth.svg 22-categories-bismuth-kcm.svg
64-categories-bismuth-kcm.svg DESTINATION ${KDE_INSTALL_ICONDIR})
71 changes: 30 additions & 41 deletions src/kwinscript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ project(bismuth-kwinscript)
add_custom_target(
KWinScript ALL
COMMENT "🏗️ Building KWin Script..."
DEPENDS
"bismuth/contents/code/index.mjs"
"bismuth/contents/ui"
)
DEPENDS "bismuth/contents/code/index.mjs" "bismuth/contents/ui")

file(GLOB_RECURSE TYPESCRIPT_SOURCES CONFIGURE_DEPENDS "*.ts")

Expand All @@ -22,32 +19,27 @@ if(USE_TSC)
else()
message(
FATAL_ERROR
"You are trying to use USE_TSC=ON with USE_NPM=OFF options. "
"This is currently unsupported, because in this case TypeScript Compiler "
"is going to throw a bunch of errors at you, because it cannot "
"find a lot of stuff, like Jest or \"console\" JS global variable. "
"\n"
"This is happening, because normally TSC thinks, that he looks at "
"code, that will be used with NPM packages and Node.js runtime. "
"This is of course is not OK, but we ought to live with this "
"behavior, because we need to use Jest Unit Testing Framework. "
"\n"
"You are supposed to use USE_NPM=OFF only with USE_TSC=OFF, "
"because, if you are using these options at all, it means, that "
"you are most probably a packager and packagers do not need "
"to check TypeScript code for correctness."
)
"You are trying to use USE_TSC=ON with USE_NPM=OFF options. "
"This is currently unsupported, because in this case TypeScript Compiler "
"is going to throw a bunch of errors at you, because it cannot "
"find a lot of stuff, like Jest or \"console\" JS global variable. "
"\n"
"This is happening, because normally TSC thinks, that he looks at "
"code, that will be used with NPM packages and Node.js runtime. "
"This is of course is not OK, but we ought to live with this "
"behavior, because we need to use Jest Unit Testing Framework. "
"\n"
"You are supposed to use USE_NPM=OFF only with USE_TSC=OFF, "
"because, if you are using these options at all, it means, that "
"you are most probably a packager and packagers do not need "
"to check TypeScript code for correctness.")
endif()
endif()

set(
ESBUILD_COMMAND
"esbuild"
"--bundle" "${CMAKE_CURRENT_SOURCE_DIR}/index.ts"
"--outfile=${CMAKE_CURRENT_BINARY_DIR}/bismuth/contents/code/index.mjs"
"--format=esm"
"--platform=neutral"
)
set(ESBUILD_COMMAND
"esbuild" "--bundle" "${CMAKE_CURRENT_SOURCE_DIR}/index.ts"
"--outfile=${CMAKE_CURRENT_BINARY_DIR}/bismuth/contents/code/index.mjs"
"--format=esm" "--platform=neutral")
if(USE_NPM)
list(PREPEND ESBUILD_COMMAND "npx")
endif()
Expand All @@ -56,25 +48,22 @@ add_custom_command(
OUTPUT "bismuth/contents/code/index.mjs"
COMMAND ${TSC_COMMAND}
COMMAND ${ESBUILD_COMMAND}
COMMAND DEPENDS ${TYPESCRIPT_SOURCES}
COMMENT "🏗️ Compiling and bundling TypeScript sources..."
)
COMMAND
DEPENDS ${TYPESCRIPT_SOURCES}
COMMENT "🏗️ Compiling and bundling TypeScript sources...")

add_custom_command(
OUTPUT "bismuth/contents/ui"
COMMAND "${CMAKE_COMMAND}" "-E" "copy_directory"
"${CMAKE_CURRENT_SOURCE_DIR}/ui" "${CMAKE_CURRENT_BINARY_DIR}/bismuth/contents/ui"
DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/ui/main.qml"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/popup.qml"
COMMENT "📑 Preparing UI and metadata files..."
)
COMMAND
"${CMAKE_COMMAND}" "-E" "copy_directory" "${CMAKE_CURRENT_SOURCE_DIR}/ui"
"${CMAKE_CURRENT_BINARY_DIR}/bismuth/contents/ui"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/ui/main.qml"
"${CMAKE_CURRENT_SOURCE_DIR}/ui/popup.qml"
COMMENT "📑 Preparing UI and metadata files...")

configure_file("metadata.desktop" "bismuth/metadata.desktop" @ONLY)

install(
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bismuth"
DESTINATION "${KDE_INSTALL_DATAROOTDIR}/kwin/scripts"
)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bismuth"
DESTINATION "${KDE_INSTALL_DATAROOTDIR}/kwin/scripts")

add_subdirectory(icons)
4 changes: 2 additions & 2 deletions src/kwinscript/icons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ ecm_install_icons(
32-status-bismuth-spread.svg
32-status-bismuth-stair.svg
32-status-bismuth-tile.svg
DESTINATION ${KDE_INSTALL_ICONDIR}
)
DESTINATION
${KDE_INSTALL_ICONDIR})
12 changes: 4 additions & 8 deletions src/kwinscript/kconf_update/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <[email protected]>
# SPDX-License-Identifier: MIT

install(
FILES local_install_to_global.upd
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR}
)
install(
PROGRAMS local_install_to_global.sh
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR}
)
install(FILES local_install_to_global.upd
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR})
install(PROGRAMS local_install_to_global.sh
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR})
Loading

0 comments on commit 38712f6

Please sign in to comment.