cmake_minimum_required(VERSION 3.10) project(ScreenLockDetector VERSION 1.3.0 LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Auto-include current directory for MOC set(CMAKE_INCLUDE_CURRENT_DIR ON) # Enable Qt MOC, UIC, RCC set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) # Platform detection if(APPLE) message(STATUS "Building for macOS") set(PLATFORM_NAME "macOS") elseif(UNIX) message(STATUS "Building for Linux") set(PLATFORM_NAME "Linux") else() message(WARNING "Unsupported platform") endif() # Set Qt5 path (customize this based on your installation) if(APPLE) # macOS: Try common Qt installation paths if(NOT DEFINED Qt5_DIR) # Check MacPorts installation if(EXISTS "/opt/local/lib/cmake/Qt5") set(Qt5_DIR "/opt/local/lib/cmake/Qt5") # Check Homebrew installation (Intel) elseif(EXISTS "/usr/local/opt/qt@5/lib/cmake/Qt5") set(Qt5_DIR "/usr/local/opt/qt@5/lib/cmake/Qt5") # Check Homebrew installation (Apple Silicon) elseif(EXISTS "/opt/homebrew/opt/qt@5/lib/cmake/Qt5") set(Qt5_DIR "/opt/homebrew/opt/qt@5/lib/cmake/Qt5") # Check official Qt installer elseif(EXISTS "$ENV{HOME}/Qt/5.15.2/clang_64/lib/cmake/Qt5") set(Qt5_DIR "$ENV{HOME}/Qt/5.15.2/clang_64/lib/cmake/Qt5") # Check custom installation elseif(EXISTS "$ENV{HOME}/sdk/qt-5.15.2/lib/cmake/Qt5") set(Qt5_DIR "$ENV{HOME}/sdk/qt-5.15.2/lib/cmake/Qt5") endif() endif() else() # Linux: Use custom path if(NOT DEFINED Qt5_DIR) set(Qt5_DIR "$ENV{HOME}/sdk/qt-5.15.2/lib/cmake/Qt5") endif() endif() # Find Qt5 packages set(QT_COMPONENTS Core Gui Widgets) if(UNIX AND NOT APPLE) list(APPEND QT_COMPONENTS DBus) endif() find_package(Qt5 REQUIRED COMPONENTS ${QT_COMPONENTS}) # FreeType support (for text rendering in Vulkan) find_package(Freetype) if(FREETYPE_FOUND) message(STATUS "FreeType found: ${FREETYPE_LIBRARIES}") message(STATUS "FreeType include: ${FREETYPE_INCLUDE_DIRS}") else() message(WARNING "FreeType not found, text rendering may be limited") endif() # Vulkan support (optional) - only headers needed, volk loads dynamically option(ENABLE_VULKAN "Enable Vulkan support" ON) set(VULKAN_FOUND FALSE) if(ENABLE_VULKAN) # Set Vulkan headers path if(APPLE) set(VULKAN_HEADERS_DIR "$ENV{HOME}/VulkanSDK/1.4.328.1/macOS/include") elseif(LINUX) set(VULKAN_HEADERS_DIR "$ENV{HOME}/sdk/Vulkan-Headers-1.3.302/include") endif() # Check if Vulkan headers exist if(EXISTS "${VULKAN_HEADERS_DIR}/vulkan/vulkan.h") set(VULKAN_FOUND TRUE) message(STATUS "Vulkan headers found at: ${VULKAN_HEADERS_DIR}") # Add volk source directory set(VOLK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/volk") if(EXISTS "${VOLK_DIR}/volk.c") add_library(volk STATIC ${VOLK_DIR}/volk.c) # Disable Qt MOC for volk (it's pure C code) set_target_properties(volk PROPERTIES AUTOMOC OFF AUTOUIC OFF AUTORCC OFF LINKER_LANGUAGE C ) target_include_directories(volk PUBLIC ${VOLK_DIR} ${VULKAN_HEADERS_DIR} ) # Define platform-specific Vulkan extensions for volk if(WIN32) target_compile_definitions(volk PUBLIC VK_USE_PLATFORM_WIN32_KHR) elseif(APPLE) target_compile_definitions(volk PUBLIC VK_USE_PLATFORM_METAL_EXT) elseif(UNIX) target_compile_definitions(volk PUBLIC VK_USE_PLATFORM_XLIB_KHR) endif() # Volk only needs libdl (or equivalent) for dynamic loading target_link_libraries(volk PUBLIC ${CMAKE_DL_LIBS}) message(STATUS "Volk configured with dynamic Vulkan loading") else() message(WARNING "Volk source not found at ${VOLK_DIR}, disabling Vulkan support") set(VULKAN_FOUND FALSE) endif() else() message(STATUS "Vulkan headers not found at ${VULKAN_HEADERS_DIR}, disabling Vulkan support") endif() else() message(STATUS "Vulkan support disabled") endif() # Generate version header from template (for C++ code) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/version.h" @ONLY ) # Generate version shell script from template (for shell scripts) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/version.sh.in" "${CMAKE_CURRENT_SOURCE_DIR}/version.sh" @ONLY ) # Common source files set(SOURCES src/main.cpp src/mainwindow.cpp src/customwidget.cpp src/screenlockdetector.cpp src/screenlockdetector_base.cpp src/powermonitor.cpp src/powermonitor_base.cpp ) set(HEADERS src/mainwindow.h src/renderwidgetbase.h src/customwidget.h src/screenlockdetector.h src/screenlockdetector_base.h src/powermonitor.h src/powermonitor_base.h ) # Add Vulkan widget if Vulkan is available if(VULKAN_FOUND) list(APPEND SOURCES src/vulkanwidget.cpp src/vulkanrenderer.cpp ) list(APPEND HEADERS src/vulkanwidget.h src/vulkanrenderer.h ) add_definitions(-DENABLE_VULKAN_WIDGET) endif() # Platform-specific source files if(APPLE) # macOS specific files list(APPEND SOURCES src/screenlockdetector_macos.mm src/powermonitor_macos.mm src/vulkanwidget_macos.mm ) list(APPEND HEADERS src/screenlockdetector_macos.h src/powermonitor_macos.h src/vulkanwidget_macos.h ) # Enable Objective-C++ for .mm files set_source_files_properties( src/screenlockdetector_macos.mm src/powermonitor_macos.mm src/vulkanwidget_macos.mm PROPERTIES COMPILE_FLAGS "-x objective-c++" ) elseif(UNIX) # Linux specific files list(APPEND SOURCES src/screenlockdetector_linux.cpp src/powermonitor_linux.cpp ) list(APPEND HEADERS src/screenlockdetector_linux.h src/powermonitor_linux.h ) endif() # Add executable add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ) # Include build directory for generated version.h target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ) # Link Qt5 libraries target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui Qt5::Widgets ) # Add Vulkan support if available if(VULKAN_FOUND) target_include_directories(${PROJECT_NAME} PRIVATE ${VULKAN_HEADERS_DIR} ${VOLK_DIR} ) # Only link volk - no Vulkan library needed as volk loads it dynamically target_link_libraries(${PROJECT_NAME} volk ) # Add FreeType support for text rendering in Vulkan if(FREETYPE_FOUND) target_include_directories(${PROJECT_NAME} PRIVATE ${FREETYPE_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} ${FREETYPE_LIBRARIES}) target_compile_definitions(${PROJECT_NAME} PRIVATE ENABLE_FREETYPE) endif() endif() # Platform-specific linking if(UNIX AND NOT APPLE) target_link_libraries(${PROJECT_NAME} Qt5::DBus X11) elseif(APPLE) # Link macOS frameworks target_link_libraries(${PROJECT_NAME} "-framework Foundation" "-framework Cocoa" "-framework QuartzCore" "-framework Metal" ) endif() # Set output directory set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" ) # macOS specific settings if(APPLE) set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE FALSE ) endif() # Install target install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin ) # Print configuration info message(STATUS "========================================") message(STATUS "Build Configuration:") message(STATUS "========================================") message(STATUS "Platform: ${PLATFORM_NAME}") message(STATUS "Qt5_DIR: ${Qt5_DIR}") message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") message(STATUS "Qt Components: ${QT_COMPONENTS}") if(VULKAN_FOUND) message(STATUS "Vulkan support: ENABLED (headers-only, dynamic loading via volk)") message(STATUS "Vulkan headers: ${VULKAN_HEADERS_DIR}") message(STATUS "Volk directory: ${VOLK_DIR}") message(STATUS "Note: No Vulkan library linking - volk loads dynamically at runtime") if(FREETYPE_FOUND) message(STATUS "FreeType support: ENABLED (for text rendering)") message(STATUS "FreeType libraries: ${FREETYPE_LIBRARIES}") else() message(STATUS "FreeType support: DISABLED") endif() else() message(STATUS "Vulkan support: DISABLED") endif() message(STATUS "========================================")