@@ -5,99 +5,133 @@ cmake_minimum_required(VERSION 3.13 FATAL_ERROR) # target_link_directories
55project (tray VERSION 0.0.0
66 DESCRIPTION "A cross-platform system tray library"
77 HOMEPAGE_URL "https://app.lizardbyte.dev"
8- LANGUAGES C )
8+ LANGUAGES C CXX )
99
1010set (PROJECT_LICENSE "MIT" )
1111
12+ set (TRAY_IS_TOP_LEVEL OFF )
13+ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR )
14+ set (TRAY_IS_TOP_LEVEL ON )
15+ endif ()
16+
1217if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
1318 message (STATUS "Setting build type to 'Release' as none was specified." )
1419 set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE )
1520endif ()
1621
17- # Add our custom CMake modules to the global path
18- set ( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR } /cmake" )
22+ # Add our custom CMake modules without overriding parent project settings.
23+ list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR } /cmake" )
1924
2025#
2126# Project optional configuration
2227#
23- if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME )
24- option (BUILD_DOCS "Build documentation" ON )
25- option (BUILD_TESTS "Build tests" ON )
26- endif ()
28+ option (BUILD_DOCS "Build documentation" ${TRAY_IS_TOP_LEVEL} )
29+ option (BUILD_TESTS "Build tests" ${TRAY_IS_TOP_LEVEL} )
30+ option (BUILD_EXAMPLE "Build example app" ${TRAY_IS_TOP_LEVEL} )
2731
2832# Generate 'compile_commands.json' for clang_complete
2933set (CMAKE_COLOR_MAKEFILE ON )
3034set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
3135
32- find_package (PkgConfig REQUIRED )
36+ find_package (PkgConfig )
3337
3438file (GLOB TRAY_SOURCES
35- "${CMAKE_SOURCE_DIR } /src/*.h"
36- "${CMAKE_SOURCE_DIR } /icons/*.ico"
37- "${CMAKE_SOURCE_DIR } /icons/*.png" )
39+ "${CMAKE_CURRENT_SOURCE_DIR } /src/*.h"
40+ )
41+
42+ set (TRAY_ICON_ICO "${CMAKE_CURRENT_SOURCE_DIR } /icons/icon.ico" )
43+ set (TRAY_ICON_PNG "${CMAKE_CURRENT_SOURCE_DIR } /icons/icon.png" )
44+ set (TRAY_ICON_SVG "${CMAKE_CURRENT_SOURCE_DIR } /icons/icon.svg" )
45+ set (TRAY_ICON_FILES
46+ "${TRAY_ICON_ICO} "
47+ "${TRAY_ICON_PNG} "
48+ "${TRAY_ICON_SVG} "
49+ )
50+
51+ set (_TRAY_ICON_ICO "${TRAY_ICON_ICO} " CACHE INTERNAL "Default tray ICO icon path" )
52+ set (_TRAY_ICON_PNG "${TRAY_ICON_PNG} " CACHE INTERNAL "Default tray PNG icon path" )
53+ set (_TRAY_ICON_SVG "${TRAY_ICON_SVG} " CACHE INTERNAL "Default tray SVG icon path" )
54+
55+ # Copy default tray icon files into the output directory of the specified target.
56+ function (tray_copy_default_icons target_name )
57+ if (NOT TARGET "${target_name} " )
58+ message (FATAL_ERROR "tray_copy_default_icons expected an existing target: ${target_name} " )
59+ endif ()
60+
61+ foreach (icon_file IN LISTS TRAY_ICON_FILES)
62+ add_custom_command (TARGET "${target_name} " POST_BUILD
63+ COMMAND ${CMAKE_COMMAND } -E copy_if_different
64+ "${icon_file} "
65+ "$<TARGET_FILE_DIR :${target_name} >"
66+ COMMENT "Copying ${icon_file} to $<TARGET_FILE_DIR :${target_name} >" )
67+ endforeach ()
68+ endfunction ()
3869
3970if (WIN32 )
40- list (APPEND TRAY_SOURCES "${CMAKE_SOURCE_DIR } /src/tray_windows.c" )
71+ list (APPEND TRAY_SOURCES "${CMAKE_CURRENT_SOURCE_DIR } /src/tray_windows.c" )
4172else ()
4273 if (UNIX )
4374 if (APPLE )
4475 find_library (COCOA Cocoa REQUIRED )
45- list (APPEND TRAY_SOURCES "${CMAKE_SOURCE_DIR } /src/tray_darwin.m" )
76+ list (APPEND TRAY_SOURCES "${CMAKE_CURRENT_SOURCE_DIR } /src/tray_darwin.m" )
4677 else ()
47- find_package (APPINDICATOR REQUIRED )
48- find_package (LibNotify REQUIRED )
49- list (APPEND TRAY_SOURCES "${CMAKE_SOURCE_DIR } /src/tray_linux.c" )
78+ find_package (Qt6 COMPONENTS Widgets DBus Svg )
79+ if (Qt6_FOUND)
80+ set (TRAY_QT_VERSION 6)
81+ else ()
82+ find_package (Qt5 REQUIRED COMPONENTS Widgets DBus Svg )
83+ set (TRAY_QT_VERSION 5)
84+ endif ()
85+ set (TRAY_QT_VERSION # cmake-lint: disable=C0103
86+ "${TRAY_QT_VERSION} "
87+ CACHE INTERNAL "Qt major version selected by tray"
88+ )
89+ set (CMAKE_AUTOMOC ON )
90+ list (APPEND TRAY_SOURCES "${CMAKE_CURRENT_SOURCE_DIR } /src/tray_linux.cpp" )
5091 endif ()
5192 endif ()
5293endif ()
5394
5495add_library (${PROJECT_NAME } STATIC ${TRAY_SOURCES} )
5596set_property (TARGET ${PROJECT_NAME } PROPERTY C_STANDARD 99)
97+ set_property (TARGET ${PROJECT_NAME } PROPERTY CXX_STANDARD 17)
98+ target_include_directories (${PROJECT_NAME }
99+ PUBLIC
100+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR } /src >
101+ $<INSTALL_INTERFACE :include >)
56102
57103if (WIN32 )
58- list (APPEND TRAY_DEFINITIONS TRAY_WINAPI=1 WIN32_LEAN_AND_MEAN NOMINMAX)
59104 if (MSVC )
60105 list (APPEND TRAY_COMPILE_OPTIONS "/MT$<$<CONFIG :Debug >:d >" )
61106 endif ()
62107else ()
63108 if (UNIX )
64109 if (APPLE )
65- list (APPEND TRAY_DEFINITIONS TRAY_APPKIT=1)
66110 list (APPEND TRAY_EXTERNAL_LIBRARIES ${COCOA} )
67111 else ()
68- list (APPEND TRAY_COMPILE_OPTIONS ${APPINDICATOR_CFLAGS} )
69- list (APPEND TRAY_EXTERNAL_DIRECTORIES ${APPINDICATOR_LIBRARY_DIRS} )
70- list (APPEND TRAY_DEFINITIONS TRAY_APPINDICATOR=1)
71- if (APPINDICATOR_AYATANA)
72- list (APPEND TRAY_DEFINITIONS TRAY_AYATANA_APPINDICATOR=1)
112+ if (TRAY_QT_VERSION EQUAL 6)
113+ list (APPEND TRAY_EXTERNAL_LIBRARIES Qt6::Widgets Qt6::DBus Qt6::Svg)
114+ else ()
115+ list (APPEND TRAY_EXTERNAL_LIBRARIES Qt5::Widgets Qt5::DBus Qt5::Svg)
73116 endif ()
74- if (APPINDICATOR_LEGACY)
75- list (APPEND TRAY_DEFINITIONS TRAY_LEGACY_APPINDICATOR=1)
76- endif ()
77- list (APPEND TRAY_LIBNOTIFY=1)
78- list (APPEND TRAY_EXTERNAL_LIBRARIES ${APPINDICATOR_LIBRARIES} ${LIBNOTIFY_LIBRARIES} )
79-
80- include_directories (SYSTEM ${APPINDICATOR_INCLUDE_DIRS} ${LIBNOTIFY_INCLUDE_DIRS} )
81- link_directories (${APPINDICATOR_LIBRARY_DIRS} ${LIBNOTIFY_LIBRARY_DIRS} )
82117 endif ()
83118 endif ()
84119endif ()
85120
86121add_library (tray::tray ALIAS ${PROJECT_NAME } )
87122
88- add_executable (tray_example "${CMAKE_SOURCE_DIR } /src/example.c" )
89- target_link_libraries (tray_example tray::tray )
90-
91- configure_file ("${CMAKE_SOURCE_DIR } /icons/icon.ico" "${CMAKE_BINARY_DIR } /icon.ico" COPYONLY )
92- configure_file ("${CMAKE_SOURCE_DIR } /icons/icon.png" "${CMAKE_BINARY_DIR } /icon.png" COPYONLY )
93-
94- INSTALL (TARGETS tray tray DESTINATION lib)
123+ if (BUILD_EXAMPLE)
124+ add_executable (tray_example "${CMAKE_CURRENT_SOURCE_DIR } /src/example.c" )
125+ target_link_libraries (tray_example tray::tray )
126+ tray_copy_default_icons (tray_example )
127+ endif ()
95128
96- IF (NOT WIN32 )
97- INSTALL (FILES tray.h DESTINATION include)
98- ENDIF ()
129+ if (TRAY_IS_TOP_LEVEL)
130+ install (TARGETS tray DESTINATION lib)
131+ install (FILES "${CMAKE_CURRENT_SOURCE_DIR } /src/tray.h" DESTINATION include)
132+ install (FILES ${TRAY_ICON_FILES} DESTINATION share/tray/icons)
133+ endif ()
99134
100- target_compile_definitions (${PROJECT_NAME } PRIVATE ${TRAY_DEFINITIONS} )
101135target_compile_options (${PROJECT_NAME } PRIVATE ${TRAY_COMPILE_OPTIONS} )
102136target_link_directories (${PROJECT_NAME } PRIVATE ${TRAY_EXTERNAL_DIRECTORIES} )
103137target_link_libraries (${PROJECT_NAME } PRIVATE ${TRAY_EXTERNAL_LIBRARIES} )
0 commit comments