Skip to content

Commit 82df5c8

Browse files
committed
Added possibility to include particular files only in the build
1 parent e8f76a5 commit 82df5c8

File tree

9 files changed

+501
-51
lines changed

9 files changed

+501
-51
lines changed

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"functional": "c",
4848
"tuple": "c",
4949
"type_traits": "c",
50-
"utility": "c"
50+
"utility": "c",
51+
"xcli.h": "c"
5152
}
5253
}

CMakeLists.tmp

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)
2+
project(libxutils LANGUAGES C)
3+
4+
IF (WIN32)
5+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Od /W3")
6+
ELSE()
7+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -Wall")
8+
ENDIF()
9+
10+
set(THREADS_PREFER_PTHREAD_FLAG ON)
11+
find_package(Threads REQUIRED)
12+
13+
find_package(OpenSSL)
14+
IF(OpenSSL_FOUND)
15+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XUTILS_USE_SSL")
16+
ENDIF()
17+
18+
SET(HEADER_DST "include/xutils")
19+
SET(SOURCE_DIR "./src")
20+
SET(CRYPT_DIR "./src/crypt")
21+
SET(DATA_DIR "./src/data")
22+
SET(NET_DIR "./src/net")
23+
SET(SYS_DIR "./src/sys")
24+
25+
include_directories(
26+
${SOURCE_DIR}
27+
${CRYPT_DIR}
28+
${DATA_DIR}
29+
${NET_DIR}
30+
${SYS_DIR}
31+
)
32+
33+
add_library(xutils STATIC
34+
_SOURCE_LIST_
35+
)
36+
37+
install(TARGETS xutils DESTINATION lib)
38+
39+
install(DIRECTORY "${SOURCE_DIR}/"
40+
DESTINATION "${HEADER_DST}"
41+
FILES_MATCHING
42+
PATTERN "*.h"
43+
)
44+
45+
install(DIRECTORY "${CRYPT_DIR}/"
46+
DESTINATION "${HEADER_DST}"
47+
FILES_MATCHING
48+
PATTERN "*.h"
49+
)
50+
51+
install(DIRECTORY "${DATA_DIR}/"
52+
DESTINATION "${HEADER_DST}"
53+
FILES_MATCHING
54+
PATTERN "*.h"
55+
)
56+
57+
install(DIRECTORY "${NET_DIR}/"
58+
DESTINATION "${HEADER_DST}"
59+
FILES_MATCHING
60+
PATTERN "*.h"
61+
)
62+
63+
install(DIRECTORY "${SYS_DIR}/"
64+
DESTINATION "${HEADER_DST}"
65+
FILES_MATCHING
66+
PATTERN "*.h"
67+
)

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ add_library(xutils STATIC
4444
${CRYPT_DIR}/aes.c
4545
${CRYPT_DIR}/base64.c
4646
${CRYPT_DIR}/sha256.c
47+
${CRYPT_DIR}/sha1.c
4748
${CRYPT_DIR}/crc32.c
4849
${CRYPT_DIR}/hmac.c
4950
${CRYPT_DIR}/md5.c

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,41 @@ make
8989
sudo make install
9090
```
9191

92+
### Build particular files only
93+
If you want to use particular files and functions, you can configure the library and select only that functionality for the build. In this way, it is possible not to increase the size of the program and to avoid the linkage of unused code.
94+
95+
The `libxutils` project has a config file that contains a list of modules that will be included in the build. This file is used by the `generate.sh` script, which resolves dependencies for each enabled module and generates a `CMakeList.txt` file.
96+
97+
Open `xutils.conf` file with a text editor and mark only the functionality you want to include in the build. Use a low-case `y` symbol to enable and any other symbol to disable modules. Removing a related line from the list will also disable the module.
98+
99+
Example:
100+
```
101+
...
102+
USE_ARRAY=n
103+
USE_CRYPT=n
104+
USE_XTIME=n
105+
USE_EVENT=y
106+
USE_LIST=n
107+
USE_XBUF=n
108+
USE_HASH=n
109+
USE_SOCK=n
110+
USE_XLOG=y
111+
USE_XSTR=n
112+
...
113+
```
114+
After updating the configuration, use the `generate.sh` script to generate the `CMakeLists.txt` file and then build the project using the `CMake` tool as in this example:
115+
116+
```bash
117+
./generate.sh
118+
mkdir build
119+
cd build
120+
cmake .. && make
121+
```
122+
123+
You may notice that when you select only one module, several other modules may be also included in the build. Because some files depend on other files in the project, the `generate.sh` script will automatically resolve these dependencies and include required files in the build as well.
124+
125+
For example, if you only mark HTTP library for a build, the socket library will be automatically enabled because HTTP uses some functionality from sockets.
126+
92127
### Dependencies
93128
The only dependency that the library uses is the `openssl-devel` package for the `SSL` and `RSA` implementations.\
94129
You can either install the `openssl-devel` package or disable the `SSL` support in the library.

examples/Makefile

+49-49
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
2-
CFLAGS = -g -O2 -Wall
3-
LIBS = -lxutils -lpthread
4-
5-
ifeq ($(XUTILS_USE_SSL),y)
6-
CFLAGS += -D_XUTILS_USE_SSL
7-
LIBS += -lssl -lcrypto
8-
endif
9-
10-
EXECS = array \
11-
http-server \
12-
tcp-server \
13-
ws-server \
14-
ws-client \
15-
events \
16-
files \
17-
thread \
18-
statcov \
19-
strings \
20-
json \
21-
xtop \
22-
xlog \
23-
xcrypt \
24-
xpass \
25-
xhttp \
26-
xjson \
27-
xsrc \
28-
list \
29-
ntp \
30-
jwt \
31-
rsa
32-
33-
all: $(EXECS)
34-
35-
$(EXECS): %: %.c
36-
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
37-
38-
.PHONY: install
39-
install:
40-
install -m 0755 xcrypt /usr/local/bin/
41-
install -m 0755 xpass /usr/local/bin/
42-
install -m 0755 xjson /usr/local/bin/
43-
install -m 0755 xhttp /usr/local/bin/
44-
install -m 0755 xtop /usr/local/bin/
45-
install -m 0755 xsrc /usr/local/bin/
46-
47-
.PHONY: clean
48-
clean:
49-
$(RM) $(EXECS)
1+
2+
CFLAGS = -g -O2 -Wall
3+
LIBS = -lxutils -lpthread
4+
5+
ifeq ($(XUTILS_USE_SSL),y)
6+
CFLAGS += -D_XUTILS_USE_SSL
7+
LIBS += -lssl -lcrypto
8+
endif
9+
10+
EXECS = array \
11+
http-server \
12+
tcp-server \
13+
ws-server \
14+
ws-client \
15+
events \
16+
files \
17+
thread \
18+
statcov \
19+
strings \
20+
json \
21+
xtop \
22+
xlog \
23+
xcrypt \
24+
xpass \
25+
xhttp \
26+
xjson \
27+
xsrc \
28+
list \
29+
ntp \
30+
jwt \
31+
rsa
32+
33+
all: $(EXECS)
34+
35+
$(EXECS): %: %.c
36+
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
37+
38+
.PHONY: install
39+
install:
40+
install -m 0755 xcrypt /usr/local/bin/
41+
install -m 0755 xpass /usr/local/bin/
42+
install -m 0755 xjson /usr/local/bin/
43+
install -m 0755 xhttp /usr/local/bin/
44+
install -m 0755 xtop /usr/local/bin/
45+
install -m 0755 xsrc /usr/local/bin/
46+
47+
.PHONY: clean
48+
clean:
49+
$(RM) $(EXECS)

0 commit comments

Comments
 (0)