From: Dariusz Michaluk Date: Wed, 17 Jun 2020 13:35:24 +0000 (+0200) Subject: Rewrite cmake infrastructure X-Git-Tag: submit/tizen/20200728.071123~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1b4e24a5cf70e4a3cc8668f624f1f62954984377;p=platform%2Fcore%2Fsecurity%2Fdevice-certificate-manager-backend.git Rewrite cmake infrastructure Change-Id: Ibdf64b63560abf5b693e26b8e5d9dfe3ae3ec260 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c3af93..93e5048 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2017 - 2019 Samsung Electronics Co., Ltd All Rights Reserved +# Copyright (c) 2017 - 2020 Samsung Electronics Co., Ltd All Rights Reserved # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,14 +17,10 @@ # @author Jaroslaw Pelczar # -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - -IF(POLICY CMP0048) - CMAKE_POLICY(SET CMP0048 NEW) -ENDIF() +CMAKE_MINIMUM_REQUIRED(VERSION 3.0) INCLUDE(GNUInstallDirs) -INCLUDE(cmake/CheckFrameworks.cmake) +INCLUDE(CheckLibraryExists) IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "RELEASE") @@ -42,6 +38,10 @@ ADD_DEFINITIONS("-Wextra") SET(CMAKE_POSITION_INDEPENDENT_CODE "True") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) - -ADD_SUBDIRECTORY(src) +IF(DCM_BACKEND_TYPE STREQUAL "dummy") + ADD_SUBDIRECTORY(src/dummy-backend) +ELSEIF(DCM_BACKEND_TYPE STREQUAL "kse") + ADD_SUBDIRECTORY(src/kse-backend) +ELSE() + ADD_SUBDIRECTORY(src/dummy-backend) +ENDIF() diff --git a/cmake/CheckFrameworks.cmake b/cmake/CheckFrameworks.cmake deleted file mode 100644 index e6827e6..0000000 --- a/cmake/CheckFrameworks.cmake +++ /dev/null @@ -1,45 +0,0 @@ -INCLUDE(CheckIncludeFile) -INCLUDE(CheckIncludeFileCXX) -INCLUDE(CheckLibraryExists) -INCLUDE(CheckFunctionExists) -INCLUDE(CheckIncludeFiles) - -FIND_PACKAGE(PkgConfig REQUIRED) - -PKG_CHECK_MODULES(DLOG REQUIRED dlog) - -#### Find mbedtls #### - -find_library(MBEDTLS_LIB - mbedtls) - -find_library(MBEDCRYPTO_LIB - mbedcrypto) - -find_library(MBEDX509_LIB - mbedx509) - -IF(MBEDTLS_LIB-NOTFOUND) - message(FATAL_ERROR "mbedtls not found ...") -ENDIF() - -IF(MBEDCRYPTO_LIB-NOTFOUND) - message(FATAL_ERROR "mbedcrypto not found ...") -ENDIF() - -IF(MBEDX509_LIB-NOTFOUND) - message(FATAL_ERROR "mbedx509 not found ...") -ENDIF() - -CHECK_INCLUDE_FILES("mbedtls/rsa.h;mbedtls/ecdsa.h" MBEDTLS_HEADERS_OK) - -IF(NOT MBEDTLS_HEADERS_OK) - message(FATAL_ERROR "No mbedtls headers") -ENDIF() - -#### Find dcm-backend-api.h header #### - -FIND_FILE(DCM_BACKEND_API_H device-certificate-manager-backend/dcm-backend-api.h) -IF(NOT DCM_BACKEND_API_H) - message(FATAL_ERROR "No dcm-backend-api.h") -ENDIF() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 55b7557..0000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# -# DCM backends build script -# Jaroslaw Pelczar -# - -###### Setup include paths and library directories ####### - -include_directories(${DLOG_INCLUDE_DIRS}) -link_directories(${DLOG_LIBRARY_DIRS}) - -include_directories(${Boost_INCLUDE_DIRS}) -include_directories(device-certificate-manager) -link_directories(${Boost_LIBRARY_DIRS}) - -include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) - -###### Crypto Backends ####### - -ADD_DEFINITIONS(-DDCM_BACKEND) - -IF(DCM_BACKEND_TYPE STREQUAL "dummy") - add_subdirectory(dummy-backend) -ELSEIF(DCM_BACKEND_TYPE STREQUAL "kse") - add_subdirectory(kse-backend) -ELSE() - add_subdirectory(dummy-backend) -ENDIF() diff --git a/src/dummy-backend/CMakeLists.txt b/src/dummy-backend/CMakeLists.txt index 8b1f3c9..220cdff 100644 --- a/src/dummy-backend/CMakeLists.txt +++ b/src/dummy-backend/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2017 - 2019 Samsung Electronics Co., Ltd All Rights Reserved +# Copyright (c) 2017 - 2020 Samsung Electronics Co., Ltd All Rights Reserved # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,92 +17,76 @@ # @author Jaroslaw Pelczar # -find_program(OPENSSL_TOOL openssl) +FIND_PROGRAM(OPENSSL_TOOL openssl REQUIRED) +FIND_PACKAGE(PkgConfig REQUIRED) +FIND_LIBRARY(MBEDTLS_LIB mbedtls) +FIND_LIBRARY(MBEDCRYPTO_LIB mbedcrypto) -IF(NOT OPENSSL_TOOL) - MESSAGE(FATAL_ERROR "openssl required to build dummy CA") -ENDIF() +ADD_EXECUTABLE(bin2c bin2c.c) -add_executable(helper_bin2c bin2c.c) - -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootCA.key +ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootCA.key COMMAND ${OPENSSL_TOOL} genrsa -out ${CMAKE_CURRENT_BINARY_DIR}/rootCA.key 1024) -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootCA.pem +ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootCA.pem COMMAND ${OPENSSL_TOOL} req -x509 -new -nodes -key ${CMAKE_CURRENT_BINARY_DIR}/rootCA.key -sha256 -days 1024 -out ${CMAKE_CURRENT_BINARY_DIR}/rootCA.pem -subj "/C=PL/ST=Test1/L=Test2/O=Dis/CN=www.example.com" - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/rootCA.key) + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/rootCA.key) -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.key +ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.key COMMAND ${OPENSSL_TOOL} ecparam -name secp521r1 -genkey -noout -out ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.key) -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.pem +ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.pem COMMAND ${OPENSSL_TOOL} req -x509 -new -nodes -key ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.key -sha256 -days 1024 -out ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.pem -subj "/C=PL/ST=Test1/L=Test2/O=Dis/CN=www.example.com" - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.key) - -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootCA_rsa_key.c - COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/rootCA.key ${CMAKE_CURRENT_BINARY_DIR}/rootCA_rsa_key.c dummy_rootca_rsa_key - DEPENDS helper_bin2c ${CMAKE_CURRENT_BINARY_DIR}/rootCA.key) - -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootCA_rsa_cert.c - COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/rootCA.pem ${CMAKE_CURRENT_BINARY_DIR}/rootCA_rsa_cert.c dummy_rootca_rsa_cert - DEPENDS helper_bin2c ${CMAKE_CURRENT_BINARY_DIR}/rootCA.pem) + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.key) -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_key.c - COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.key ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_key.c dummy_rootca_ecdsa_key - DEPENDS helper_bin2c ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.key) +ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootCA_rsa_key.c + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/rootCA.key ${CMAKE_CURRENT_BINARY_DIR}/rootCA_rsa_key.c dummy_rootca_rsa_key + DEPENDS bin2c ${CMAKE_CURRENT_BINARY_DIR}/rootCA.key) -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_cert.c - COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.pem ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_cert.c dummy_rootca_ecdsa_cert - DEPENDS helper_bin2c ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.pem) +ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootCA_rsa_cert.c + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/rootCA.pem ${CMAKE_CURRENT_BINARY_DIR}/rootCA_rsa_cert.c dummy_rootca_rsa_cert + DEPENDS bin2c ${CMAKE_CURRENT_BINARY_DIR}/rootCA.pem) -###### Include and library directories ###### +ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_key.c + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.key ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_key.c dummy_rootca_ecdsa_key + DEPENDS bin2c ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.key) -include_directories(${DLOG_INCLUDE_DIRS}) -link_directories(${DLOG_LIBRARY_DIRS}) +ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_cert.c + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.pem ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_cert.c dummy_rootca_ecdsa_cert + DEPENDS bin2c ${CMAKE_CURRENT_BINARY_DIR}/rootECDSA.pem) -include_directories(${Boost_INCLUDE_DIRS}) -link_directories(${Boost_LIBRARY_DIRS}) +PKG_CHECK_MODULES(DUMMY_DEPS REQUIRED dlog device-certificate-manager-backend) +INCLUDE_DIRECTORIES(SYSTEM ${DUMMY_DEPS_INCLUDE_DIRS}) +LINK_DIRECTORIES(${DUMMY_DEPS_LIBRARY_DIRS}) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) +INCLUDE_DIRECTORIES(../shared) -###### Library sources ###### - -add_library(${DCM_BACKEND_API} +ADD_LIBRARY(${DCM_BACKEND_API} SHARED dcm-backend-api-dummy.cpp dummycryptobackendcontext.cpp - ../log.cpp + ../shared/log.cpp ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_key.c ${CMAKE_CURRENT_BINARY_DIR}/rootCA_ecdsa_cert.c ${CMAKE_CURRENT_BINARY_DIR}/rootCA_rsa_key.c - ${CMAKE_CURRENT_BINARY_DIR}/rootCA_rsa_cert.c -) + ${CMAKE_CURRENT_BINARY_DIR}/rootCA_rsa_cert.c) -###### Linking ###### -target_link_libraries(${DCM_BACKEND_API} - ${Boost_SYSTEM_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} +TARGET_LINK_LIBRARIES(${DCM_BACKEND_API} ${MBEDTLS_LIB} ${MBEDCRYPTO_LIB} - ${DLOG_LIBRARIES} -) - -###### Properties of library ###### - -set_property(TARGET ${DCM_BACKEND_API} PROPERTY DEFINE_SYMBOL DCM_BACKEND_API_DUMMY_EXPORT) -set_property(TARGET ${DCM_BACKEND_API} PROPERTY VISIBILITY_INLINES_HIDDEN TRUE) -set_property(TARGET ${DCM_BACKEND_API} PROPERTY VERSION 1.0) -set_property(TARGET ${DCM_BACKEND_API} PROPERTY C_VISIBILITY_PRESET hidden) -set_property(TARGET ${DCM_BACKEND_API} PROPERTY CXX_VISIBILITY_PRESET hidden) + ${DUMMY_DEPS_LIBRARIES}) -###### Installation ###### +SET_TARGET_PROPERTIES(${DCM_BACKEND_API} + PROPERTIES + VERSION 1.0 + DEFINE_SYMBOL DCM_BACKEND_API_DUMMY_EXPORT + VISIBILITY_INLINES_HIDDEN TRUE + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden) -install(TARGETS - ${DCM_BACKEND_API} +INSTALL(TARGETS ${DCM_BACKEND_API} LIBRARY DESTINATION - ${CMAKE_INSTALL_LIBDIR} -) + ${CMAKE_INSTALL_LIBDIR}) diff --git a/src/kse-backend/CMakeLists.txt b/src/kse-backend/CMakeLists.txt index 59a027a..3d2a67a 100644 --- a/src/kse-backend/CMakeLists.txt +++ b/src/kse-backend/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +# Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,50 +16,37 @@ # @author Pawel Kowalski # -###### Include and library directories ###### +FIND_PACKAGE(PkgConfig REQUIRED) +FIND_LIBRARY(MBEDTLS_LIB mbedtls) -include_directories(${DLOG_INCLUDE_DIRS}) -link_directories(${DLOG_LIBRARY_DIRS}) +PKG_CHECK_MODULES(KSE_DEPS REQUIRED dlog device-certificate-manager-backend) +INCLUDE_DIRECTORIES(SYSTEM ${KSE_DEPS_INCLUDE_DIRS}) +LINK_DIRECTORIES(${KSE_DEPS_LIBRARY_DIRS}) -include_directories(${Boost_INCLUDE_DIRS}) -link_directories(${Boost_LIBRARY_DIRS}) +INCLUDE_DIRECTORIES(../shared) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -###### Library sources ###### - -add_library(${DCM_BACKEND_API} +ADD_LIBRARY(${DCM_BACKEND_API} SHARED dcm-backend-api-kse.cpp soresolver.cpp ksebackend.cpp ksebackendcontext.cpp - ../log.cpp -) + ../shared/log.cpp) -###### Linking ###### -target_link_libraries(${DCM_BACKEND_API} - ${Boost_SYSTEM_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} +TARGET_LINK_LIBRARIES(${DCM_BACKEND_API} ${MBEDTLS_LIB} - ${MBEDCRYPTO_LIB} - ${DLOG_LIBRARIES} -) - -###### Properties of library ###### - -set_property(TARGET ${DCM_BACKEND_API} PROPERTY DEFINE_SYMBOL DCM_BACKEND_API_SEE_EXPORT) -set_property(TARGET ${DCM_BACKEND_API} PROPERTY VISIBILITY_INLINES_HIDDEN TRUE) -set_property(TARGET ${DCM_BACKEND_API} PROPERTY VERSION 1.0) -set_property(TARGET ${DCM_BACKEND_API} PROPERTY C_VISIBILITY_PRESET hidden) -set_property(TARGET ${DCM_BACKEND_API} PROPERTY CXX_VISIBILITY_PRESET hidden) + ${KSE_DEPS_LIBRARIES}) -###### Installation ###### +SET_TARGET_PROPERTIES(${DCM_BACKEND_API} + PROPERTIES + VERSION 1.0 + DEFINE_SYMBOL DCM_BACKEND_API_SEE_EXPORT + VISIBILITY_INLINES_HIDDEN TRUE + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden) -install(TARGETS - ${DCM_BACKEND_API} +INSTALL(TARGETS ${DCM_BACKEND_API} LIBRARY DESTINATION - ${CMAKE_INSTALL_LIBDIR} -) + ${CMAKE_INSTALL_LIBDIR}) ADD_SUBDIRECTORY(tools) diff --git a/src/kse-backend/tools/CMakeLists.txt b/src/kse-backend/tools/CMakeLists.txt index 5f12f6e..d33ce32 100644 --- a/src/kse-backend/tools/CMakeLists.txt +++ b/src/kse-backend/tools/CMakeLists.txt @@ -1,22 +1,36 @@ -####################################################################################### -# For SE_KONAI +# Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# @file src/kse-backend/CMakeLists.txt +# @author Pawel Kowalski +# -include_directories(${Boost_INCLUDE_DIRS}) -link_directories(${Boost_LIBRARY_DIRS}) +FIND_PACKAGE(PkgConfig REQUIRED) -include_directories(../src ../src/kse-backend) +PKG_CHECK_MODULES(TOOL_DEPS REQUIRED dlog) +INCLUDE_DIRECTORIES(SYSTEM ${TOOL_DEPS_INCLUDE_DIRS}) +LINK_DIRECTORIES(${TOOL_DEPS_LIBRARY_DIRS}) -add_executable(dcm_konaise_tool +INCLUDE_DIRECTORIES(../ ../../shared) + +SET(TARGET_TOOL "dcm_konaise_tool") +ADD_EXECUTABLE(${TARGET_TOOL} + konaise_tool.cpp ../soresolver.cpp - ../../log.cpp - konaise_tool.cpp) + ../../shared/log.cpp) -target_link_libraries(dcm_konaise_tool - ${Boost_SYSTEM_LIBRARY} - dl - ${CMAKE_THREAD_LIBS_INIT} - ${DLOG_LIBRARIES} -) +TARGET_LINK_LIBRARIES(${TARGET_TOOL} ${TOOL_DEPS_LIBRARIES} dl) -install(TARGETS dcm_konaise_tool RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -####################################################################################### +INSTALL(TARGETS ${TARGET_TOOL} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/log.cpp b/src/log.cpp deleted file mode 100644 index baef423..0000000 --- a/src/log.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************** - * - * Copyright 2020 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ - -#include -#include - -#ifdef NDEBUG -int __log_level = LOG_ERR; -#else -int __log_level = LOG_DEBUG; -#endif - -#define DCM_LOG_TAG "DEVICE_CERTIFICATE_MANAGER_BACKEND" - -void dcm_print(int priority, char const *fmt, ...) -{ - log_priority dlog_prio; - - switch (priority) { - case LOG_EMERG: - dlog_prio = DLOG_FATAL; - break; - case LOG_ERR: - dlog_prio = DLOG_ERROR; - break; - case LOG_WARNING: - dlog_prio = DLOG_WARN; - break; - case LOG_INFO: - dlog_prio = DLOG_INFO; - break; - case LOG_DEBUG: - dlog_prio = DLOG_DEBUG; - break; - default: - dlog_prio = DLOG_DEFAULT; - } - - va_list ap; - va_start(ap, fmt); - (void) vprint_system_log(dlog_prio, DCM_LOG_TAG, fmt, ap); - va_end(ap); -} diff --git a/src/log.h b/src/log.h deleted file mode 100644 index f479e31..0000000 --- a/src/log.h +++ /dev/null @@ -1,70 +0,0 @@ -/****************************************************************** - * - * Copyright 2020 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ -#ifndef SHARED_LOG_H_ -#define SHARED_LOG_H_ - -#include -#include -#include - -#define UNUSED __attribute__((unused)) - -extern int __log_level; -extern void dcm_print(int priority, char const *fmt, ...); - -namespace { - template - void UNUSED __LOG_FUN(int level, const std::stringstream &format, Args&&... args) { - dcm_print(level, format.str().c_str(), std::forward(args)...); - } - - template <> - void UNUSED __LOG_FUN(int level, const std::stringstream &format) { - dcm_print(level, "%s", format.str().c_str()); - } - - template - void UNUSED __LOG_FUN(int level, const char *format, Args&&... args) { - dcm_print(level, format, std::forward(args)...); - } - - template <> - void UNUSED __LOG_FUN(int level, const char *format) { - dcm_print(level, "%s", format); - } - -} // namespace anonymous - -#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) - -#define __LOG(LEVEL, FORMAT, ...) \ - do { \ - if (LEVEL <= __log_level) { \ - std::stringstream __LOG_FORMAT; \ - __LOG_FORMAT << __FILENAME__ << ": " << __func__ << "(" << __LINE__ << ") > " << FORMAT; \ - __LOG_FUN(LEVEL, __LOG_FORMAT, ##__VA_ARGS__); \ - } \ - } while (0) - -#define LOGM(...) __LOG(LOG_EMERG, __VA_ARGS__) /* system is unusable */ -#define LOGE(...) __LOG(LOG_ERR, __VA_ARGS__) /* error conditions */ -#define LOGW(...) __LOG(LOG_WARNING, __VA_ARGS__) /* warning conditions */ -#define LOGI(...) __LOG(LOG_INFO, __VA_ARGS__) /* informational */ -#define LOGD(...) __LOG(LOG_DEBUG, __VA_ARGS__) /* debug-level messages */ - -#endif /* SHARED_LOG_H_ */ diff --git a/src/shared/log.cpp b/src/shared/log.cpp new file mode 100644 index 0000000..baef423 --- /dev/null +++ b/src/shared/log.cpp @@ -0,0 +1,58 @@ +/****************************************************************** + * + * Copyright 2020 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include +#include + +#ifdef NDEBUG +int __log_level = LOG_ERR; +#else +int __log_level = LOG_DEBUG; +#endif + +#define DCM_LOG_TAG "DEVICE_CERTIFICATE_MANAGER_BACKEND" + +void dcm_print(int priority, char const *fmt, ...) +{ + log_priority dlog_prio; + + switch (priority) { + case LOG_EMERG: + dlog_prio = DLOG_FATAL; + break; + case LOG_ERR: + dlog_prio = DLOG_ERROR; + break; + case LOG_WARNING: + dlog_prio = DLOG_WARN; + break; + case LOG_INFO: + dlog_prio = DLOG_INFO; + break; + case LOG_DEBUG: + dlog_prio = DLOG_DEBUG; + break; + default: + dlog_prio = DLOG_DEFAULT; + } + + va_list ap; + va_start(ap, fmt); + (void) vprint_system_log(dlog_prio, DCM_LOG_TAG, fmt, ap); + va_end(ap); +} diff --git a/src/shared/log.h b/src/shared/log.h new file mode 100644 index 0000000..f479e31 --- /dev/null +++ b/src/shared/log.h @@ -0,0 +1,70 @@ +/****************************************************************** + * + * Copyright 2020 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +#ifndef SHARED_LOG_H_ +#define SHARED_LOG_H_ + +#include +#include +#include + +#define UNUSED __attribute__((unused)) + +extern int __log_level; +extern void dcm_print(int priority, char const *fmt, ...); + +namespace { + template + void UNUSED __LOG_FUN(int level, const std::stringstream &format, Args&&... args) { + dcm_print(level, format.str().c_str(), std::forward(args)...); + } + + template <> + void UNUSED __LOG_FUN(int level, const std::stringstream &format) { + dcm_print(level, "%s", format.str().c_str()); + } + + template + void UNUSED __LOG_FUN(int level, const char *format, Args&&... args) { + dcm_print(level, format, std::forward(args)...); + } + + template <> + void UNUSED __LOG_FUN(int level, const char *format) { + dcm_print(level, "%s", format); + } + +} // namespace anonymous + +#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) + +#define __LOG(LEVEL, FORMAT, ...) \ + do { \ + if (LEVEL <= __log_level) { \ + std::stringstream __LOG_FORMAT; \ + __LOG_FORMAT << __FILENAME__ << ": " << __func__ << "(" << __LINE__ << ") > " << FORMAT; \ + __LOG_FUN(LEVEL, __LOG_FORMAT, ##__VA_ARGS__); \ + } \ + } while (0) + +#define LOGM(...) __LOG(LOG_EMERG, __VA_ARGS__) /* system is unusable */ +#define LOGE(...) __LOG(LOG_ERR, __VA_ARGS__) /* error conditions */ +#define LOGW(...) __LOG(LOG_WARNING, __VA_ARGS__) /* warning conditions */ +#define LOGI(...) __LOG(LOG_INFO, __VA_ARGS__) /* informational */ +#define LOGD(...) __LOG(LOG_DEBUG, __VA_ARGS__) /* debug-level messages */ + +#endif /* SHARED_LOG_H_ */