From 3dc608da22aaf4ef872e25e508fe2450d81f1748 Mon Sep 17 00:00:00 2001 From: fancy <258828110.@qq.com> Date: Thu, 26 Oct 2023 08:03:52 -0700 Subject: [PATCH] Improve config lib. --- utils/Config/CMakeLists.txt | 16 +++++++++++++++- utils/Config/config.cmake | 13 +++++++++++++ utils/Config/src/ConfigCode.h | 7 +++++-- utils/Config/src/ConfigImpl.h | 7 +++++-- 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 utils/Config/config.cmake diff --git a/utils/Config/CMakeLists.txt b/utils/Config/CMakeLists.txt index 31fd5ea..ea39c9e 100644 --- a/utils/Config/CMakeLists.txt +++ b/utils/Config/CMakeLists.txt @@ -63,4 +63,18 @@ add_custom_target( # WORKING_DIRECTORY ${PROJECT_ROOT_PATH}/cmake-shell # ) -define_file_name(${TARGET_NAME}) \ No newline at end of file +function(config_owner target) + get_target_property(source_files "${target}" SOURCES) + foreach(source_file ${source_files}) + get_property(defs SOURCE "${source_file}" + PROPERTY COMPILE_DEFINITIONS) + get_filename_component(file_name "${source_file}" NAME) + list(APPEND defs "CONFIG_OWNER") + set_property( + SOURCE "${source_file}" + PROPERTY COMPILE_DEFINITIONS ${defs}) + endforeach() +endfunction() + +define_file_name(${TARGET_NAME}) +config_owner(${TARGET_NAME}) \ No newline at end of file diff --git a/utils/Config/config.cmake b/utils/Config/config.cmake new file mode 100644 index 0000000..1f8d44d --- /dev/null +++ b/utils/Config/config.cmake @@ -0,0 +1,13 @@ + +function(config_owner target) + get_target_property(source_files "${target}" SOURCES) + foreach(source_file ${source_files}) + get_property(defs SOURCE "${source_file}" + PROPERTY COMPILE_DEFINITIONS) + get_filename_component(file_name "${source_file}" NAME) + list(APPEND defs "CONFIG_OWNER") + set_property( + SOURCE "${source_file}" + PROPERTY COMPILE_DEFINITIONS ${defs}) + endforeach() +endfunction() \ No newline at end of file diff --git a/utils/Config/src/ConfigCode.h b/utils/Config/src/ConfigCode.h index 4ce6510..947cc5c 100644 --- a/utils/Config/src/ConfigCode.h +++ b/utils/Config/src/ConfigCode.h @@ -3,9 +3,9 @@ * 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. @@ -18,6 +18,9 @@ #ifdef __cplusplus extern "C" { +#endif +#ifndef CONFIG_OWNER +#error This is internal file, never include it. #endif const StatusCode CreateConfigCode(const long int code); #ifdef __cplusplus diff --git a/utils/Config/src/ConfigImpl.h b/utils/Config/src/ConfigImpl.h index 871aa22..c18ded8 100644 --- a/utils/Config/src/ConfigImpl.h +++ b/utils/Config/src/ConfigImpl.h @@ -3,9 +3,9 @@ * 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. @@ -19,6 +19,9 @@ #ifdef __cplusplus extern "C" { +#endif +#ifndef CONFIG_OWNER +#error This is internal file, never include it. #endif typedef struct config Config; typedef struct config