Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cmake export to allow cross-compilation with sysroot #837

Open
aurelien-enchanted-tools opened this issue Mar 5, 2024 · 3 comments
Open

Comments

@aurelien-enchanted-tools
  • v1.7.15 and following

Hello,

Please fix the following:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7aecd98..4a42d92 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -146,21 +146,21 @@ endif()
 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson.pc.in"
     "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" @ONLY)
 
-install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
-install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
+install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson")
+install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
 install(TARGETS "${CJSON_LIB}"
     EXPORT "${CJSON_LIB}"
-    ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
-    LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
-    RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}"
-    INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
+    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+    LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+    RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+    INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 )
 if (BUILD_SHARED_AND_STATIC_LIBS)
-    install(TARGETS "${CJSON_LIB}-static" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
+    install(TARGETS "${CJSON_LIB}-static" DESTINATION "${CMAKE_INSTALL_LIBDIR}")
 endif()
 if(ENABLE_TARGET_EXPORT)
     # export library information for CMake projects
-    install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
+    install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
 endif()
 
 set_target_properties("${CJSON_LIB}"
@@ -193,19 +193,19 @@ if(ENABLE_CJSON_UTILS)
 
     install(TARGETS "${CJSON_UTILS_LIB}"
         EXPORT "${CJSON_UTILS_LIB}"
-        ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
-        LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
-        RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}"
-        INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
+        ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+        LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+        RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+        INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
     )
     if (BUILD_SHARED_AND_STATIC_LIBS)
-        install(TARGETS "${CJSON_UTILS_LIB}-static" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
+        install(TARGETS "${CJSON_UTILS_LIB}-static" DESTINATION "${CMAKE_INSTALL_LIBDIR}")
     endif()
-    install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
-    install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
+    install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson")
+    install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
     if(ENABLE_TARGET_EXPORT)
       # export library information for CMake projects
-      install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
+      install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
     endif()
 
     set_target_properties("${CJSON_UTILS_LIB}"
@@ -226,7 +226,7 @@ if(ENABLE_TARGET_EXPORT)
     # Install package config files
     install(FILES ${PROJECT_BINARY_DIR}/cJSONConfig.cmake
         ${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake
-        DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
+        DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
 endif()
 
 option(ENABLE_CJSON_TEST "Enable building cJSON test" ON)
diff --git a/library_config/cJSONConfig.cmake.in b/library_config/cJSONConfig.cmake.in
index 909f7a9..206566b 100644
--- a/library_config/cJSONConfig.cmake.in
+++ b/library_config/cJSONConfig.cmake.in
@@ -2,8 +2,8 @@
 set(CJSON_UTILS_FOUND @ENABLE_CJSON_UTILS@)
 
 # The include directories used by cJSON
-set(CJSON_INCLUDE_DIRS "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
-set(CJSON_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
+set(CJSON_INCLUDE_DIRS "@CMAKE_INSTALL_INCLUDEDIR@")
+set(CJSON_INCLUDE_DIR "@CMAKE_INSTALL_INCLUDEDIR@")
 
 get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
@albert2004
Copy link

albert2004 commented Mar 15, 2024

I vote for this change. With current state, CMake paths to library are hardcoded and makes it impossible to use in SDKs (for example Yocto build).
This is also directly related to pull request: #812

@ClausKlein
Copy link

This would also enable the cpack installation!

Claus-iMac:build clausklein$ cpack
CPack: Create package using TGZ
CPack: Install projects
CPack: - Install project: cJSON-test []
CPack: Create package
CPack: - package: /Users/clausklein/Workspace/c/tests/build/cJSON-test-0.1.0-Darwin.tar.gz generated.
Claus-iMac:build clausklein$ tree _CPack_Packages/Darwin/TGZ/cJSON-test-0.1.0-Darwin
_CPack_Packages/Darwin/TGZ/cJSON-test-0.1.0-Darwin
├── include
│   └── cjson
│       └── cJSON.h
└── lib
    ├── cmake
    │   └── cJSON
    │       ├── cJSONConfig.cmake
    │       ├── cJSONConfigVersion.cmake
    │       ├── cjson-release.cmake
    │       └── cjson.cmake
    ├── libcjson.1.7.18.dylib
    ├── libcjson.1.dylib -> libcjson.1.7.18.dylib
    ├── libcjson.a
    ├── libcjson.dylib -> libcjson.1.dylib
    └── pkgconfig
        └── libcjson.pc

7 directories, 10 files
Claus-iMac:build clausklein$ 

@ClausKlein
Copy link

see #873

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants