# # Project configuration # cmake_minimum_required(VERSION 3.13 FATAL_ERROR) # target_link_directories project(tray VERSION 0.0.0 DESCRIPTION "A cross-platform system tray library" HOMEPAGE_URL "https://app.lizardbyte.dev" LANGUAGES C CXX) set(PROJECT_LICENSE "MIT") set(TRAY_IS_TOP_LEVEL OFF) if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(TRAY_IS_TOP_LEVEL ON) endif() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to 'Release' as none was specified.") set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE) endif() # Add our custom CMake modules without overriding parent project settings. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") # # Project optional configuration # option(BUILD_DOCS "Build documentation" ${TRAY_IS_TOP_LEVEL}) option(BUILD_TESTS "Build tests" ${TRAY_IS_TOP_LEVEL}) option(BUILD_EXAMPLE "Build example app" ${TRAY_IS_TOP_LEVEL}) # Generate 'compile_commands.json' for clang_complete set(CMAKE_COLOR_MAKEFILE ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) file(GLOB TRAY_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h" ) if(TRAY_IS_TOP_LEVEL) set(TRAY_ICON_ICO "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon.ico") set(TRAY_ICON_PNG "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon.png") set(TRAY_ICON_SVG "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon.svg") set(TRAY_ICON2_ICO "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon2.ico") set(TRAY_ICON2_PNG "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon2.png") set(TRAY_ICON2_SVG "${CMAKE_CURRENT_SOURCE_DIR}/icons/icon2.svg") set(TRAY_ICON_FILES "${TRAY_ICON_ICO}" "${TRAY_ICON_PNG}" "${TRAY_ICON_SVG}" "${TRAY_ICON2_ICO}" "${TRAY_ICON2_PNG}" "${TRAY_ICON2_SVG}" ) set(_TRAY_ICON_ICO "${TRAY_ICON_ICO}" CACHE INTERNAL "Default tray ICO icon path") set(_TRAY_ICON_PNG "${TRAY_ICON_PNG}" CACHE INTERNAL "Default tray PNG icon path") set(_TRAY_ICON_SVG "${TRAY_ICON_SVG}" CACHE INTERNAL "Default tray SVG icon path") # Copy default tray icon files into the output directory of the specified target. function(tray_copy_default_icons target_name) if(NOT TARGET "${target_name}") message(FATAL_ERROR "tray_copy_default_icons expected an existing target: ${target_name}") endif() foreach(icon_file IN LISTS TRAY_ICON_FILES) add_custom_command(TARGET "${target_name}" POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${icon_file}" "$" COMMENT "Copying ${icon_file} to $") endforeach() endfunction() endif() find_package(Qt6 COMPONENTS Widgets Svg) if(Qt6_FOUND) set(TRAY_QT_VERSION 6) else() find_package(Qt5 REQUIRED COMPONENTS Widgets Svg) set(TRAY_QT_VERSION 5) endif() set(CMAKE_AUTOMOC ON) list(APPEND TRAY_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/tray_qt.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/QtTrayMenu.cpp" ) if(WIN32) list(APPEND TRAY_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/WindowsAppearance.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/WindowsAppearance.h" ) endif() add_library(${PROJECT_NAME} STATIC ${TRAY_SOURCES}) set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17) if(TRAY_IS_TOP_LEVEL AND BUILD_TESTS) target_compile_definitions(${PROJECT_NAME} PRIVATE TRAY_ENABLE_TEST_HOOKS) endif() target_include_directories(${PROJECT_NAME} PUBLIC $ $) if(WIN32 AND MSVC) list(APPEND TRAY_COMPILE_OPTIONS "/MT$<$:d>") endif() if(TRAY_QT_VERSION EQUAL 6) list(APPEND TRAY_EXTERNAL_LIBRARIES Qt6::Widgets Qt6::Svg) else() list(APPEND TRAY_EXTERNAL_LIBRARIES Qt5::Widgets Qt5::Svg) endif() if(WIN32) list(APPEND TRAY_EXTERNAL_LIBRARIES advapi32 Wtsapi32) endif() if(TRAY_COMPILE_DEFINITIONS) target_compile_definitions(${PROJECT_NAME} PRIVATE ${TRAY_COMPILE_DEFINITIONS}) endif() add_library(tray::tray ALIAS ${PROJECT_NAME}) if(TRAY_IS_TOP_LEVEL AND BUILD_EXAMPLE) add_executable(tray_example "${CMAKE_CURRENT_SOURCE_DIR}/src/example.c") target_link_libraries(tray_example tray::tray) tray_copy_default_icons(tray_example) endif() if(TRAY_IS_TOP_LEVEL) install(TARGETS tray DESTINATION lib) install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/tray.h" DESTINATION include) install(FILES ${TRAY_ICON_FILES} DESTINATION share/tray/icons) endif() target_compile_options(${PROJECT_NAME} PRIVATE ${TRAY_COMPILE_OPTIONS}) target_link_libraries(${PROJECT_NAME} PRIVATE ${TRAY_EXTERNAL_LIBRARIES}) # # Testing and documentation are only available if this is the main project # if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) if(BUILD_DOCS) include(third-party/dockle/cmake/Dockle.cmake) dockle_add_docs(docs TARGETS api) endif() if(BUILD_TESTS) # # Additional setup for coverage # https://gcovr.com/en/stable/guide/compiling.html#compiler-options # if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage -ggdb -O0") set(CMAKE_C_FLAGS "-fprofile-arcs -ftest-coverage -ggdb -O0") endif() enable_testing() add_subdirectory(tests) endif() endif()