aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2024-11-25 04:53:27 +0100
committerPřemysl Eric Janouch <p@janouch.name>2024-11-25 05:46:26 +0100
commit0283189070f577e77d8f6a41c00d7cd69709ce14 (patch)
tree14834b350167eff75cd714b71d6668a2c056692f
parent3219d87bc4453a2e34d5e017979d2746d13fe1d4 (diff)
downloadusb-drivers-0283189070f577e77d8f6a41c00d7cd69709ce14.tar.gz
usb-drivers-0283189070f577e77d8f6a41c00d7cd69709ce14.tar.xz
usb-drivers-0283189070f577e77d8f6a41c00d7cd69709ce14.zip
Port eizoctl build to CMake
The GNU Makefile approach has its limits.
-rw-r--r--.gitignore7
-rw-r--r--CMakeLists.txt38
-rw-r--r--Makefile38
-rw-r--r--eizoctl.c14
4 files changed, 47 insertions, 50 deletions
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 3c8f0d9..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,7 +0,0 @@
-/compile_commands.json
-/eizoctl
-/eizoctl.exe
-/eizoctltray.png
-/eizoctltray.ico
-/eizoctltray.o
-/eizoctltray.exe
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9ce894d..1c4b6fd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,12 +13,13 @@ endif ()
# Dependencies
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/liberty/cmake)
-include (AddThreads)
find_package (PkgConfig REQUIRED)
pkg_check_modules (libusb libusb-1.0)
+pkg_search_module (hidapi hidapi hidapi-hidraw)
option (WITH_LIBUSB "Compile with libusb utilities" ${libusb_FOUND})
+option (WITH_HIDRAW "Compile with hidraw utilities" ${hidapi_FOUND})
# Generate a configuration file
configure_file (${PROJECT_SOURCE_DIR}/config.h.in
@@ -48,6 +49,40 @@ if (WITH_LIBUSB)
target_link_libraries (razer-bw-te-ctl ${libusb_LIBRARIES})
endif ()
+if (WITH_HIDRAW)
+ list (APPEND targets eizoctl)
+ add_executable (eizoctl eizoctl.c)
+ target_include_directories (eizoctl PUBLIC ${hidapi_INCLUDE_DIRS})
+ target_link_directories (eizoctl PUBLIC ${hidapi_LIBRARY_DIRS})
+ target_link_libraries (eizoctl ${hidapi_LIBRARIES})
+endif ()
+if (WITH_HIDRAW AND WIN32)
+ list (APPEND targets_gui eizoctltray)
+
+ include (IconUtils)
+ set (icon_png_list)
+ foreach (icon_size 16 32 48)
+ icon_to_png (eizoctltray ${PROJECT_SOURCE_DIR}/eizoctltray.svg
+ ${icon_size} ${PROJECT_BINARY_DIR}/icons icon_png)
+ list (APPEND icon_png_list ${icon_png})
+ endforeach ()
+ icon_to_png (eizoctltray ${PROJECT_SOURCE_DIR}/eizoctltray.svg
+ 256 ${PROJECT_BINARY_DIR}/icons icon_png)
+
+ set (icon_ico ${PROJECT_BINARY_DIR}/eizoctltray.ico)
+ icon_for_win32 (${icon_ico} "${icon_png_list}" "${icon_png}")
+ list (APPEND icon_ico_list )
+ set_property (SOURCE eizoctltray.rc
+ APPEND PROPERTY OBJECT_DEPENDS ${icon_ico})
+
+ add_executable (eizoctltray WIN32 eizoctl.c eizoctltray.rc)
+ target_compile_definitions (eizoctltray PUBLIC -DUNICODE -D_UNICODE -DTRAY)
+ target_link_options (eizoctltray PUBLIC -static -municode)
+ target_include_directories (eizoctltray PUBLIC ${hidapi_INCLUDE_DIRS})
+ target_link_directories (eizoctltray PUBLIC ${hidapi_LIBRARY_DIRS})
+ target_link_libraries (eizoctltray ${hidapi_LIBRARIES} PowrProf)
+endif ()
+
# Generate documentation from help output
find_program (HELP2MAN_EXECUTABLE help2man)
if (NOT HELP2MAN_EXECUTABLE)
@@ -77,6 +112,7 @@ install (TARGETS ${targets} DESTINATION ${CMAKE_INSTALL_BINDIR}
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
SETUID)
+install (TARGETS ${targets_gui} DESTINATION ${CMAKE_INSTALL_BINDIR})
install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
foreach (page ${project_MAN_PAGES})
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 4246b3a..0000000
--- a/Makefile
+++ /dev/null
@@ -1,38 +0,0 @@
-UNAME_S := $(shell uname -s)
-ifeq ($(UNAME_S),Linux)
- HIDAPI = hidapi-hidraw
-else
- HIDAPI = hidapi
-endif
-
-CFLAGS += -Wall -Wextra -g -std=gnu99 $(shell pkg-config --cflags $(HIDAPI))
-LDFLAGS += $(shell pkg-config --libs $(HIDAPI))
-outputs = eizoctl compile_commands.json
-ifeq ($(OS),Windows_NT)
- outputs += eizoctltray.png eizoctltray.ico eizoctltray.o eizoctltray.exe
- LDFLAGS += -static
-endif
-
-all: $(outputs)
-compile_commands.json:
- >$@ echo '[{'
- >>$@ echo '"directory": "'"$$(pwd)"'",'
- >>$@ echo '"command": "$(CC) $(CFLAGS) eizoctl.c",'
- >>$@ echo '"file": "'"$$(pwd)"'/eizoctl.c"'
- >>$@ echo '}]'
-eizoctl: eizoctl.c
- $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ $(LDFLAGS)
-clean:
- rm -f $(outputs)
-
-ifeq ($(OS),Windows_NT)
-eizoctltray.png: eizoctltray.svg
- rsvg-convert --output=$@ -- $<
-eizoctltray.ico: eizoctltray.png
- icotool -c -o $@ -- $<
-eizoctltray.o: eizoctltray.rc eizoctltray.ico
- windres -o $@ $<
-eizoctltray.exe: eizoctl.c eizoctltray.o
- $(CC) $(CFLAGS) $(CPPFLAGS) -DUNICODE -D_UNICODE -DTRAY \
- -o $@ $^ $(LDFLAGS) -mwindows -municode -lPowrProf
-endif
diff --git a/eizoctl.c b/eizoctl.c
index 6a335cb..a1e5da5 100644
--- a/eizoctl.c
+++ b/eizoctl.c
@@ -33,7 +33,9 @@
#include <getopt.h>
#include <hidapi.h>
-#define PROJECT_NAME "eizoctl"
+#include "config.h"
+#undef PROGRAM_NAME
+#define PROGRAM_NAME "eizoctl"
#if defined __GNUC__
#define ATTRIBUTE_PRINTF(x, y) __attribute__((format(printf, x, y)))
@@ -966,6 +968,7 @@ run(int argc, char *argv[], print_fn output, print_fn error, bool verbose)
{"restart", no_argument, NULL, 'r'},
{"events", no_argument, NULL, 'e'},
{"help", no_argument, NULL, 'h'},
+ {"version", no_argument, NULL, 'V'},
{}
};
@@ -994,6 +997,9 @@ run(int argc, char *argv[], print_fn output, print_fn error, bool verbose)
case 'h':
output(usage, name);
return 0;
+ case 'V':
+ output(PROGRAM_NAME " " PROGRAM_VERSION "\n");
+ return 0;
default:
error("Unknown option\n");
error(usage, name);
@@ -1397,14 +1403,14 @@ wWinMain(
.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(1)),
.hCursor = LoadCursor(NULL, IDC_ARROW),
.hbrBackground = GetSysColorBrush(COLOR_3DFACE),
- .lpszClassName = TEXT(PROJECT_NAME),
+ .lpszClassName = TEXT(PROGRAM_NAME),
};
if (!RegisterClassEx(&wc))
return 1;
// We need a window, but it can stay hidden.
g.hwnd = CreateWindowEx(WS_EX_CONTROLPARENT,
- wc.lpszClassName, TEXT(PROJECT_NAME), WS_OVERLAPPEDWINDOW,
+ wc.lpszClassName, TEXT(PROGRAM_NAME), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 600, 400, NULL, NULL, hInstance, NULL);
NOTIFYICONDATA nid = {
.cbSize = sizeof nid,
@@ -1414,7 +1420,7 @@ wWinMain(
.uCallbackMessage = WM_APP + 0,
// TODO(p): LoadIconMetric is suggested for high-DPI displays.
.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(1)),
- .szTip = TEXT(PROJECT_NAME),
+ .szTip = TEXT(PROGRAM_NAME),
};
if (!Shell_NotifyIcon(NIM_ADD, &nid)) {
message_error("Failed to add notification area icon.");