Refactor CMake and Make file (#1766)

* Refactor CMake and Make file

- modernize CMake a bit
- "unscreamify" CMake commands
- replace undocumented CMake option -H by -S in Makefile
- remove unnecessary "cd" in Makefile

* Fix include path to wlroots generated header files
This commit is contained in:
stephan-cr 2023-03-14 22:50:30 +01:00 committed by GitHub
parent d63e8c8f45
commit e4b6af41e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 58 deletions

View File

@ -5,7 +5,7 @@ include(CheckIncludeFile)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/props.json PROPS) file(READ ${CMAKE_CURRENT_SOURCE_DIR}/props.json PROPS)
string(JSON VER GET ${PROPS} version) string(JSON VER GET ${PROPS} version)
project(Hyprland project(Hyprland
DESCRIPTION "A Modern C++ Wayland Compositor" DESCRIPTION "A Modern C++ Wayland Compositor"
VERSION ${VER} VERSION ${VER}
) )
@ -42,22 +42,24 @@ execute_process(
# #
# #
IF(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG) if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
message(STATUS "Configuring Hyprland in Debug with CMake") message(STATUS "Configuring Hyprland in Debug with CMake")
add_definitions( -DHYPRLAND_DEBUG ) add_compile_definitions(HYPRLAND_DEBUG)
ELSE() else()
add_compile_options( -O3 ) add_compile_options(-O3)
message(STATUS "Configuring Hyprland in Release with CMake") message(STATUS "Configuring Hyprland in Release with CMake")
ENDIF(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG) endif()
include_directories(. PRIVATE "subprojects/wlroots/include/") include_directories(
include_directories(. PRIVATE "subprojects/wlroots/build/include/") .
include_directories(. PRIVATE "subprojects/udis86/") "subprojects/wlroots/include/"
"subprojects/wlroots/build/include/"
"subprojects/udis86/")
set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD 23)
add_compile_options(-DWLR_USE_UNSTABLE) add_compile_definitions(WLR_USE_UNSTABLE)
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value -Wno-missing-field-initializers -Wno-narrowing -Wno-pointer-arith) add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value -Wno-missing-field-initializers -Wno-narrowing -Wno-pointer-arith)
ADD_LINK_OPTIONS( -rdynamic ) add_link_options(-rdynamic)
SET(CMAKE_ENABLE_EXPORTS TRUE) set(CMAKE_ENABLE_EXPORTS TRUE)
message(STATUS "Checking deps...") message(STATUS "Checking deps...")
@ -66,7 +68,7 @@ find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-server wayland-client wayland-cursor wayland-protocols cairo libdrm egl xkbcommon libinput) # we do not check for wlroots, as we provide it ourselves pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-server wayland-client wayland-cursor wayland-protocols cairo libdrm egl xkbcommon libinput) # we do not check for wlroots, as we provide it ourselves
file(GLOB_RECURSE SRCFILES "src/*.cpp") file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp")
add_executable(Hyprland ${SRCFILES}) add_executable(Hyprland ${SRCFILES})
@ -76,38 +78,40 @@ if(HAVE_LIBEXECINFO)
target_link_libraries(Hyprland PRIVATE execinfo) target_link_libraries(Hyprland PRIVATE execinfo)
endif() endif()
IF(LEGACY_RENDERER MATCHES true) if(LEGACY_RENDERER)
message(STATUS "Using the legacy GLES2 renderer!") message(STATUS "Using the legacy GLES2 renderer!")
add_definitions( -DLEGACY_RENDERER ) add_compile_definitions(LEGACY_RENDERER)
ENDIF(LEGACY_RENDERER MATCHES true) endif()
IF(NO_XWAYLAND MATCHES true) if(NO_XWAYLAND)
message(STATUS "Using the NO_XWAYLAND flag, disabling XWayland!") message(STATUS "Using the NO_XWAYLAND flag, disabling XWayland!")
add_definitions( -DNO_XWAYLAND ) add_compile_definitions(NO_XWAYLAND)
ELSE() else()
message(STATUS "XWAYLAND Enabled (NO_XWAYLAND not defined) checking deps...") message(STATUS "XWAYLAND Enabled (NO_XWAYLAND not defined) checking deps...")
pkg_check_modules(xcbdep REQUIRED xcb) pkg_check_modules(xcbdep REQUIRED xcb)
target_link_libraries(Hyprland xcb) target_link_libraries(Hyprland xcb)
ENDIF(NO_XWAYLAND MATCHES true) endif()
IF(NO_SYSTEMD MATCHES true) if(NO_SYSTEMD)
message(STATUS "SYSTEMD support is disabled...") message(STATUS "SYSTEMD support is disabled...")
ELSE() else()
message(STATUS "SYSTEMD support is requested (NO_SYSTEMD not defined) checking deps...") message(STATUS "SYSTEMD support is requested (NO_SYSTEMD not defined) checking deps...")
pkg_check_modules(LIBSYSTEMD libsystemd) pkg_check_modules(LIBSYSTEMD libsystemd)
check_include_file("systemd/sd-daemon.h" SYSTEMDH) check_include_file("systemd/sd-daemon.h" SYSTEMDH)
IF(LIBSYSTEMD_FOUND AND SYSTEMDH) if(LIBSYSTEMD_FOUND AND SYSTEMDH)
add_definitions( -DUSES_SYSTEMD ) add_compile_definitions(USES_SYSTEMD)
target_link_libraries(Hyprland "${LIBSYSTEMD_LIBRARIES}") target_link_libraries(Hyprland "${LIBSYSTEMD_LIBRARIES}")
ELSE() else()
message(WARNING "Systemd support requested but libsystemd or systemd headers were not found") message(WARNING "Systemd support requested but libsystemd or systemd headers were not found")
ENDIF(LIBSYSTEMD_FOUND AND SYSTEMDH) endif()
ENDIF(NO_SYSTEMD MATCHES true) endif()
target_compile_definitions(Hyprland PRIVATE "-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"") target_compile_definitions(Hyprland
target_compile_definitions(Hyprland PRIVATE "-DGIT_BRANCH=\"${GIT_BRANCH}\"") PRIVATE
target_compile_definitions(Hyprland PRIVATE "-DGIT_COMMIT_MESSAGE=\"${GIT_COMMIT_MESSAGE}\"") "GIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\""
target_compile_definitions(Hyprland PRIVATE "-DGIT_DIRTY=\"${GIT_DIRTY}\"") "GIT_BRANCH=\"${GIT_BRANCH}\""
"GIT_COMMIT_MESSAGE=\"${GIT_COMMIT_MESSAGE}\""
"GIT_DIRTY=\"${GIT_DIRTY}\"")
target_link_libraries(Hyprland rt) target_link_libraries(Hyprland rt)
@ -119,15 +123,14 @@ message(STATUS "Setting link libraries")
target_link_libraries(Hyprland PkgConfig::deps) target_link_libraries(Hyprland PkgConfig::deps)
IF(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG) if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
message(STATUS "Setting debug flags") message(STATUS "Setting debug flags")
target_link_libraries(Hyprland asan) target_link_libraries(Hyprland asan)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg -no-pie -fno-builtin -fsanitize=address") add_compile_options(-pg -no-pie -fno-builtin -fsanitize=address)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg -no-pie -fno-builtin") add_link_options(-pg -no-pie -fno-builtin)
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg -no-pie -fno-builtin") endif()
ENDIF(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
target_link_libraries(Hyprland target_link_libraries(Hyprland
${CMAKE_SOURCE_DIR}/subprojects/wlroots/build/libwlroots.so.12032 # wlroots is provided by us ${CMAKE_SOURCE_DIR}/subprojects/wlroots/build/libwlroots.so.12032 # wlroots is provided by us

View File

@ -142,19 +142,19 @@ text-input-unstable-v1-protocol.c:
text-input-unstable-v1-protocol.o: text-input-unstable-v1-protocol.h text-input-unstable-v1-protocol.o: text-input-unstable-v1-protocol.h
legacyrenderer: legacyrenderer:
mkdir -p build && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DLEGACY_RENDERER:STRING=true -H./ -B./build -G Ninja cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DLEGACY_RENDERER:BOOL=true -S . -B ./build -G Ninja
cmake --build ./build --config Release --target all -j$(shell nproc) cmake --build ./build --config Release --target all -j$(shell nproc)
legacyrendererdebug: legacyrendererdebug:
mkdir -p build && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DLEGACY_RENDERER:STRING=true -H./ -B./build -G Ninja cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DLEGACY_RENDERER:BOOL=true -S . -B ./build -G Ninja
cmake --build ./build --config Release --target all -j$(shell nproc) cmake --build ./build --config Release --target all -j$(shell nproc)
release: release:
mkdir -p build && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -H./ -B./build -G Ninja cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B ./build -G Ninja
cmake --build ./build --config Release --target all -j$(shell nproc) cmake --build ./build --config Release --target all -j$(shell nproc)
debug: debug:
mkdir -p build && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -H./ -B./build -G Ninja cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -S . -B ./build -G Ninja
cmake --build ./build --config Debug --target all -j$(shell nproc) cmake --build ./build --config Debug --target all -j$(shell nproc)
clear: clear:
@ -166,20 +166,20 @@ clear:
all: all:
make clear make clear
make fixwlr make fixwlr
cd ./subprojects/wlroots && meson build/ --buildtype=release && ninja -C build/ && cp ./build/libwlroots.so.12032 ${PREFIX}/lib/ || echo "Could not install libwlroots to ${PREFIX}/lib/libwlroots.so.12032" && cd ../.. cd ./subprojects/wlroots && meson setup build/ --buildtype=release && ninja -C build/ && cp ./build/libwlroots.so.12032 ${PREFIX}/lib/ || echo "Could not install libwlroots to ${PREFIX}/lib/libwlroots.so.12032"
cd subprojects/udis86 && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -H./ -B./build -G Ninja && cmake --build ./build --config Release --target all -j$(shell nproc) cd subprojects/udis86 && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B./build -G Ninja && cmake --build ./build --config Release --target all -j$(shell nproc)
make protocols make protocols
make release make release
cd hyprctl && make all && cd .. make -C hyprctl all
install: install:
make clear make clear
make fixwlr make fixwlr
cd ./subprojects/wlroots && meson build/ --buildtype=release && ninja -C build/ && cp ./build/libwlroots.so.12032 ${PREFIX}/lib/ || echo "Could not install libwlroots to ${PREFIX}/lib/libwlroots.so.12032" && cd ../.. cd ./subprojects/wlroots && meson setup build/ --buildtype=release && ninja -C build/ && cp ./build/libwlroots.so.12032 ${PREFIX}/lib/ || echo "Could not install libwlroots to ${PREFIX}/lib/libwlroots.so.12032"
cd subprojects/udis86 && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -H./ -B./build -G Ninja && cmake --build ./build --config Release --target all -j$(shell nproc) && cd ../.. cd subprojects/udis86 && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B./build -G Ninja && cmake --build ./build --config Release --target all -j$(shell nproc) && cd ../..
make protocols make protocols
make release make release
cd hyprctl && make all && cd .. make -C hyprctl all
mkdir -p ${PREFIX}/share/wayland-sessions mkdir -p ${PREFIX}/share/wayland-sessions
mkdir -p ${PREFIX}/bin mkdir -p ${PREFIX}/bin
@ -218,32 +218,32 @@ config:
make fixwlr make fixwlr
cd subprojects/wlroots && meson ./build --prefix=${PREFIX} --buildtype=release -Dwerror=false -Dexamples=false meson setup subprojects/wlroots/build subprojects/wlroots --prefix=${PREFIX} --buildtype=release -Dwerror=false -Dexamples=false
cd subprojects/wlroots && ninja -C build/ ninja -C subprojects/wlroots/build/
cd subprojects/wlroots && ninja -C build/ install ninja -C subprojects/wlroots/build/ install
cd subprojects/udis86 && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -H./ -B./build -G Ninja && cmake --build ./build --config Release --target all -j$(shell nproc) cd subprojects/udis86 && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B ./build -G Ninja && cmake --build ./build --config Release --target all -j$(shell nproc)
pluginenv: pluginenv:
make protocols make protocols
cd subprojects/udis86 && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -H./ -B./build -G Ninja && cmake --build ./build --config Release --target all -j$(shell nproc) cd subprojects/udis86 && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B ./build -G Ninja && cmake --build ./build --config Release --target all -j$(shell nproc)
make fixwlr make fixwlr
cd subprojects/wlroots && meson ./build --prefix=${PREFIX} --buildtype=release -Dwerror=false -Dexamples=false meson setup subprojects/wlroots/build subprojects/wlroots --prefix=${PREFIX} --buildtype=release -Dwerror=false -Dexamples=false
cd subprojects/wlroots && ninja -C build/ ninja -C subprojects/wlroots/build/
configdebug: configdebug:
make protocols make protocols
make fixwlr make fixwlr
cd subprojects/wlroots && meson ./build --prefix=${PREFIX} --buildtype=debug -Dwerror=false -Dexamples=false -Db_sanitize=address meson setup subprojects/wlroots/build subprojects/wlroots --prefix=${PREFIX} --buildtype=debug -Dwerror=false -Dexamples=false -Db_sanitize=address
cd subprojects/wlroots && ninja -C build/ ninja -C subprojects/wlroots/build/
cd subprojects/wlroots && ninja -C build/ install ninja -C subprojects/wlroots/build/ install
man: man:
pandoc ./docs/Hyprland.1.rst \ pandoc ./docs/Hyprland.1.rst \