summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2025-12-05 14:16:22 +0000
committerGitHub <noreply@github.com>2025-12-05 14:16:22 +0000
commit9264436f35e2c4e94adfdf2a8ea23a346ace3a65 (patch)
tree9fe48ff4728060445e655d8a3b528999fd124ff8 /CMakeLists.txt
parentd5c52ef58e57b371a9df8fd4404c5d55a1b26f34 (diff)
desktop: rewrite reserved area handling + improve tests (#12383)
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt101
1 files changed, 75 insertions, 26 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2695bc05..78a76b21 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -79,9 +79,11 @@ message(
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
message(STATUS "Configuring Hyprland in Debug with CMake")
add_compile_definitions(HYPRLAND_DEBUG)
+ set(BUILD_TESTING ON)
else()
add_compile_options(-O3)
message(STATUS "Configuring Hyprland in Release with CMake")
+ set(BUILD_TESTING OFF)
endif()
add_compile_definitions(HYPRLAND_VERSION="${HYPRLAND_VERSION}")
@@ -241,7 +243,7 @@ set(LIBINPUT_MINIMUM_VERSION 1.28)
pkg_check_modules(
deps
REQUIRED
- IMPORTED_TARGET
+ IMPORTED_TARGET GLOBAL
xkbcommon>=${XKBCOMMMON_MINIMUM_VERSION}
uuid
wayland-server>=${WAYLAND_SERVER_MINIMUM_VERSION}
@@ -261,6 +263,8 @@ pkg_check_modules(
find_package(hyprwayland-scanner 0.3.10 REQUIRED)
file(GLOB_RECURSE SRCFILES "src/*.cpp")
+get_filename_component(FULL_MAIN_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp ABSOLUTE)
+list(REMOVE_ITEM SRCFILES "${FULL_MAIN_PATH}")
set(TRACY_CPP_FILES "")
if(USE_TRACY)
@@ -268,7 +272,12 @@ if(USE_TRACY)
message(STATUS "Tracy enabled, TRACY_CPP_FILES: " ${TRACY_CPP_FILES})
endif()
-add_executable(Hyprland ${SRCFILES} ${TRACY_CPP_FILES})
+add_library(hyprland_lib STATIC ${SRCFILES})
+add_executable(Hyprland src/main.cpp ${TRACY_CPP_FILES})
+target_link_libraries(Hyprland hyprland_lib)
+
+target_include_directories(hyprland_lib PUBLIC ${deps_INCLUDE_DIRS})
+target_include_directories(Hyprland PUBLIC ${deps_INCLUDE_DIRS})
set(USE_GPROF OFF)
@@ -278,8 +287,8 @@ if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
if(WITH_ASAN)
message(STATUS "Enabling ASan")
- target_link_libraries(Hyprland asan)
- target_compile_options(Hyprland PUBLIC -fsanitize=address)
+ target_link_libraries(hyprland_lib PUBLIC asan)
+ target_compile_options(hyprland_lib PUBLIC -fsanitize=address)
endif()
if(USE_TRACY)
@@ -289,7 +298,7 @@ if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
option(TRACY_ON_DEMAND "" ON)
add_subdirectory(subprojects/tracy)
- target_link_libraries(Hyprland Tracy::TracyClient)
+ target_link_libraries(hyprland_lib PUBLIC Tracy::TracyClient)
if(USE_TRACY_GPU)
message(STATUS "Tracy GPU Profiling is turned on")
@@ -314,19 +323,19 @@ endif()
include(CheckLibraryExists)
check_library_exists(execinfo backtrace "" HAVE_LIBEXECINFO)
if(HAVE_LIBEXECINFO)
- target_link_libraries(Hyprland execinfo)
+ target_link_libraries(hyprland_lib PUBLIC execinfo)
endif()
check_include_file("sys/timerfd.h" HAS_TIMERFD)
pkg_check_modules(epoll IMPORTED_TARGET epoll-shim)
if(NOT HAS_TIMERFD AND epoll_FOUND)
- target_link_libraries(Hyprland PkgConfig::epoll)
+ target_link_libraries(hyprland_lib PUBLIC PkgConfig::epoll)
endif()
check_include_file("sys/inotify.h" HAS_INOTIFY)
pkg_check_modules(inotify IMPORTED_TARGET libinotify)
if(NOT HAS_INOTIFY AND inotify_FOUND)
- target_link_libraries(Hyprland PkgConfig::inotify)
+ target_link_libraries(hyprland_lib PUBLIC PkgConfig::inotify)
endif()
if(NO_XWAYLAND)
@@ -352,7 +361,7 @@ else()
string(JOIN ", " PKGCONFIG_XWAYLAND_DEPENDENCIES ${XWAYLAND_DEPENDENCIES})
string(PREPEND PKGCONFIG_XWAYLAND_DEPENDENCIES ", ")
- target_link_libraries(Hyprland PkgConfig::xdeps)
+ target_link_libraries(hyprland_lib PUBLIC PkgConfig::xdeps)
endif()
configure_file(hyprland.pc.in hyprland.pc @ONLY)
@@ -381,31 +390,38 @@ if(CMAKE_DISABLE_PRECOMPILE_HEADERS)
message(STATUS "Not using precompiled headers")
else()
message(STATUS "Setting precompiled headers")
- target_precompile_headers(Hyprland PRIVATE
+ target_precompile_headers(hyprland_lib PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:src/pch/pch.hpp>)
endif()
message(STATUS "Setting link libraries")
target_link_libraries(
- Hyprland
- ${LIBRT}
+ hyprland_lib
+ PUBLIC
PkgConfig::aquamarine_dep
PkgConfig::hyprlang_dep
PkgConfig::hyprutils_dep
PkgConfig::hyprcursor_dep
PkgConfig::hyprgraphics_dep
- PkgConfig::deps)
+ PkgConfig::deps
+)
+
+target_link_libraries(
+ Hyprland
+ ${LIBRT}
+ hyprland_lib)
if(udis_dep_FOUND)
- target_link_libraries(Hyprland PkgConfig::udis_dep)
+ target_link_libraries(hyprland_lib PUBLIC PkgConfig::udis_dep)
elseif(NOT("${udis_nopc}" MATCHES "udis_nopc-NOTFOUND"))
- target_link_libraries(Hyprland ${udis_nopc})
+ target_link_libraries(hyprland_lib PUBLIC ${udis_nopc})
else()
- target_link_libraries(Hyprland libudis86)
+ target_link_libraries(hyprland_lib PUBLIC libudis86)
endif()
# used by `make installheaders`, to ensure the headers are generated
add_custom_target(generate-protocol-headers)
+set(PROTOCOL_SOURCES "")
function(protocolnew protoPath protoName external)
if(external)
@@ -419,10 +435,15 @@ function(protocolnew protoPath protoName external)
COMMAND hyprwayland-scanner ${path}/${protoName}.xml
${CMAKE_SOURCE_DIR}/protocols/
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
- target_sources(Hyprland PRIVATE protocols/${protoName}.cpp
+ target_sources(hyprland_lib PRIVATE protocols/${protoName}.cpp
protocols/${protoName}.hpp)
target_sources(generate-protocol-headers
PRIVATE ${CMAKE_SOURCE_DIR}/protocols/${protoName}.hpp)
+
+ list(APPEND PROTOCOL_SOURCES "${CMAKE_SOURCE_DIR}/protocols/${protoName}.cpp")
+ set(PROTOCOL_SOURCES "${PROTOCOL_SOURCES}" PARENT_SCOPE)
+ list(APPEND PROTOCOL_SOURCES "${CMAKE_SOURCE_DIR}/protocols/${protoName}.hpp")
+ set(PROTOCOL_SOURCES "${PROTOCOL_SOURCES}" PARENT_SCOPE)
endfunction()
function(protocolWayland)
add_custom_command(
@@ -432,12 +453,17 @@ function(protocolWayland)
hyprwayland-scanner --wayland-enums
${WAYLAND_SCANNER_PKGDATA_DIR}/wayland.xml ${CMAKE_SOURCE_DIR}/protocols/
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
- target_sources(Hyprland PRIVATE protocols/wayland.cpp protocols/wayland.hpp)
+ target_sources(hyprland_lib PRIVATE protocols/wayland.cpp protocols/wayland.hpp)
target_sources(generate-protocol-headers
PRIVATE ${CMAKE_SOURCE_DIR}/protocols/wayland.hpp)
+
+ list(APPEND PROTOCOL_SOURCES "${CMAKE_SOURCE_DIR}/protocols/wayland.hpp")
+ set(PROTOCOL_SOURCES "${PROTOCOL_SOURCES}" PARENT_SCOPE)
+ list(APPEND PROTOCOL_SOURCES "${CMAKE_SOURCE_DIR}/protocols/wayland.cpp")
+ set(PROTOCOL_SOURCES "${PROTOCOL_SOURCES}" PARENT_SCOPE)
endfunction()
-target_link_libraries(Hyprland OpenGL::EGL OpenGL::GL Threads::Threads)
+target_link_libraries(hyprland_lib PUBLIC OpenGL::EGL OpenGL::GL Threads::Threads)
pkg_check_modules(hyprland_protocols_dep hyprland-protocols>=0.6.4)
if(hyprland_protocols_dep_FOUND)
@@ -582,10 +608,37 @@ install(
PATTERN "*.hpp"
PATTERN "*.inc")
-if(BUILD_TESTING OR BUILD_HYPRTESTER)
- message(STATUS "Building hyprtester")
+if(BUILD_TESTING OR WITH_TESTS)
+ message(STATUS "Building tests")
+ # hyprtester
add_subdirectory(hyprtester)
+
+ # GTest
+ find_package(GTest CONFIG REQUIRED)
+ include(GoogleTest)
+ file(GLOB_RECURSE TESTFILES "tests/*.cpp")
+ add_executable(hyprland_gtests ${TESTFILES})
+ target_compile_options(hyprland_gtests PRIVATE --coverage)
+ target_link_options(hyprland_gtests PRIVATE --coverage)
+ target_include_directories(
+ hyprland_gtests
+ PUBLIC "./include"
+ PRIVATE "./src" "./src/include" "./protocols" "${CMAKE_BINARY_DIR}")
+
+ target_link_libraries(hyprland_gtests hyprland_lib GTest::gtest_main)
+
+ gtest_discover_tests(hyprland_gtests)
+
+ # Enable coverage in main hyprland lib
+ target_compile_options(hyprland_lib PRIVATE --coverage)
+ target_link_options(hyprland_lib PRIVATE --coverage)
+ target_link_libraries(hyprland_lib PUBLIC gcov)
+
+ # Enable coverage in hyprland exe
+ target_compile_options(Hyprland PRIVATE --coverage)
+ target_link_options(Hyprland PRIVATE --coverage)
+ target_link_libraries(Hyprland gcov)
endif()
if(BUILD_TESTING)
@@ -594,12 +647,8 @@ if(BUILD_TESTING)
enable_testing()
add_custom_target(tests)
- add_test(
- NAME "Main Test"
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/hyprtester
- COMMAND hyprtester)
+ add_dependencies(tests hyprland_gtests)
- add_dependencies(tests hyprtester)
else()
message(STATUS "Testing is disabled")
endif()