CMake: Use library aliases instead of library names (#55)

This changeset makes it possible to compile hyprlang with a custom
install prefix, which was not honored because of using "hyprutils" as
a raw dependency, which means that CMake was adding "-lhyprutils" flag
to the linker, but the linker didn't know the path in case a custom
install prefix was used to compile hyprutils.
This commit is contained in:
Petr Kobalicek 2024-09-10 21:51:00 +02:00 committed by GitHub
parent 5b175c9704
commit dfeb5811dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -56,13 +56,14 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(STATUS "Using clang++ to compile hyprlang") message(STATUS "Using clang++ to compile hyprlang")
endif() endif()
add_library(hypr::hyprlang ALIAS hyprlang)
install(TARGETS hyprlang) install(TARGETS hyprlang)
# tests # tests
add_custom_target(tests) add_custom_target(tests)
add_executable(hyprlang_test "tests/parse/main.cpp") add_executable(hyprlang_test "tests/parse/main.cpp")
target_link_libraries(hyprlang_test PRIVATE hyprlang hyprutils) target_link_libraries(hyprlang_test PRIVATE hypr::hyprlang)
add_test( add_test(
NAME "Parsing" NAME "Parsing"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
@ -70,7 +71,7 @@ add_test(
add_dependencies(tests hyprlang_test) add_dependencies(tests hyprlang_test)
add_executable(hyprlang_fuzz "tests/fuzz/main.cpp") add_executable(hyprlang_fuzz "tests/fuzz/main.cpp")
target_link_libraries(hyprlang_fuzz PRIVATE hyprlang hyprutils) target_link_libraries(hyprlang_fuzz PRIVATE hypr::hyprlang)
add_test( add_test(
NAME "Fuzz" NAME "Fuzz"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests