CMake: add protocol building and install rule

Makefile: delegate protocols to CMakeLists.txt
Nix: update derivation
This commit is contained in:
Mihai Fufezan 2024-03-12 21:50:23 +02:00
parent 2ef703474f
commit 698b6ecd54
No known key found for this signature in database
3 changed files with 45 additions and 67 deletions

View file

@ -35,6 +35,36 @@ execute_process(
#
#
find_program(WaylandScanner NAMES wayland-scanner)
message(STATUS "Found WaylandScanner at ${WaylandScanner}")
execute_process(
COMMAND pkg-config --variable=pkgdatadir wayland-protocols
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE WAYLAND_PROTOCOLS_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Found wayland-protocols at ${WAYLAND_PROTOCOLS_DIR}")
function(protocol protoPath protoName external)
if (external)
execute_process(
COMMAND ${WaylandScanner} client-header ${protoPath} ${protoName}-protocol.h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
execute_process(
COMMAND ${WaylandScanner} private-code ${protoPath} ${protoName}-protocol.c
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
# target_sources(hyprpicker PRIVATE ${protoName}-protocol.h)
target_sources(hyprpicker PRIVATE ${protoName}-protocol.h ${protoName}-protocol.c)
else()
execute_process(
COMMAND ${WaylandScanner} client-header ${WAYLAND_PROTOCOLS_DIR}/${protoPath} ${protoName}-protocol.h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
execute_process(
COMMAND ${WaylandScanner} private-code ${WAYLAND_PROTOCOLS_DIR}/${protoPath} ${protoName}-protocol.c
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
target_sources(hyprpicker PRIVATE ${protoName}-protocol.h ${protoName}-protocol.c)
endif()
endfunction()
include_directories(.)
add_compile_options(-std=c++23 -DWLR_USE_UNSTABLE )
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value -Wno-missing-field-initializers -Wno-narrowing -Wno-pointer-arith)
@ -47,6 +77,10 @@ file(GLOB_RECURSE SRCFILES "src/*.cpp")
add_executable(hyprpicker ${SRCFILES})
protocol("protocols/wlr-layer-shell-unstable-v1.xml" "wlr-layer-shell-unstable-v1" true)
protocol("protocols/wlr-screencopy-unstable-v1.xml" "wlr-screencopy-unstable-v1" true)
protocol("stable/xdg-shell/xdg-shell.xml" "xdg-shell" false)
target_compile_definitions(hyprpicker PRIVATE "-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"")
target_compile_definitions(hyprpicker PRIVATE "-DGIT_BRANCH=\"${GIT_BRANCH}\"")
target_compile_definitions(hyprpicker PRIVATE "-DGIT_COMMIT_MESSAGE=\"${GIT_COMMIT_MESSAGE}\"")
@ -65,9 +99,6 @@ target_link_libraries(hyprpicker
GLESv2
pthread
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_SOURCE_DIR}/wlr-layer-shell-unstable-v1-protocol.o
${CMAKE_SOURCE_DIR}/wlr-screencopy-unstable-v1-protocol.o
${CMAKE_SOURCE_DIR}/xdg-shell-protocol.o
wayland-cursor
)
@ -76,3 +107,5 @@ IF(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg -no-pie -fno-builtin")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg -no-pie -fno-builtin")
ENDIF(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
install(TARGETS hyprpicker)

View file

@ -12,38 +12,6 @@ LDLIBS += $(foreach p,$(PKGS),$(shell pkg-config --libs $(p)))
default: all
wlr-layer-shell-unstable-v1-protocol.h:
$(WAYLAND_SCANNER) client-header \
protocols/wlr-layer-shell-unstable-v1.xml $@
wlr-layer-shell-unstable-v1-protocol.c:
$(WAYLAND_SCANNER) private-code \
protocols/wlr-layer-shell-unstable-v1.xml $@
wlr-layer-shell-unstable-v1-protocol.o: wlr-layer-shell-unstable-v1-protocol.h
wlr-screencopy-unstable-v1-protocol.h:
$(WAYLAND_SCANNER) client-header \
protocols/wlr-screencopy-unstable-v1.xml $@
wlr-screencopy-unstable-v1-protocol.c:
$(WAYLAND_SCANNER) private-code \
protocols/wlr-screencopy-unstable-v1.xml $@
wlr-screencopy-unstable-v1-protocol.o: wlr-screencopy-unstable-v1-protocol.h
xdg-shell-protocol.h:
$(WAYLAND_SCANNER) client-header \
$(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@
xdg-shell-protocol.c:
$(WAYLAND_SCANNER) private-code \
$(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@
xdg-shell-protocol.o: xdg-shell-protocol.h
protocols: wlr-layer-shell-unstable-v1-protocol.o wlr-screencopy-unstable-v1-protocol.o xdg-shell-protocol.o
clear:
rm -rf build
rm -f *.o *-protocol.h *-protocol.c
@ -58,7 +26,6 @@ debug:
all:
make clear
make protocols
make release
install:

View file

@ -3,7 +3,6 @@
stdenv,
pkg-config,
cmake,
ninja,
cairo,
fribidi,
libdatrie,
@ -15,6 +14,7 @@
libxkbcommon,
pango,
pcre,
pcre2,
utillinux,
wayland,
wayland-protocols,
@ -27,13 +27,16 @@
stdenv.mkDerivation {
pname = "hyprpicker" + lib.optionalString debug "-debug";
inherit version;
src = ../.;
cmakeFlags = lib.optional debug "-DCMAKE_BUILD_TYPE=Debug";
cmakeBuildType =
if debug
then "Debug"
else "Release";
nativeBuildInputs = [
cmake
ninja
pkg-config
];
@ -48,6 +51,7 @@ stdenv.mkDerivation {
libthai
pango
pcre
pcre2
wayland
wayland-protocols
wayland-scanner
@ -57,37 +61,11 @@ stdenv.mkDerivation {
utillinux
];
configurePhase = ''
runHook preConfigure
make protocols
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
make release
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/{bin,share/licenses}
install -Dm755 build/hyprpicker -t $out/bin
install -Dm644 LICENSE -t $out/share/licenses/hyprpicker
runHook postInstall
'';
meta = with lib; {
homepage = "https://github.com/hyprwm/hyprpicker";
description = "A wlroots-compatible Wayland color picker that does not suck";
license = licenses.bsd3;
platforms = platforms.linux;
mainProgram = "hyprpicker";
};
}