ScreenLockDetector/CMakeLists.txt

242 lines
6.8 KiB
CMake
Raw Normal View History

2025-11-07 10:56:45 +08:00
cmake_minimum_required(VERSION 3.10)
2025-11-10 13:26:57 +08:00
project(ScreenLockDetector VERSION 1.0.0 LANGUAGES C CXX)
2025-11-07 10:56:45 +08:00
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()
2025-11-07 10:56:45 +08:00
# 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})
2025-11-07 10:56:45 +08:00
2025-11-10 13:26:57 +08:00
# 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
set(VULKAN_HEADERS_DIR "$ENV{HOME}/sdk/Vulkan-Headers-1.3.302/include")
# 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()
# Common source files
2025-11-07 10:56:45 +08:00
set(SOURCES
src/main.cpp
src/mainwindow.cpp
src/customwidget.cpp
)
set(HEADERS
src/mainwindow.h
src/customwidget.h
)
2025-11-10 13:26:57 +08:00
# 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
)
2025-11-10 13:26:57 +08:00
add_definitions(-DENABLE_VULKAN_WIDGET)
endif()
# Platform-specific source files
if(APPLE)
# macOS specific files
list(APPEND SOURCES
src/screenlockdetector.cpp
src/screenlockdetector_mac.mm
)
list(APPEND HEADERS
src/screenlockdetector.h
src/screenlockdetector_mac.h
)
# Enable Objective-C++ for .mm files
set_source_files_properties(
src/screenlockdetector_mac.mm
PROPERTIES
COMPILE_FLAGS "-x objective-c++"
)
elseif(UNIX)
# Linux specific files
list(APPEND SOURCES
src/screenlockdetector.cpp
)
list(APPEND HEADERS
src/screenlockdetector.h
)
endif()
2025-11-07 10:56:45 +08:00
# Add executable
add_executable(${PROJECT_NAME}
${SOURCES}
${HEADERS}
)
# Link Qt5 libraries
target_link_libraries(${PROJECT_NAME}
Qt5::Core
Qt5::Gui
Qt5::Widgets
)
2025-11-10 13:26:57 +08:00
# 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
)
endif()
# Platform-specific linking
if(UNIX AND NOT APPLE)
2025-11-10 13:26:57 +08:00
target_link_libraries(${PROJECT_NAME} Qt5::DBus X11)
elseif(APPLE)
# Link macOS frameworks
target_link_libraries(${PROJECT_NAME}
"-framework Foundation"
"-framework Cocoa"
2025-11-10 13:26:57 +08:00
"-framework QuartzCore"
"-framework Metal"
)
endif()
2025-11-07 10:56:45 +08:00
# 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()
2025-11-07 10:56:45 +08:00
# 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}")
2025-11-07 10:56:45 +08:00
message(STATUS "Qt5_DIR: ${Qt5_DIR}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Qt Components: ${QT_COMPONENTS}")
2025-11-10 13:26:57 +08:00
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")
else()
message(STATUS "Vulkan support: DISABLED")
endif()
2025-11-07 10:56:45 +08:00
message(STATUS "========================================")