Skip to content

Commit

Permalink
Safeclib Optional Download and Static Link Build Option
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel K Osawa <[email protected]>
  • Loading branch information
dkosawa authored and gldiviney committed Dec 4, 2018
1 parent 1191a65 commit a026f5e
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 2 deletions.
102 changes: 102 additions & 0 deletions CMake/safeclib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# @internal
# @copyright
# Copyright (c) 2018, Intel Corporation All Rights Reserved.
#
# INTEL CONFIDENTIAL
#
# The source code contained or described herein and all documents related to the
# source code ("Material") are owned by Intel Corporation or its suppliers or
# licensors. Title to the Material remains with Intel Corporation or its
# suppliers and licensors. The Material may contain trade secrets and proprietary
# and confidential information of Intel Corporation and its suppliers and licensors,
# and is protected by worldwide copyright and trade secret laws and treaty
# provisions. No part of the Material may be used, copied, reproduced, modified,
# published, uploaded, posted, transmitted, distributed, or disclosed in any way
# without Intel's prior express written permission.

# No license under any patent, copyright, trade secret or other intellectual
# property right is granted to or conferred upon you by disclosure or delivery
# of the Materials, either expressly, by implication, inducement, estoppel or
# otherwise. Any license under such intellectual property rights must be express
# and approved by Intel in writing.

# Unless otherwise agreed by Intel in writing, you may not remove or alter this
# notice or any other notice embedded in Materials by Intel or Intel's suppliers
# or licensors in any way.
# @endinternal

#----------------------------------------------------------------------------------------------------
# Project wide defines and flags
#----------------------------------------------------------------------------------------------------


#----------------------------------------------------------------------------------------------------
# Create Safe String Library
#----------------------------------------------------------------------------------------------------
# safe c library requires the compiler path with double quotes. Also, doesn't accept few of the C compiler flags
set(CMAKE_C_FLAGS_SAFEC "-DNO_MSABI_VA_FUNCS -fPIC")

include(ExternalProject)
find_package(Git REQUIRED)

ExternalProject_Add(safeclib_proj
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/safeclib
DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/safeclib
GIT_REPOSITORY https://github.com/rurban/safeclib
GIT_TAG 59eba324c20c07f7ca8190238dd415525f4925dc
UPDATE_COMMAND ""
CONFIGURE_COMMAND ./build-tools/autogen.sh && ./configure CFLAGS=${CMAKE_C_FLAGS_SAFEC} --enable-strmax=0x8000 --enable-shared=no --disable-doc
BUILD_COMMAND make
BUILD_IN_SOURCE ON
STEP_TARGETS build
BUILD_ALWAYS OFF
BUILD_BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/safeclib/src/safeclib_proj/src/.libs/libsafec-3.3.a
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
LOG_UPDATE ON
LOG_BUILD ON
)

ExternalProject_Get_property(safeclib_proj SOURCE_DIR)
add_library(safeclib STATIC IMPORTED)
set_property(TARGET safeclib PROPERTY IMPORTED_LOCATION ${SOURCE_DIR}/src/.libs/libsafec-3.3.a)
add_dependencies(safeclib safeclib_proj)
set(SAFECLIB_COMPILE_FLAGS "-DHAVE_C99")

#----------------------------------------------------------------------------------------------------
# OS driver interface library
#----------------------------------------------------------------------------------------------------

target_link_libraries(ipmctl_os_interface
safeclib
)
target_include_directories(ipmctl_os_interface
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/safeclib/src/safeclib_proj/include)

set_source_files_properties(${OS_INTERFACE_SOURCE_FILES}
PROPERTIES COMPILE_FLAGS ${SAFECLIB_COMPILE_FLAGS})

#----------------------------------------------------------------------------------------------------
# libipmctl
#----------------------------------------------------------------------------------------------------
target_link_libraries(ipmctl
safeclib
)

target_include_directories(ipmctl
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/safeclib/src/safeclib_proj/include)

