Skip to content

Commit 673bc01

Browse files
authored
Merge pull request #138 from EmperorYP7/cmake-config
refactor: Exported targets for easy access
2 parents 32bfa27 + a5a4e77 commit 673bc01

File tree

24 files changed

+8983
-148
lines changed

24 files changed

+8983
-148
lines changed

CMakeLists.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ endif()
3131
###############################################################################
3232
# Project definition.
3333

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

8888
add_subdirectory(casbin)
89+
90+
export(TARGETS
91+
casbin
92+
NAMESPACE casbin::
93+
FILE "${CMAKE_CURRENT_BINARY_DIR}/CasbinConfig.cmake"
94+
)
95+
96+
if(CASBIN_BUILD_PYTHON_BINDINGS)
97+
export(TARGETS pycasbin
98+
NAMESPACE casbin::
99+
FILE "${CMAKE_CURRENT_BINARY_DIR}/PyCasbinConfig.cmake"
100+
)
101+
endif()

bindings/python/CMakeLists.txt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ set(HEADERS
2626

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

29-
target_include_directories(pycasbin PUBLIC ${CMAKE_SOURCE_DIR})
29+
target_include_directories(pycasbin PUBLIC ${CMAKE_SOURCE_DIR}/include)
3030

3131
set_target_properties(pycasbin PROPERTIES
3232
PREFIX ""
@@ -42,9 +42,6 @@ if(WIN32)
4242
)
4343
endif()
4444

45-
46-
# NOTE: Depending of the compiler version pybind11 2.4.3 does not compile with C++17 so revert to c++11
47-
4845
if(UNIX)
4946
# A 'module' is a dynamic library on Linux (i.e. '-fPIC' needed),
5047
# but a static library on Windows.
@@ -70,7 +67,20 @@ target_link_libraries(pycasbin
7067
casbin
7168
)
7269

70+
if(WIN32)
71+
set(Python_VARIANT_PATH "lib${LIB_SUFFIX}/site-packages")
72+
else()
73+
set(Python_VARIANT_PATH "lib${LIB_SUFFIX}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages")
74+
endif()
75+
76+
# For testing
77+
install(
78+
TARGETS pycasbin
79+
LIBRARY DESTINATION ${CMAKE_SOURCE_DIR}/tests/python
80+
)
81+
82+
# For actual installation
7383
install(
7484
TARGETS pycasbin
75-
DESTINATION ${CMAKE_SOURCE_DIR}/tests/python
85+
LIBRARY DESTINATION ${Python_VARIANT_PATH}
7686
)

casbin/CMakeLists.txt

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,70 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FILE(GLOB_RECURSE SRC_FILES "*.cpp" "*.h")
15+
set(CASBIN_SOURCE
16+
abac_data.cpp
17+
enforcer.cpp
18+
enforcer_cached.cpp
19+
enforcer_synced.cpp
20+
internal_api.cpp
21+
logger.cpp
22+
management_api.cpp
23+
pch.cpp
24+
rbac_api.cpp
25+
rbac_api_with_domains.cpp
26+
config/config.cpp
27+
duktape/duktape.cpp
28+
effect/default_effector.cpp
29+
ip_parser/exception/parser_exception.cpp
30+
ip_parser/parser/allFF.cpp
31+
ip_parser/parser/CIDRMask.cpp
32+
ip_parser/parser/dtoi.cpp
33+
ip_parser/parser/equal.cpp
34+
ip_parser/parser/IP.cpp
35+
ip_parser/parser/IPNet.cpp
36+
ip_parser/parser/IPv4.cpp
37+
ip_parser/parser/parseCIDR.cpp
38+
ip_parser/parser/parseIP.cpp
39+
ip_parser/parser/parseIPv4.cpp
40+
ip_parser/parser/parseIPv6.cpp
41+
ip_parser/parser/Print.cpp
42+
ip_parser/parser/xtoi.cpp
43+
model/assertion.cpp
44+
model/function.cpp
45+
model/model.cpp
46+
model/scope_config.cpp
47+
persist/file_adapter/batch_file_adapter.cpp
48+
persist/file_adapter/file_adapter.cpp
49+
persist/file_adapter/filtered_file_adapter.cpp
50+
persist/adapter.cpp
51+
persist/default_watcher.cpp
52+
persist/default_watcher_ex.cpp
53+
rbac/default_role_manager.cpp
54+
util/array_equals.cpp
55+
util/array_remove_duplicates.cpp
56+
util/array_to_string.cpp
57+
util/built_in_functions.cpp
58+
util/ends_with.cpp
59+
util/escape_assertion.cpp
60+
util/find_all_occurences.cpp
61+
util/is_instance_of.cpp
62+
util/join.cpp
63+
util/join_slice.cpp
64+
util/remove_comments.cpp
65+
util/set_subtract.cpp
66+
util/split.cpp
67+
util/ticker.cpp
68+
util/trim.cpp
69+
)
1670

1771
# Setting to C++ standard to C++17
1872
set(CMAKE_CXX_STANDARD 17)
1973

20-
add_library(casbin ${SRC_FILES})
21-
include_directories(${CMAKE_SOURCE_DIR}/casbin)
74+
add_library(casbin ${CASBIN_SOURCE})
75+
target_include_directories(casbin PUBLIC ${CMAKE_SOURCE_DIR}/casbin)
2276

2377
target_precompile_headers(casbin PUBLIC "pch.h")
2478

25-
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR})
26-
2779
set_target_properties(casbin PROPERTIES
2880
PREFIX ""
2981
)
@@ -37,13 +89,14 @@ elseif(UNIX)
3789
)
3890
endif()
3991

