2025-11-07 10:56:45 +08:00
|
|
|
cmake_minimum_required(VERSION 3.10)
|
2025-11-08 12:44:35 +08:00
|
|
|
project(ScreenLockDetector VERSION 1.0.0 LANGUAGES 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)
|
|
|
|
|
|
2025-11-08 16:57:58 +08:00
|
|
|
# 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
|
2025-11-08 16:57:58 +08:00
|
|
|
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-08 16:57:58 +08:00
|
|
|
# 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-08 16:57:58 +08:00
|
|
|
# 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-08 16:57:58 +08:00
|
|
|
# Platform-specific linking
|
|
|
|
|
if(UNIX AND NOT APPLE)
|
|
|
|
|
target_link_libraries(${PROJECT_NAME} Qt5::DBus)
|
|
|
|
|
elseif(APPLE)
|
|
|
|
|
# Link macOS frameworks
|
|
|
|
|
target_link_libraries(${PROJECT_NAME}
|
|
|
|
|
"-framework Foundation"
|
|
|
|
|
"-framework Cocoa"
|
|
|
|
|
)
|
|
|
|
|
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"
|
|
|
|
|
)
|
|
|
|
|
|
2025-11-08 16:57:58 +08:00
|
|
|
# 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 "========================================")
|
2025-11-08 16:57:58 +08:00
|
|
|
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}")
|
2025-11-08 16:57:58 +08:00
|
|
|
message(STATUS "Qt Components: ${QT_COMPONENTS}")
|
2025-11-07 10:56:45 +08:00
|
|
|
message(STATUS "========================================")
|