From 0bdf6986734a4dcea3d4bd2fc015b7b033125039 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Sat, 31 May 2025 11:45:35 +0200 Subject: [PATCH] fix(build): pkgconfig and use of GNUInstallDirs (#4319) * Fix pkgconfig Init CMAKE_INSTALL_INCLUDEDIR before pc file generation. Install pc file to CMAKE_INSTALL_LIBDIR/pkgconfig - it accompanies the architecture-dependent library. * Include GNUInstallDirs early The CMake module initializes variables which are used for exported information (CMake and pkgconfig). * Change pc file install destination --- cli/src/templates/cmakelists.cmake | 6 +++--- lib/CMakeLists.txt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/src/templates/cmakelists.cmake b/cli/src/templates/cmakelists.cmake index ee6fe2b4..34dd8efc 100644 --- a/cli/src/templates/cmakelists.cmake +++ b/cli/src/templates/cmakelists.cmake @@ -15,6 +15,8 @@ if(NOT ${TREE_SITTER_ABI_VERSION} MATCHES "^[0-9]+$") message(FATAL_ERROR "TREE_SITTER_ABI_VERSION must be an integer") endif() +include(GNUInstallDirs) + find_program(TREE_SITTER_CLI tree-sitter DOC "Tree-sitter CLI") add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/parser.c" @@ -47,13 +49,11 @@ set_target_properties(tree-sitter-KEBAB_PARSER_NAME configure_file(bindings/c/tree-sitter-KEBAB_PARSER_NAME.pc.in "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-KEBAB_PARSER_NAME.pc" @ONLY) -include(GNUInstallDirs) - install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bindings/c/tree_sitter" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" FILES_MATCHING PATTERN "*.h") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-KEBAB_PARSER_NAME.pc" - DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install(TARGETS tree-sitter-KEBAB_PARSER_NAME LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 34dde038..29c38d39 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -83,13 +83,13 @@ set_target_properties(tree-sitter target_compile_definitions(tree-sitter PRIVATE _POSIX_C_SOURCE=200112L _DEFAULT_SOURCE) -configure_file(tree-sitter.pc.in "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter.pc" @ONLY) - include(GNUInstallDirs) +configure_file(tree-sitter.pc.in "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter.pc" @ONLY) + install(FILES include/tree_sitter/api.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tree_sitter") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter.pc" - DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install(TARGETS tree-sitter LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")