feat: a desktop entry, installed by an opt-in CMake target
The entry's Exec is the built binary's absolute path, so it always launches what was last built -- and moving the build directory breaks it, which is the price of having no install step. An install() rule would make a second copy that can diverge; a documented cp would need the binary on PATH, which it is not. The target writes the entry and both icons under XDG_DATA_HOME, refreshes the desktop and icon caches when the tools are there, and runs desktop-file-validate as a hard failure -- the shell ignores a malformed entry in silence, so the failure belongs at the moment the entry is asked for. It prints the three paths it wrote, which is the uninstall instructions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
33eee0c8d0
commit
a055325831
3 files changed
+99
No files matched your search
@@ -126,3 +126,30 @@ add_dependencies(udpscope udpscope_build_info)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
target_compile_options(udpscope PRIVATE -Wall -Wextra -Wpedantic)
|
||||
endif()
|
||||
|
||||
# --- the desktop entry: opt-in, never part of `cmake --build` ------------------
|
||||
# `Exec` is the built binary's absolute path in the build tree, so the entry always launches
|
||||
# exactly the binary that was last built -- and moving or deleting the build directory breaks
|
||||
# it. That is the price of having no install step, and it is the right one here: an install()
|
||||
# rule would create a second copy of the app that can diverge from the build tree, and a
|
||||
# documented `cp` would need the binary on PATH, which it is not.
|
||||
#
|
||||
# configure_file() cannot evaluate a generator expression and file(GENERATE) cannot substitute
|
||||
# an @VAR@, so the two run in sequence: the first writes the genex out literally, the second
|
||||
# evaluates it. This is the documented idiom.
|
||||
set(UDPSCOPE_EXEC "$<TARGET_FILE:udpscope>")
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/data/org.udpscope.app.desktop.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/desktop-entry.in @ONLY)
|
||||
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/org.udpscope.app.desktop
|
||||
INPUT ${CMAKE_CURRENT_BINARY_DIR}/desktop-entry.in)
|
||||
|
||||
# No ALL: this runs only when it is named, so `cmake --build build` is unaffected.
|
||||
add_custom_target(desktop-entry
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DENTRY=${CMAKE_CURRENT_BINARY_DIR}/org.udpscope.app.desktop
|
||||
-DICON=${UDPSCOPE_ICON_DIR}/scalable/apps/org.udpscope.app.svg
|
||||
-DSYMBOLIC=${UDPSCOPE_ICON_DIR}/scalable/apps/org.udpscope.app-symbolic.svg
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install_desktop_entry.cmake
|
||||
COMMENT "Installing the udpscope desktop entry into XDG_DATA_HOME"
|
||||
VERBATIM)
|
||||
add_dependencies(desktop-entry udpscope)
|
||||
Reference in new issue
Block a user