Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Commit a026f5e

Browse files
dkosawagldiviney
authored andcommitted
Safeclib Optional Download and Static Link Build Option
Signed-off-by: Daniel K Osawa <daniel.k.osawa@intel.com>
1 parent 1191a65 commit a026f5e

File tree

4 files changed

+123
-2
lines changed

4 files changed

+123
-2
lines changed

CMake/safeclib.cmake

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# @internal
2+
# @copyright
3+
# Copyright (c) 2018, Intel Corporation All Rights Reserved.
4+
#
5+
# INTEL CONFIDENTIAL
6+
#
7+
# The source code contained or described herein and all documents related to the
8+
# source code ("Material") are owned by Intel Corporation or its suppliers or
9+
# licensors. Title to the Material remains with Intel Corporation or its
10+
# suppliers and licensors. The Material may contain trade secrets and proprietary
11+
# and confidential information of Intel Corporation and its suppliers and licensors,
12+
# and is protected by worldwide copyright and trade secret laws and treaty
13+
# provisions. No part of the Material may be used, copied, reproduced, modified,
14+
# published, uploaded, posted, transmitted, distributed, or disclosed in any way
15+
# without Intel's prior express written permission.
16+
17+
# No license under any patent, copyright, trade secret or other intellectual
18+
# property right is granted to or conferred upon you by disclosure or delivery
19+
# of the Materials, either expressly, by implication, inducement, estoppel or
20+
# otherwise. Any license under such intellectual property rights must be express
21+
# and approved by Intel in writing.
22+
23+
# Unless otherwise agreed by Intel in writing, you may not remove or alter this
24+
# notice or any other notice embedded in Materials by Intel or Intel's suppliers
25+
# or licensors in any way.
26+
# @endinternal
27+
28+
#----------------------------------------------------------------------------------------------------
29+
# Project wide defines and flags
30+
#----------------------------------------------------------------------------------------------------
31+
32+
33+
#----------------------------------------------------------------------------------------------------
34+
# Create Safe String Library
35+
#----------------------------------------------------------------------------------------------------
36+
# safe c library requires the compiler path with double quotes. Also, doesn't accept few of the C compiler flags
37+
set(CMAKE_C_FLAGS_SAFEC "-DNO_MSABI_VA_FUNCS -fPIC")
38+
39+
include(ExternalProject)
40+
find_package(Git REQUIRED)
41+
42+
ExternalProject_Add(safeclib_proj
43+
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/safeclib
44+
DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/safeclib
45+
GIT_REPOSITORY https://github.com/rurban/safeclib
46+
GIT_TAG 59eba324c20c07f7ca8190238dd415525f4925dc
47+
UPDATE_COMMAND ""
48+
CONFIGURE_COMMAND ./build-tools/autogen.sh && ./configure CFLAGS=${CMAKE_C_FLAGS_SAFEC} --enable-strmax=0x8000 --enable-shared=no --disable-doc
49+
BUILD_COMMAND make
50+
BUILD_IN_SOURCE ON
51+
STEP_TARGETS build
52+
BUILD_ALWAYS OFF
53+
BUILD_BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/safeclib/src/safeclib_proj/src/.libs/libsafec-3.3.a
54+
INSTALL_COMMAND ""
55+
LOG_DOWNLOAD ON
56+
LOG_UPDATE ON
57+
LOG_BUILD ON
58+
)
59+
60+
ExternalProject_Get_property(safeclib_proj SOURCE_DIR)
61+
add_library(safeclib STATIC IMPORTED)
62+
set_property(TARGET safeclib PROPERTY IMPORTED_LOCATION ${SOURCE_DIR}/src/.libs/libsafec-3.3.a)
63+
add_dependencies(safeclib safeclib_proj)
64+
set(SAFECLIB_COMPILE_FLAGS "-DHAVE_C99")
65+
66+
#----------------------------------------------------------------------------------------------------
67+
# OS driver interface library
68+
#----------------------------------------------------------------------------------------------------
69+
70+
target_link_libraries(ipmctl_os_interface
71+
safeclib
72+
)
73+
target_include_directories(ipmctl_os_interface
74+
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/safeclib/src/safeclib_proj/include)
75+
76+
set_source_files_properties(${OS_INTERFACE_SOURCE_FILES}
77+
PROPERTIES COMPILE_FLAGS ${SAFECLIB_COMPILE_FLAGS})
78+
79+
#----------------------------------------------------------------------------------------------------
80+
# libipmctl
81+
#----------------------------------------------------------------------------------------------------
82+
target_link_libraries(ipmctl
83+
safeclib
84+
)
85+
86+
target_include_directories(ipmctl
87+
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/safeclib/src/safeclib_proj/include)
88+
89+
set_source_files_properties(${LIBIPMCTL_SOURCE_FILES}
90+
PROPERTIES COMPILE_FLAGS ${SAFECLIB_COMPILE_FLAGS})
91+
92+
#---------------------------------------------------------------------------------------------------
93+
# ipmctl executable
94+
#---------------------------------------------------------------------------------------------------
95+
set_source_files_properties(${IPMCTL_SOURCE_FILES}
96+
PROPERTIES COMPILE_FLAGS ${SAFECLIB_COMPILE_FLAGS})
97+
98+
#---------------------------------------------------------------------------------------------------
99+
# Monitor service executable
100+
#---------------------------------------------------------------------------------------------------
101+
set_source_files_properties(${IPMCTL_MONITOR_SOURCE_FILES}
102+
PROPERTIES COMPILE_FLAGS ${SAFECLIB_COMPILE_FLAGS})

CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ elseif(UNIX)
8484
find_package(asciidoc)
8585
pkg_check_modules(NDCTL REQUIRED libndctl>=58.2)
8686
pkg_check_modules(SYSTEMD systemd)
87+
if(NOT SAFECLIB_SRC_DOWNLOAD_AND_STATIC_LINK)
8788
pkg_check_modules(LIBSAFEC REQUIRED safec-3.3>=03032018.0-g570fa5)
89+
endif()
8890
elseif(MSVC)
8991
set(WIN_BUILD 1)
9092
set(OS_TYPE win)
@@ -198,7 +200,7 @@ target_link_libraries(ipmctl_os_interface
198200
${CMAKE_THREAD_LIBS_INIT}
199201
)
200202

201-
if(LNX_BUILD)
203+
if(LNX_BUILD AND (NOT SAFECLIB_SRC_DOWNLOAD_AND_STATIC_LINK))
202204
target_link_libraries(ipmctl_os_interface
203205
${LIBSAFEC_LIBRARIES}
204206
)
@@ -485,10 +487,17 @@ if (NOT ESX_BUILD)
485487

486488
add_executable(ipmctl-monitor ${IPMCTL_MONITOR_SOURCE_FILES})
487489

490+
if(NOT SAFECLIB_SRC_DOWNLOAD_AND_STATIC_LINK)
488491
target_link_libraries(ipmctl-monitor
489492
ipmctl
490493
${LIBSAFEC_LIBRARIES}
491494
)
495+
else()
496+
target_link_libraries(ipmctl-monitor
497+
ipmctl
498+
)
499+
endif()
500+
492501

493502
target_include_directories(ipmctl-monitor PUBLIC
494503
src/os
@@ -778,4 +787,6 @@ endif()
778787

779788
if(ESX_BUILD)
780789
include(CMake/esx.cmake)
781-
endif()
790+
elseif(UNIX AND SAFECLIB_SRC_DOWNLOAD_AND_STATIC_LINK)
791+
include(CMake/safeclib.cmake)
792+
endif()

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,22 @@ Ubuntu packages can be found at: https://launchpad.net/~jhli/+archive/ubuntu/ipm
2929

3030
### libsafec
3131

32+
3233
ipmctl requires libsafec as a dependency.
3334

35+
3436
libsafec is availible on Fedora.
3537

38+
3639
EPEL 7 packages can be found at: https://copr.fedorainfracloud.org/coprs/jhli/safeclib/
3740

41+
3842
OpenSUSE and SLES packages can be found at: https://build.opensuse.org/package/show/home:jhli/safeclib
3943

44+
4045
Ubuntu packages can be found at: https://launchpad.net/~jhli/+archive/ubuntu/libsafec
4146

47+
Alternately, -DSAFECLIB_SRC_DOWNLOAD_AND_STATIC_LINK=ON to download sources and statically link to safeclib
4248

4349
## Build
4450

install/linux/rel-release/ipmctl.spec.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ API for development of Intel Optane DC persistent memory management utilities.
8686
-DCMAKE_INSTALL_SYSCONFDIR=%{_sysconfdir} \
8787
-DINSTALL_UNITDIR=%{_unitdir} \
8888
-DRELEASE=ON \
89+
-DSAFECLIB_SRC_DOWNLOAD_AND_STATIC_LINK=OFF \
8990
-DRPM_BUILD=ON
9091
%else
9192
%cmake -DBUILDNUM=%{version} -DCMAKE_INSTALL_PREFIX=/ \
@@ -100,6 +101,7 @@ API for development of Intel Optane DC persistent memory management utilities.
100101
-DINSTALL_UNITDIR=%{_unitdir} \
101102
-DRELEASE=ON \
102103
-DRPM_BUILD=ON \
104+
-DSAFECLIB_SRC_DOWNLOAD_AND_STATIC_LINK=OFF \
103105
-DWHITLEY=ON
104106
%endif
105107
%make_build

0 commit comments

Comments
 (0)