From 542391b58f7a407565a6a82e9e45d68fb6f85ed2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Nov 2025 10:49:40 +0000 Subject: [PATCH 1/2] Initial plan From 08a121aab511e87eeca52903f31f9575e2e72eea Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Nov 2025 11:03:55 +0000 Subject: [PATCH 2/2] Add vcpkg support with proper CMake installation and package config - Add proper install(TARGETS) command for the casbin library - Add install(EXPORT) to generate and install CMake config files - Create casbinConfig.cmake.in for proper package discovery - Use GNUInstallDirs for standard installation paths - Change include directories and link libraries from PRIVATE to PUBLIC - Add generator expressions for BUILD_INTERFACE and INSTALL_INTERFACE - Create casbinConfigVersion.cmake with version compatibility checking - All tests pass successfully Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com> --- CMakeLists.txt | 56 +++++++++++++++++++++++++++++++------ casbin/CMakeLists.txt | 8 ++++-- cmake/casbinConfig.cmake.in | 25 +++++++++++++++++ 3 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 cmake/casbinConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index cf6415be..698a0c73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,21 +170,61 @@ endif() # Install casbin if(CASBIN_INSTALL) + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) + message(CHECK_START "[casbin]: Installing casbin ...") - export( + + # Install the library + install( TARGETS casbin - NAMESPACE casbin:: - FILE casbinConfig.cmake + EXPORT casbinTargets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) - + # Installing headers install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/casbin - DESTINATION include + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) + + # Install the export set + install( + EXPORT casbinTargets + FILE casbinTargets.cmake + NAMESPACE casbin:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/casbin + ) + + # Create and install the config file + configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/casbinConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/casbinConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/casbin + ) + + # Create and install the version file + write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/casbinConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion + ) + + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/casbinConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/casbinConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/casbin + ) + + # Export for build tree (optional, for developers) + export( + EXPORT casbinTargets + FILE ${CMAKE_CURRENT_BINARY_DIR}/casbinTargets.cmake + NAMESPACE casbin:: ) - - set(CMAKE_EXPORT_PACKAGE_REGISTRY ON) - export(PACKAGE casbin) message(CHECK_PASS " The targets can now be imported with find_package(casbin)") message(STATUS "[casbin]: Build the \"install\" target and add \"${CMAKE_INSTALL_PREFIX}/include\" to you PATH for casbin to work") diff --git a/casbin/CMakeLists.txt b/casbin/CMakeLists.txt index cc51e164..c242791e 100644 --- a/casbin/CMakeLists.txt +++ b/casbin/CMakeLists.txt @@ -76,8 +76,12 @@ set(CMAKE_CXX_STANDARD 17) add_library(casbin STATIC ${CASBIN_SOURCE_FILES}) target_precompile_headers(casbin PRIVATE ${CASBIN_INCLUDE_DIR}/casbin/pch.h) -target_include_directories(casbin PRIVATE ${CASBIN_INCLUDE_DIR}) -target_link_libraries(casbin PRIVATE nlohmann_json::nlohmann_json) +target_include_directories(casbin + PUBLIC + $ + $ +) +target_link_libraries(casbin PUBLIC nlohmann_json::nlohmann_json) set_target_properties(casbin PROPERTIES PREFIX "" diff --git a/cmake/casbinConfig.cmake.in b/cmake/casbinConfig.cmake.in new file mode 100644 index 00000000..d9f3e29f --- /dev/null +++ b/cmake/casbinConfig.cmake.in @@ -0,0 +1,25 @@ +# Copyright 2020 The casbin Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +# Find required dependencies +find_dependency(nlohmann_json 3.10.1 REQUIRED) + +# Include the targets file +include("${CMAKE_CURRENT_LIST_DIR}/casbinTargets.cmake") + +check_required_components(casbin)