Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

CMake Config uses absolute paths.

Đang mở
#987 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
54/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cmake
Lĩnh vực
build-system

Hướng nghiên cứu

Bắt đầu với CMakeLists.txt và kiểm tra cách các biến GNUInstallDirs được đưa vào các tệp được tạo cjson.cmake, cjson_utils.cmake và cjson-<BUILD_TYPE>.cmake. So sánh các import được tạo trước và sau khi thay đổi cấu hình; hoàn tất khi một gói cJSON đã cài đặt có thể được tìm thấy từ một tiền tố cài đặt khác mà không cần các đường dẫn được hard-code.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Out of the box it is not possible to import cjson using find_package cmake command If you have not build the library yourself. This is due to the CMakeLists.txt file using CMAKE_INSTALL_FULL_* variables from GNUInstallDirs module which according to the documentation should not be used on install() commands.

In any case the fix is simple, just replace CMAKE_INSTALL_FULL_* variables with their relative counterparts (i.e., CMAKE_INSTALL_LIBDIR, CMAKE_INSTALL_BINDIR, etc.)

If you want a little bit more detail. What happens is that if you use the FULL variables in install commands. The cmake config files will use the FULL path as the installation prefix instead of calculating the path at runtime base on the file location. You can see this in the cjson.cmake file (more or less line 48) and in cjson_utils.cmake where when using the FULL variant the code looks like this:

# The installation prefix configured by this project.
set(_IMPORT_PREFIX "/<my-person-install>/cjson/cjson-1.7.19/")


While when using the relative paths it looks like this:

# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
  set(_IMPORT_PREFIX "")
endif()

You can also see it on the cjson-<BUILD_TYPE>.cmake Where the IMPORTED_LOCATION_<BUILD_TYPE> will be the FULL path and if using the relative path variables it will just use the calculated _IMPORT_PREFIX instead.

If you want I can make a pull request with this simple fix. 😅

PS. This does not affect CJSON_INCLUDE_DIRS and CJSON_INCLUDE_DIR variables. Those still have the full path.

Ngôn ngữ chính
C
Star
13k
Fork
3.5k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của DaveGamble/cJSON

Tất cả issue của DaveGamble/cJSON

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.