[FEAT MERGE] 开源裁减颗粒度优化

Co-authored-by: nroskill <nroskill@gmail.com>
Co-authored-by: akaError <lzg020616@163.com>
Co-authored-by: yinyj17 <yinyijun92@gmail.com>
This commit is contained in:
wenxingsen
2023-08-15 02:40:25 +00:00
committed by ob-robot
parent a31e422133
commit 9b31f8aa03
378 changed files with 26718 additions and 2379 deletions

View File

@ -1,3 +1,6 @@
if(NOT OB_BUILD_OPENSOURCE)
include(cmake/Err.cmake)
endif()
macro(ob_define VAR DEFAULT)
if (NOT DEFINED ${VAR})
@ -11,27 +14,26 @@ function(ob_replace_in_file INFILE OUTFILE MATCH-STRING REPLACE-STRING)
file(WRITE ${OUTFILE} ${NEW-CONTENT})
endfunction()
# ob_set_subtarget usage demo
# ob_set_subtarget(ob_sql common
# sql1.cpp
# sql2.cpp
# sql3.cpp
# )
# ob_set_subtarget(ob_sql executor
# executor/ob_executor1.cpp
# executor/ob_executor2.cpp
# executor/ob_executor3.cpp
# )
function(ob_set_subtarget target group)
list(APPEND "${target}_cache_objects_" ${ARGN})
list(LENGTH ${target}_cache_objects_ CCLS_TARGET_CURRENT_LENGTH)
# 需要参与编译的源文件列表
set(ARGN_NEED_LIST "")
FOREACH(item ${ARGN})
list(APPEND ARGN_NEED_LIST ${item})
ENDFOREACH(item)
list(APPEND "${target}_cache_objects_" ${ARGN_NEED_LIST})
set("${target}_cache_objects_" ${${target}_cache_objects_} PARENT_SCOPE)
# if need check ob cmake rules
if (OB_CMAKE_RULES_CHECK)
FOREACH(item ${ARGN})
FOREACH(item ${ARGN_NEED_LIST})
# [E1001] Header files are not allowed in CMakeLists.txt
string(REGEX MATCHALL "^.*\.h$" MATCH_OUTPUT ${item})
if(MATCH_OUTPUT)
message(FATAL_ERROR "Header files are not allowed in CMakeLists.txt\n")
message(FATAL_ERROR "\n${E1001}\n不允许把头文件${item}写到CMakeLists.txt文件中\n")
endif()
ENDFOREACH(item)
endif()
@ -41,30 +43,55 @@ function(ob_set_subtarget target group)
return()
endif()
# ALONE group will not join unity build
if(group STREQUAL "ALONE")
return()
endif()
set(i 0)
set(group_id 0)
if (NOT OB_BUILD_CCLS)
set(i 0)
set(group_id 0)
else()
# ccls构建,将更改分组方法,是以target为单位,而不是以group为单元
set(i ${CCLS_TARGET_CURRENT_LENGTH})
math(EXPR group_id "(${i} / ${OB_MAX_UNITY_BATCH_SIZE})")
endif()
set(ob_sub_objects "")
FOREACH(item ${ARGN})
FOREACH(item ${ARGN_NEED_LIST})
math(EXPR i "(${i} + 1) % ${OB_MAX_UNITY_BATCH_SIZE}")
list(APPEND ob_sub_objects ${item})
if (${i} EQUAL 0)
set_source_files_properties(${ob_sub_objects} PROPERTIES UNITY_GROUP "${target}_${group}/${group_id}")
if (NOT OB_BUILD_CCLS)
set_source_files_properties(${ob_sub_objects} PROPERTIES UNITY_GROUP "${target}_${group}/${group_id}")
else()
set_source_files_properties(${ob_sub_objects} PROPERTIES UNITY_GROUP "${target}/${group_id}")
endif()
math(EXPR group_id "${group_id} + 1")
set(ob_sub_objects "")
endif()
ENDFOREACH(item)
if (${i} GREATER 0)
set_source_files_properties(${ob_sub_objects} PROPERTIES UNITY_GROUP "${target}_${group}/${group_id}")
if (NOT OB_BUILD_CCLS)
set_source_files_properties(${ob_sub_objects} PROPERTIES UNITY_GROUP "${target}_${group}/${group_id}")
else()
set_source_files_properties(${ob_sub_objects} PROPERTIES UNITY_GROUP "${target}/${group_id}")
endif()
endif()
endfunction()
function (check_need_build_unity_target target need_build)
list(LENGTH ${target}_cache_objects_ TARGET_LENGTH)
if (TARGET_LENGTH EQUAL 0)
set(${need_build} FALSE PARENT_SCOPE)
else()
set(${need_build} TRUE PARENT_SCOPE)
endif()
endfunction()
set(unity_after [[
#ifdef USING_LOG_PREFIX
#undef USING_LOG_PREFIX