Skip to content

Commit

Permalink
Merge pull request #138 from EmperorYP7/cmake-config
Browse files Browse the repository at this point in the history
refactor: Exported targets for easy access
  • Loading branch information
hsluoyz authored Aug 11, 2021
2 parents 32bfa27 + a5a4e77 commit 673bc01
Show file tree
Hide file tree
Showing 24 changed files with 8,983 additions and 148 deletions.
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ endif()
###############################################################################
# Project definition.

project(Casbin-CPP
VERSION 1.27.0
project(CasbinCPP
VERSION 1.36.0
DESCRIPTION "An authorization library that supports access control models like ACL, RBAC, ABAC in C/C++"
HOMEPAGE_URL https://github.com/casbin/casbin-cpp
LANGUAGES CXX C
Expand Down Expand Up @@ -86,3 +86,16 @@ set(CMAKE_CXX_STANDARD 17)
include(FindExtPackages)

add_subdirectory(casbin)

export(TARGETS
casbin
NAMESPACE casbin::
FILE "${CMAKE_CURRENT_BINARY_DIR}/CasbinConfig.cmake"
)

if(CASBIN_BUILD_PYTHON_BINDINGS)
export(TARGETS pycasbin
NAMESPACE casbin::
FILE "${CMAKE_CURRENT_BINARY_DIR}/PyCasbinConfig.cmake"
)
endif()
20 changes: 15 additions & 5 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ set(HEADERS

add_library(pycasbin MODULE ${SOURCES} ${HEADERS})

target_include_directories(pycasbin PUBLIC ${CMAKE_SOURCE_DIR})
target_include_directories(pycasbin PUBLIC ${CMAKE_SOURCE_DIR}/include)

set_target_properties(pycasbin PROPERTIES
PREFIX ""
Expand All @@ -42,9 +42,6 @@ if(WIN32)
)
endif()


# NOTE: Depending of the compiler version pybind11 2.4.3 does not compile with C++17 so revert to c++11

if(UNIX)
# A 'module' is a dynamic library on Linux (i.e. '-fPIC' needed),
# but a static library on Windows.
Expand All @@ -70,7 +67,20 @@ target_link_libraries(pycasbin
casbin
)

if(WIN32)
set(Python_VARIANT_PATH "lib${LIB_SUFFIX}/site-packages")
else()
set(Python_VARIANT_PATH "lib${LIB_SUFFIX}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages")
endif()

# For testing
install(
TARGETS pycasbin
LIBRARY DESTINATION ${CMAKE_SOURCE_DIR}/tests/python
)

# For actual installation
install(
TARGETS pycasbin
DESTINATION ${CMAKE_SOURCE_DIR}/tests/python
LIBRARY DESTINATION ${Python_VARIANT_PATH}
)
77 changes: 65 additions & 12 deletions casbin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,70 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FILE(GLOB_RECURSE SRC_FILES "*.cpp" "*.h")
set(CASBIN_SOURCE
abac_data.cpp
enforcer.cpp
enforcer_cached.cpp
enforcer_synced.cpp
internal_api.cpp
logger.cpp
management_api.cpp
pch.cpp
rbac_api.cpp
rbac_api_with_domains.cpp
config/config.cpp
duktape/duktape.cpp
effect/default_effector.cpp
ip_parser/exception/parser_exception.cpp
ip_parser/parser/allFF.cpp
ip_parser/parser/CIDRMask.cpp
ip_parser/parser/dtoi.cpp
ip_parser/parser/equal.cpp
ip_parser/parser/IP.cpp
ip_parser/parser/IPNet.cpp
ip_parser/parser/IPv4.cpp
ip_parser/parser/parseCIDR.cpp
ip_parser/parser/parseIP.cpp
ip_parser/parser/parseIPv4.cpp
ip_parser/parser/parseIPv6.cpp
ip_parser/parser/Print.cpp
ip_parser/parser/xtoi.cpp
model/assertion.cpp
model/function.cpp
model/model.cpp
model/scope_config.cpp
persist/file_adapter/batch_file_adapter.cpp
persist/file_adapter/file_adapter.cpp
persist/file_adapter/filtered_file_adapter.cpp
persist/adapter.cpp
persist/default_watcher.cpp
persist/default_watcher_ex.cpp
rbac/default_role_manager.cpp
util/array_equals.cpp
util/array_remove_duplicates.cpp
util/array_to_string.cpp
util/built_in_functions.cpp
util/ends_with.cpp
util/escape_assertion.cpp
util/find_all_occurences.cpp
util/is_instance_of.cpp
util/join.cpp
util/join_slice.cpp
util/remove_comments.cpp
util/set_subtract.cpp
util/split.cpp
util/ticker.cpp
util/trim.cpp
)

# Setting to C++ standard to C++17
set(CMAKE_CXX_STANDARD 17)

add_library(casbin ${SRC_FILES})
include_directories(${CMAKE_SOURCE_DIR}/casbin)
add_library(casbin ${CASBIN_SOURCE})
target_include_directories(casbin PUBLIC ${CMAKE_SOURCE_DIR}/casbin)

target_precompile_headers(casbin PUBLIC "pch.h")

set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR})

set_target_properties(casbin PROPERTIES
PREFIX ""
)
Expand All @@ -37,13 +89,14 @@ elseif(UNIX)
)
endif()

