cmake_minimum_required(VERSION 3.10) project(ScreenLockDetector VERSION 1.0.0 LANGUAGES 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}) # Common source files set(SOURCES src/main.cpp src/mainwindow.cpp src/customwidget.cpp ) set(HEADERS src/mainwindow.h src/customwidget.h ) # 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() # Add executable add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ) # Link Qt5 libraries target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui Qt5::Widgets ) # 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() # 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}") message(STATUS "========================================")