Skip to content

Commit d4d00f7

Browse files
authored
Merge pull request #7 from alexmohr/dev
Added version info
2 parents 84b92c9 + ccd1c26 commit d4d00f7

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(thinkpad_keyboard_backlight)
3-
set(CMAKE_INSTALL_PREFIX /usr/bin)
3+
set(PROJECT_VERSION_MAJOR 1)
4+
set(PROJECT_VERSION_MINOR 2)
5+
set(PROJECT_VERSION_PATCH 1)
46

7+
# Add version compile definition
8+
add_compile_definitions(VERSION="${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
59

10+
set(CMAKE_INSTALL_PREFIX /usr/bin)
611
set(CMAKE_CXX_STANDARD 17)
712

813
# Configure optimization
@@ -32,22 +37,27 @@ set(CMAKE_CXX_FLAGS "${OPTIMIZATION_LEVEL} \
3237

3338
set(SERVICE_TARGET_PATH /etc/systemd/system/keyboard_backlight.service)
3439
set(APP_TARGET_PATH ${CMAKE_INSTALL_PREFIX}/keyboard_backlight)
40+
set(APP_NAME keyboard_backlight)
3541

3642
find_package (Threads)
3743

3844

39-
40-
add_executable(keyboard_backlight kbd_backlight.cpp)
45+
add_executable(${APP_NAME} kbd_backlight.cpp)
4146
target_link_libraries (keyboard_backlight ${CMAKE_THREAD_LIBS_INIT})
4247

4348
install(TARGETS keyboard_backlight DESTINATION ${CMAKE_INSTALL_PREFIX})
4449

4550
add_custom_target(service
46-
DEPENDS keyboard_backlight
51+
DEPENDS ${APP_NAME}
4752
COMMAND sudo cp ${CMAKE_CURRENT_SOURCE_DIR}/keyboard_backlight.service /etc/systemd/system &&
4853
sudo systemctl enable --now keyboard_backlight.service
4954
)
5055

5156
add_custom_target(uninstall
5257
COMMAND sudo rm -f ${SERVICE_TARGET_PATH} ${APP_TARGET_PATH}
5358
)
59+
60+
# Write version to PKGBUILD
61+
add_custom_command(TARGET ${APP_NAME} POST_BUILD
62+
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/PKGBUILD ${CMAKE_BINARY_DIR} &&
63+
sed -i s/VERSION/${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}/g ${CMAKE_BINARY_DIR}/PKGBUILD)

PKGBUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Maintainer: Alexander Mohr <keyboard_backlight at mohr dot io>
22

33
pkgname=tp-kb-backlight-git
4-
pkgver=1.2
4+
pkgver=VERSION
55
pkgrel=1
66
pkgdesc='Automated keyboard backlight'
77
arch=('x86_64')

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ sudo rm /usr/bin/keyboard_backlight
5252

5353
## Configuration
5454
````
55-
tp_kbd_backlight help
55+
keyboard_backlight 1.2.1
56+
-h show this help
5657
-i ignore an input device
5758
This device does not re enable keyboard backlight.
5859
Separate multiple device by space.

kbd_backlight.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ enum MOUSE_MODE {
5555
NONE = 2
5656
};
5757

58-
void help() {
59-
printf("tp_kbd_backlight help\n"
58+
void help(const char* name) {
59+
printf("%s %s \n", name, VERSION);
60+
printf(""
61+
" -h show this help\n"
6062
" -i ignore an input device\n"
6163
" This device does not re enable keyboard backlight.\n"
6264
" Separate multiple device by space.\n"
@@ -253,7 +255,7 @@ void parse_opts(int argc,
253255
std::string token;
254256
unsigned long mode;
255257

256-
while ((c = getopt(argc, argv, "s:i:t:m:b:f")) != -1) {
258+
while ((c = getopt(argc, argv, "hs:i:t:m:b:f")) != -1) {
257259
switch (c) {
258260
case 'b':
259261
backlightPath = optarg;
@@ -289,8 +291,9 @@ void parse_opts(int argc,
289291
exit(EXIT_FAILURE);
290292
}
291293
break;
294+
case 'h':
292295
default:
293-
help();
296+
help(argv[0]);
294297
exit(EXIT_FAILURE);
295298
}
296299
}

0 commit comments

Comments
 (0)