Skip to content

Commit 90c38f2

Browse files
committed
chore: add cmake support
Signed-off-by: Zixuan Liu <[email protected]>
1 parent 9133467 commit 90c38f2

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,7 @@ MigrationBackup/
351351
.ionide/
352352

353353
.idea/
354-
*.iml
354+
*.iml
355+
356+
# CMake work directory
357+
cmake-build/

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,18 @@ https://casbin.org/docs/en/tutorials
119119
#### Unix
120120
- `Clone` the repository in your target client project
121121
- Change the current working directory to the `casbin-cpp` directory and build the library through following commands:
122+
- ***Make***
122123
```shell
123-
$ make
124-
$ make library
124+
$ make
125+
$ make library
126+
```
127+
- ***CMake***
128+
```shell
129+
$ make build
125130
```
126131
- To get rid of intermediate files generated during building of library:
127132
```shell
128-
$ make clean
133+
$ make clean
129134
```
130135
- Now, you can use the file present in `lib` directory, created through `archiver`, as a static library
131136

makefile

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
1-
#Define C/C++ compiler variables
1+
# Define C/C++ compiler variables
22
CXX := g++
33
AR := ar
44

5-
#Define compiler flags
5+
# Define compiler flags
66
OBJ_FLAG := -c
7-
FILE_FLAG := -o
7+
FILE_FLAG := -o
88
STD_FLAG := -std=c++11
99

10-
#Define archive flags
10+
# Define archive flags
1111
AR_FLAG := crv
1212
AR_NAME := casbin.a
1313

14-
#Define directory variables
14+
# Define directory variables
1515
SRC_DIR := casbin
1616
OBJ_DIR := obj
1717
LIB_DIR := lib
1818

19-
#Define extension variables
19+
# Define extension variables
2020
SRC_EXT := cpp
2121
OBJ_EXT := o
2222
LIB_EXT := a
2323
INC_EXT := h
2424

25-
#Define make directory command variable
25+
# Define make directory command variable
2626
MKDIR_P := mkdir -p
2727

28-
#Get source cpp files
28+
# Get source cpp files
2929
SRC_FILES := $(shell find $(SRC_DIR) -type f -name *.$(SRC_EXT))
3030
INC_DIRS := $(shell find $(SRC_DIR) -type d)
3131
INC_FLAG_DIRS := $(addprefix -I /, $(INC_DIRS))
3232
OBJ_DIRS := $(addprefix $(OBJ_DIR)/, $(INC_DIRS))
3333

34+
.PHONY: object
3435
object:
3536
$(foreach OBJ_DIR, $(OBJ_DIRS),\
3637
$(MKDIR_P) $(OBJ_DIR);\
@@ -42,10 +43,18 @@ object:
4243
#Get object files
4344
OBJ_FILES := $(shell find $(OBJ_DIR) -type f -name *.$(OBJ_EXT))
4445

46+
.PHONY: library
4547
library:
4648
$(MKDIR_P) $(LIB_DIR)
4749
$(AR) $(AR_FLAG) $(AR_NAME) $(OBJ_FILES)
4850
mv $(AR_NAME) $(LIB_DIR)/$(AR_NAME)
4951

52+
.PHONY: clean
5053
clean:
5154
rm -r $(OBJ_DIR)
55+
56+
.PHONY: build
57+
build:
58+
rm -rf cmake-build
59+
mkdir cmake-build
60+
cd cmake-build ; cmake .. ; make

0 commit comments

Comments
 (0)