Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 6 additions & 2 deletions casbin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<BUILD_INTERFACE:${CASBIN_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(casbin PUBLIC nlohmann_json::nlohmann_json)

set_target_properties(casbin PROPERTIES
PREFIX ""
Expand Down
25 changes: 25 additions & 0 deletions cmake/casbinConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -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)