From 70e02cda1bf6612143ca2769a0355b5e5edd6292 Mon Sep 17 00:00:00 2001 From: SySyAli Date: Thu, 4 Jan 2024 00:05:10 -0500 Subject: [PATCH] Fixing CMakeLists.txt. --- CMakeLists.txt | 33 ++++++++++++--------------------- IWindowInterface.cpp | 4 ++-- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 84c95de..bd30f7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,11 +13,12 @@ else() # Assuming GCC or Clang add_compile_options(-Wall -Wextra -pedantic -Werror) endif() -# include sqlite3 -find_package(SQLite3 REQUIRED) -# find X11 - linux -find_package(X11 REQUIRED) +# Find packages +find_package(SQLite3 REQUIRED) +if(UNIX AND NOT APPLE) + find_package(X11 REQUIRED) +endif() # include testing enable_testing() @@ -42,24 +43,14 @@ add_executable(desktop_screentime main.cpp IWindowInterface.cpp ) -# Link SQLite3 and possibly X11 and pthread to the executable +# Link libraries if(MSVC) - # Using Microsoft Visual C++ target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES}) -else() - # Assuming GCC or Clang - if(X11_FOUND) - # Link both SQLite3 and X11 (and pthread for Linux) - target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES} ${X11_LIBRARIES} pthread) - else() - # Link only SQLite3 and pthread (for Linux without X11) - target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES} pthread) - endif() +elseif(UNIX AND NOT APPLE) + target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES} ${X11_LIBRARIES} pthread) endif() - # Testing Executable -# Define the source files and dependencies for the executable set(SOURCE_FILES tests/main.cpp tests/AppEntryTest.cpp @@ -70,9 +61,9 @@ set(SOURCE_FILES AppEntry.cpp IWindowInterface.cpp ) - -# Make the project root directory the working directory when we run -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) add_executable(tests ${SOURCE_FILES}) target_link_libraries(tests gtest gtest_main ${SQLite3_LIBRARIES}) -target_include_directories(tests PRIVATE ${SQLite3_INCLUDE_DIRS}) \ No newline at end of file +if(UNIX AND NOT APPLE) + target_link_libraries(tests ${X11_LIBRARIES} pthread) +endif() +target_include_directories(tests PRIVATE ${SQLite3_INCLUDE_DIRS}) diff --git a/IWindowInterface.cpp b/IWindowInterface.cpp index 068b677..146b6bb 100644 --- a/IWindowInterface.cpp +++ b/IWindowInterface.cpp @@ -100,8 +100,7 @@ void WindowsTracker::startTracking() #endif #if __linux__ -std::string getTrackingScreenLinux(Display* display) -{ +std::string getTrackingScreenLinux(Display* display) { Window window; char* title = nullptr; int revert_to_return; @@ -115,6 +114,7 @@ std::string getTrackingScreenLinux(Display* display) XFree(title); return windowTitle; } + void LinuxTracker::startTracking() { AppEntry prevEntry;