install(
TARGETS casbin
DESTINATION lib
)
install(TARGETS casbin EXPORT CasbinTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

install(
DIRECTORY ${CMAKE_SOURCE_DIR}/casbin
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
DIRECTORY ${CMAKE_SOURCE_DIR}/include/casbin
DESTINATION include
)
6 changes: 3 additions & 3 deletions casbin/casbin.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "enforcer_cached.h"
#include "enforcer_synced.h"
#include "config/config.h"
#include "persist.h"
#include "persist/persist.h"
#include "util.h"
#include "exception.h"
#include "rbac.h"
#include "exception/exception.h"
#include "rbac/rbac.h"
#include "abac_data.h"
2 changes: 2 additions & 0 deletions casbin/duktape/duktape.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
* (``sami.vaarala@iki.fi``) and I'll fix the omission.
*/

#include "duk_config.h"

#if !defined(DUKTAPE_H_INCLUDED)
#define DUKTAPE_H_INCLUDED

Expand Down
24 changes: 0 additions & 24 deletions casbin/effect.h

This file was deleted.

2 changes: 1 addition & 1 deletion casbin/effect/effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace casbin {

enum class Effect{
enum class Effect {
Allow, Indeterminate, Deny
};

Expand Down
14 changes: 7 additions & 7 deletions casbin/exception.h → casbin/exception/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#ifndef CASBIN_CPP_EXCEPTION
#define CASBIN_CPP_EXCEPTION

#include "./exception/casbin_adapter_exception.h"
#include "./exception/casbin_enforcer_exception.h"
#include "./exception/casbin_rbac_exception.h"
#include "./exception/illegal_argument_exception.h"
#include "./exception/io_exception.h"
#include "./exception/missing_required_sections.h"
#include "./exception/unsupported_operation_exception.h"
#include "casbin_adapter_exception.h"
#include "casbin_enforcer_exception.h"
#include "casbin_rbac_exception.h"
#include "illegal_argument_exception.h"
#include "io_exception.h"
#include "missing_required_sections.h"
#include "unsupported_operation_exception.h"

#endif
25 changes: 0 additions & 25 deletions casbin/model.h

This file was deleted.

3 changes: 3 additions & 0 deletions casbin/model/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

#include "./assertion.h"
#include "../config/config_interface.h"
#include "assertion.h"
#include "function.h"
#include "scope_config.h"

namespace casbin {

Expand Down
32 changes: 0 additions & 32 deletions casbin/persist.h

This file was deleted.

17 changes: 13 additions & 4 deletions casbin/config.h → casbin/persist/persist.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@
* limitations under the License.
*/

#ifndef CASBIN_CPP_CONFIG
#define CASBIN_CPP_CONFIG
#ifndef CASBIN_CPP_PERSIST
#define CASBIN_CPP_PERSIST

#include "./config/config.h"
#include "./config/config_interface.h"
#include "adapter.h"
#include "filtered_adapter.h"
#include "batch_adapter.h"
#include "default_watcher.h"
#include "default_watcher_ex.h"
#include "watcher.h"
#include "watcher_ex.h"

#include "file_adapter/batch_file_adapter.h"
#include "file_adapter/file_adapter.h"
#include "file_adapter/filtered_file_adapter.h"

#endif
4 changes: 2 additions & 2 deletions casbin/rbac.h → casbin/rbac/rbac.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef CASBIN_CPP_RBAC
#define CASBIN_CPP_RBAC

#include "./rbac/default_role_manager.h"
#include "./rbac/role_manager.h"
#include "default_role_manager.h"
#include "role_manager.h"

#endif
23 changes: 0 additions & 23 deletions casbin/util.h

This file was deleted.

2 changes: 2 additions & 0 deletions casbin/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <vector>
#include <string>

#include "built_in_functions.h"

namespace casbin {

// ArrayEquals determines whether two std::string arrays are identical.
Expand Down
Loading

0 comments on commit 673bc01

Please sign in to comment.