40-
install(
41-
TARGETS casbin
42-
DESTINATION lib
43-
)
92+
install(TARGETS casbin EXPORT CasbinTargets
93+
LIBRARY DESTINATION lib
94+
ARCHIVE DESTINATION lib
95+
RUNTIME DESTINATION bin
96+
INCLUDES DESTINATION include
97+
)
4498

4599
install(
46-
DIRECTORY ${CMAKE_SOURCE_DIR}/casbin
47-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
48-
FILES_MATCHING PATTERN "*.h"
100+
DIRECTORY ${CMAKE_SOURCE_DIR}/include/casbin
101+
DESTINATION include
49102
)

casbin/casbin.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include "enforcer_cached.h"
2222
#include "enforcer_synced.h"
2323
#include "config/config.h"
24-
#include "persist.h"
24+
#include "persist/persist.h"
2525
#include "util.h"
26-
#include "exception.h"
27-
#include "rbac.h"
26+
#include "exception/exception.h"
27+
#include "rbac/rbac.h"
2828
#include "abac_data.h"

casbin/duktape/duktape.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@
157157
* (``[email protected]``) and I'll fix the omission.
158158
*/
159159

160+
#include "duk_config.h"
161+
160162
#if !defined(DUKTAPE_H_INCLUDED)
161163
#define DUKTAPE_H_INCLUDED
162164

casbin/effect.h

Lines changed: 0 additions & 24 deletions
This file was deleted.

casbin/effect/effect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace casbin {
2121

22-
enum class Effect{
22+
enum class Effect {
2323
Allow, Indeterminate, Deny
2424
};
2525

casbin/exception.h renamed to casbin/exception/exception.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
#ifndef CASBIN_CPP_EXCEPTION
1818
#define CASBIN_CPP_EXCEPTION
1919

20-
#include "./exception/casbin_adapter_exception.h"
21-
#include "./exception/casbin_enforcer_exception.h"
22-
#include "./exception/casbin_rbac_exception.h"
23-
#include "./exception/illegal_argument_exception.h"
24-
#include "./exception/io_exception.h"
25-
#include "./exception/missing_required_sections.h"
26-
#include "./exception/unsupported_operation_exception.h"
20+
#include "casbin_adapter_exception.h"
21+
#include "casbin_enforcer_exception.h"
22+
#include "casbin_rbac_exception.h"
23+
#include "illegal_argument_exception.h"
24+
#include "io_exception.h"
25+
#include "missing_required_sections.h"
26+
#include "unsupported_operation_exception.h"
2727

2828
#endif

casbin/model.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

casbin/model/model.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
#include "./assertion.h"
2323
#include "../config/config_interface.h"
24+
#include "assertion.h"
25+
#include "function.h"
26+
#include "scope_config.h"
2427

2528
namespace casbin {
2629

0 commit comments

Comments
 (0)