Skip to content

Commit

Permalink
Fixing CMakeLists.txt.
Browse files Browse the repository at this point in the history
  • Loading branch information
SySyAli committed Jan 4, 2024
1 parent 70e02cd commit 6177f61
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ else()
# Assuming GCC or Clang
add_compile_options(-Wall -Wextra -pedantic -Werror)
endif()

# Find packages
# include sqlite3
find_package(SQLite3 REQUIRED)
if(UNIX AND NOT APPLE)
find_package(X11 REQUIRED)
endif()

# find X11 - linux
find_package(X11 REQUIRED)

# include testing
enable_testing()
Expand All @@ -43,14 +42,24 @@ add_executable(desktop_screentime main.cpp
IWindowInterface.cpp
)

# Link libraries
# Link SQLite3 and possibly X11 and pthread to the executable
if(MSVC)
# Using Microsoft Visual C++
target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES})
elseif(UNIX AND NOT APPLE)
target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES} ${X11_LIBRARIES} pthread)
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()
endif()


# Testing Executable
# Define the source files and dependencies for the executable
set(SOURCE_FILES
tests/main.cpp
tests/AppEntryTest.cpp
Expand All @@ -61,9 +70,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})
if(UNIX AND NOT APPLE)
target_link_libraries(tests ${X11_LIBRARIES} pthread)
endif()
target_include_directories(tests PRIVATE ${SQLite3_INCLUDE_DIRS})
target_include_directories(tests PRIVATE ${SQLite3_INCLUDE_DIRS})

0 comments on commit 6177f61

Please sign in to comment.