set_source_files_properties(${LIBIPMCTL_SOURCE_FILES}
PROPERTIES COMPILE_FLAGS ${SAFECLIB_COMPILE_FLAGS})

#---------------------------------------------------------------------------------------------------
# ipmctl executable
#---------------------------------------------------------------------------------------------------
set_source_files_properties(${IPMCTL_SOURCE_FILES}
PROPERTIES COMPILE_FLAGS ${SAFECLIB_COMPILE_FLAGS})

#---------------------------------------------------------------------------------------------------
# Monitor service executable
#---------------------------------------------------------------------------------------------------
set_source_files_properties(${IPMCTL_MONITOR_SOURCE_FILES}
PROPERTIES COMPILE_FLAGS ${SAFECLIB_COMPILE_FLAGS})
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ elseif(UNIX)
find_package(asciidoc)
pkg_check_modules(NDCTL REQUIRED libndctl>=58.2)
pkg_check_modules(SYSTEMD systemd)
if(NOT SAFECLIB_SRC_DOWNLOAD_AND_STATIC_LINK)
pkg_check_modules(LIBSAFEC REQUIRED safec-3.3>=03032018.0-g570fa5)
endif()
elseif(MSVC)
set(WIN_BUILD 1)
set(OS_TYPE win)
Expand Down Expand Up @@ -198,7 +200,7 @@ target_link_libraries(ipmctl_os_interface
${CMAKE_THREAD_LIBS_INIT}
)

if(LNX_BUILD)
if(LNX_BUILD AND (NOT SAFECLIB_SRC_DOWNLOAD_AND_STATIC_LINK))
target_link_libraries(ipmctl_os_interface
${LIBSAFEC_LIBRARIES}
)
Expand Down Expand Up @@ -485,10 +487,17 @@ if (NOT ESX_BUILD)

add_executable(ipmctl-monitor ${IPMCTL_MONITOR_SOURCE_FILES})

if(NOT SAFECLIB_SRC_DOWNLOAD_AND_STATIC_LINK)
target_link_libraries(ipmctl-monitor
ipmctl
${LIBSAFEC_LIBRARIES}
)
else()
target_link_libraries(ipmctl-monitor
ipmctl
)
endif()


target_include_directories(ipmctl-monitor PUBLIC
src/os
Expand Down Expand Up @@ -778,4 +787,6 @@ endif()

if(ESX_BUILD)
include(CMake/esx.cmake)
endif()
elseif(UNIX AND SAFECLIB_SRC_DOWNLOAD_AND_STATIC_LINK)
include(CMake/safeclib.cmake)
endif()
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,22 @@ Ubuntu packages can be found at: https://launchpad.net/~jhli/+archive/ubuntu/ipm

### libsafec


ipmctl requires libsafec as a dependency.


libsafec is availible on Fedora.


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


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


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

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

## Build

Expand Down
2 changes: 2 additions & 0 deletions install/linux/rel-release/ipmctl.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ API for development of Intel Optane DC persistent memory management utilities.
-DCMAKE_INSTALL_SYSCONFDIR=%{_sysconfdir} \
-DINSTALL_UNITDIR=%{_unitdir} \
-DRELEASE=ON \
-DSAFECLIB_SRC_DOWNLOAD_AND_STATIC_LINK=OFF \
-DRPM_BUILD=ON
%else
%cmake -DBUILDNUM=%{version} -DCMAKE_INSTALL_PREFIX=/ \
Expand All @@ -100,6 +101,7 @@ API for development of Intel Optane DC persistent memory management utilities.
-DINSTALL_UNITDIR=%{_unitdir} \
-DRELEASE=ON \
-DRPM_BUILD=ON \
-DSAFECLIB_SRC_DOWNLOAD_AND_STATIC_LINK=OFF \
-DWHITLEY=ON
%endif
%make_build
Expand Down

0 comments on commit a026f5e

Please sign in to comment.