Skip to content

Commit b0cc18c

Browse files
friissorenTomas Winkler
authored and
Tomas Winkler
committed
safestringlib: add Cmake support for creating a Debian package
Signed-off-by: Soren Friis <soren.friis@intel.com>
1 parent 02fdf9d commit b0cc18c

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

CMakeLists.txt

+48-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# SPDX-License-Identifier: MIT
22
# Copyright (C) 2019-2023 Intel Corporation
33
cmake_minimum_required(VERSION 3.5)
4-
project(safestring)
54

65
include(version.cmake)
76

7+
project(safestring
8+
VERSION ${SAFEC_VERSION_STRING}
9+
DESCRIPTION "Safe C string library"
10+
)
11+
812
option(BUILD_UNITTESTS "Build also project unit-tests" OFF)
913

1014
if(NOT DEFINED BUILD_OPT_DEFAULT)
@@ -184,7 +188,11 @@ target_compile_options(${PROJECT_NAME}_objlib PRIVATE $<$<CONFIG:RELEASE>:-s>)
184188

185189
add_library(${PROJECT_NAME}_shared SHARED $<TARGET_OBJECTS:${PROJECT_NAME}_objlib>)
186190
add_library(${PROJECT_NAME}_static STATIC $<TARGET_OBJECTS:${PROJECT_NAME}_objlib>)
187-
target_include_directories(${PROJECT_NAME}_shared PUBLIC include)
191+
192+
target_include_directories(${PROJECT_NAME}_shared PUBLIC
193+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
194+
$<INSTALL_INTERFACE:include>
195+
)
188196
target_include_directories(${PROJECT_NAME}_static PUBLIC include)
189197

190198
set_target_properties(${PROJECT_NAME}_shared PROPERTIES VERSION ${SAFEC_VERSION_STRING})
@@ -193,3 +201,41 @@ set_target_properties(${PROJECT_NAME}_static PROPERTIES VERSION ${SAFEC_VERSION_
193201
if(BUILD_UNITTESTS)
194202
add_subdirectory(unittests)
195203
endif()
204+
205+
# Install targets
206+
set(PUBLIC_HEADERS
207+
include/safe_lib_errno.h
208+
include/safe_lib.h
209+
include/safe_mem_lib.h
210+
include/safe_str_lib.h
211+
include/safe_types.h
212+
include/snprintf_s.h
213+
)
214+
215+
set_target_properties(${PROJECT_NAME}_shared PROPERTIES
216+
PUBLIC_HEADER "${PUBLIC_HEADERS}"
217+
)
218+
219+
install(TARGETS ${PROJECT_NAME}_shared EXPORT ${PROJECT_NAME}Config
220+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
221+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
222+
)
223+
224+
install(EXPORT ${PROJECT_NAME}Config DESTINATION share/${PROJECT_NAME}/cmake)
225+
226+
export(TARGETS ${PROJECT_NAME}_shared FILE ${PROJECT_NAME}Config.cmake)
227+
228+
# Debian package information for CPack
229+
set(CPACK_GENERATOR "DEB")
230+
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel")
231+
set(CPACK_PACKAGE_VERSION_MAJOR "${SAFEC_VERSION_MAJOR}")
232+
set(CPACK_PACKAGE_VERSION_MINOR "${SAFEC_VERSION_MINOR}")
233+
set(CPACK_PACKAGE_VERSION_PATCH "${SAFEC_VERSION_PATCH}")
234+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "SafeStringLib is an Intel enhanced version of the Safe C Library by Cisco.")
235+
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
236+
set(CPACK_DEBIAN_PACKAGE_NAME "lib${PROJECT_NAME}")
237+
set(CPACK_DISPLAY_NAME "lib${PROJECT_NAME} run-time library")
238+
set(CPACK_PACKAGE_NAME "lib${PROJECT_NAME}")
239+
set(CPACK_DESCRIPTION "Safe String library and header files.")
240+
include(GNUInstallDirs)
241+
include(CPack)

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,31 @@ PLANNED ENHANCEMENTS:
8484
----------------------
8585
- Add full sprintf_s() support
8686
- Add full sscanf_s() support
87+
88+
89+
# Compile and create Debian package (Ubuntu)
90+
On Ubuntu (probably also works on other Linux distributions), use the following commands to compile a library and create a Debian package for distribution.
91+
```
92+
cmake -S . -B build
93+
cd build
94+
make -j
95+
cpack
96+
```
97+
98+
The generated package can be installed and removed using the following commands:
99+
```
100+
sudo dpkg -i libsafestring_<version>_amd64.deb
101+
102+
sudo dpkg --purge libsafestring
103+
```
104+
105+
When compiling other projects against the safestring library installed via the Debian package, in the source files:
106+
```
107+
#include <safe_lib.h>
108+
#include <other relevant safestringlib headers>
109+
```
110+
111+
In the CMakeLists.txt, add:
112+
```
113+
target_link_libraries(<target name> safestring_shared <other possible library dependencies>)
114+
```

0 commit comments

Comments
 (0)