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(.) include_directories(.)
add_compile_options(-std=c++23 -DWLR_USE_UNSTABLE ) 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) 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}) 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_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"")
target_compile_definitions(hyprpicker PRIVATE "-DGIT_BRANCH=\"${GIT_BRANCH}\"") target_compile_definitions(hyprpicker PRIVATE "-DGIT_BRANCH=\"${GIT_BRANCH}\"")
target_compile_definitions(hyprpicker PRIVATE "-DGIT_COMMIT_MESSAGE=\"${GIT_COMMIT_MESSAGE}\"") target_compile_definitions(hyprpicker PRIVATE "-DGIT_COMMIT_MESSAGE=\"${GIT_COMMIT_MESSAGE}\"")
@ -65,9 +99,6 @@ target_link_libraries(hyprpicker
GLESv2 GLESv2
pthread pthread
${CMAKE_THREAD_LIBS_INIT} ${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 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_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") 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) 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 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: clear:
rm -rf build rm -rf build
rm -f *.o *-protocol.h *-protocol.c rm -f *.o *-protocol.h *-protocol.c
@ -58,7 +26,6 @@ debug:
all: all:
make clear make clear
make protocols
make release make release
install: install:

View File

@ -3,7 +3,6 @@
stdenv, stdenv,
pkg-config, pkg-config,
cmake, cmake,
ninja,
cairo, cairo,
fribidi, fribidi,
libdatrie, libdatrie,
@ -15,6 +14,7 @@
libxkbcommon, libxkbcommon,
pango, pango,
pcre, pcre,
pcre2,
utillinux, utillinux,
wayland, wayland,
wayland-protocols, wayland-protocols,
@ -27,13 +27,16 @@
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "hyprpicker" + lib.optionalString debug "-debug"; pname = "hyprpicker" + lib.optionalString debug "-debug";
inherit version; inherit version;
src = ../.; src = ../.;
cmakeFlags = lib.optional debug "-DCMAKE_BUILD_TYPE=Debug"; cmakeBuildType =
if debug
then "Debug"
else "Release";
nativeBuildInputs = [ nativeBuildInputs = [
cmake cmake
ninja
pkg-config pkg-config
]; ];
@ -48,6 +51,7 @@ stdenv.mkDerivation {
libthai libthai
pango pango
pcre pcre
pcre2
wayland wayland
wayland-protocols wayland-protocols
wayland-scanner wayland-scanner
@ -57,37 +61,11 @@ stdenv.mkDerivation {
utillinux 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; { meta = with lib; {
homepage = "https://github.com/hyprwm/hyprpicker"; homepage = "https://github.com/hyprwm/hyprpicker";
description = "A wlroots-compatible Wayland color picker that does not suck"; description = "A wlroots-compatible Wayland color picker that does not suck";
license = licenses.bsd3; license = licenses.bsd3;
platforms = platforms.linux; platforms = platforms.linux;
mainProgram = "hyprpicker";
}; };
} }