Skip to content

Commit 883e04a

Browse files
added cmake build systems and cpack for creating deb and rpm packages
1 parent 94d5ea2 commit 883e04a

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cmake-build
12
*.o
23
Makefile.depend
34
udptunnel

CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
cmake_minimum_required (VERSION 3.10)
2+
project ("udptunnel" "C")
3+
4+
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
5+
message (FATAL_ERROR "In-source builds are not allowed")
6+
endif ()
7+
8+
set (CMAKE_PROJECT_DESCRIPTION "UDP tunnel over TCP")
9+
set (CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/andrew-aladjev/udptunnel")
10+
set (PROJECT_VERSION "1.2.0")
11+
12+
if (NOT DEFINED CMAKE_INSTALL_BINDIR)
13+
set (CMAKE_INSTALL_BINDIR "sbin" CACHE PATH "output directory for binaries")
14+
endif ()
15+
16+
set (CMAKE_C_FLAGS "-O2 -std=c11 -Wall")
17+
18+
if (NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
19+
set (CMAKE_BUILD_TYPE "Release")
20+
endif ()
21+
22+
set (
23+
SOURCES
24+
"log.c"
25+
"network.c"
26+
"udptunnel.c"
27+
"utils.c"
28+
)
29+
30+
add_executable (${PROJECT_NAME} ${SOURCES})
31+
install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
32+
33+
include (CPackConfig.cmake)
34+
include (CPack)

CPackConfig.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
set (CPACK_PACKAGE_NAME ${PROJECT_NAME})
2+
set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
3+
set (CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
4+
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")
5+
6+
set (CPACK_PACKAGE_LICENSE "LGPLv2")
7+
set (CPACK_RPM_PACKAGE_LICENSE ${CPACK_PACKAGE_LICENSE})
8+
set (CPACK_FREEBSD_PACKAGE_LICENSE ${CPACK_PACKAGE_LICENSE})
9+
10+
set (CPACK_PACKAGE_MAINTAINER "Andrew Aladjev <andrew-aladjev@gmail.com>")
11+
set (CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_MAINTAINER})
12+
set (CPACK_FREEBSD_PACKAGE_MAINTAINER ${CPACK_PACKAGE_MAINTAINER})
13+
14+
set (CPACK_FREEBSD_PACKAGE_ORIGIN "net/${PROJECT_NAME}")
15+
16+
set (CPACK_PACKAGE_ARCHITECTURE "amd64")
17+
set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${CPACK_PACKAGE_ARCHITECTURE})
18+
set (CPACK_RPM_PACKAGE_ARCHITECTURE ${CPACK_PACKAGE_ARCHITECTURE})
19+
20+
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
21+
set (CPACK_GENERATOR "DEB" "RPM")
22+
elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
23+
set (CPACK_GENERATOR "FREEBSD")
24+
endif ()
25+
26+
set (PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
27+
set (CPACK_PACKAGE_FILE_NAME "${PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CPACK_PACKAGE_ARCHITECTURE}")
28+
set (CPACK_STRIP_FILES true)

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
UDP tunnel over TCP. License: LGPLv2.
2+
3+
Please build it using the following commands:
4+
5+
```bash
6+
rm -rf cmake-build
7+
cmake -S . -B cmake-build
8+
cmake --build cmake-build
9+
cmake --build cmake-build --target package
10+
```
11+
12+
After that you will receive packages for DEB-based and RPM-based distros:
13+
14+
```
15+
cmake-build/udptunnel-*.amd64.deb
16+
cmake-build/udptunnel-*.amd64.rpm
17+
```

0 commit comments

Comments
 (0)