patch 4.0
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
|
||||
macro(ob_define VAR DEFAULT)
|
||||
if (NOT DEFINED ${VAR})
|
||||
set(${VAR} ${DEFAULT})
|
||||
@ -10,26 +11,58 @@ 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})
|
||||
set("${target}_cache_objects_" ${${target}_cache_objects_} PARENT_SCOPE)
|
||||
if (OB_ENABLE_UNITY)
|
||||
set(i 0)
|
||||
set(group_id 0)
|
||||
set(ob_sub_objects "")
|
||||
|
||||
# if need check ob cmake rules
|
||||
if (OB_CMAKE_RULES_CHECK)
|
||||
FOREACH(item ${ARGN})
|
||||
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}")
|
||||
math(EXPR group_id "${group_id} + 1")
|
||||
set(ob_sub_objects "")
|
||||
string(REGEX MATCHALL "^.*\.h$" MATCH_OUTPUT ${item})
|
||||
if(MATCH_OUTPUT)
|
||||
message(FATAL_ERROR "Header files are not allowed in CMakeLists.txt\n")
|
||||
endif()
|
||||
ENDFOREACH(item)
|
||||
if (${i} GREATER 0)
|
||||
set_source_files_properties(${ob_sub_objects} PROPERTIES UNITY_GROUP "${target}_${group}/${group_id}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# diable global unity build
|
||||
if (NOT OB_ENABLE_UNITY)
|
||||
return()
|
||||
endif()
|
||||
|
||||
|
||||
# ALONE group will not join unity build
|
||||
if(group STREQUAL "ALONE")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(i 0)
|
||||
set(group_id 0)
|
||||
set(ob_sub_objects "")
|
||||
FOREACH(item ${ARGN})
|
||||
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}")
|
||||
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}")
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
|
||||
set(unity_after [[
|
||||
@ -38,19 +71,29 @@ set(unity_after [[
|
||||
#endif
|
||||
]])
|
||||
|
||||
function(ob_add_target target)
|
||||
if(ARGC EQUAL 1)
|
||||
add_library(${target} OBJECT "${${target}_cache_objects_}")
|
||||
if (OB_ENABLE_UNITY)
|
||||
set_target_properties(${target} PROPERTIES UNITY_BUILD ON)
|
||||
set_target_properties(${target} PROPERTIES UNITY_BUILD_CODE_AFTER_INCLUDE "${unity_after}")
|
||||
set_target_properties(${target} PROPERTIES UNITY_BUILD_MODE GROUP)
|
||||
endif()
|
||||
else()
|
||||
add_library(${target} OBJECT ${ARGN})
|
||||
function(config_target_unity target)
|
||||
if (OB_ENABLE_UNITY)
|
||||
set_target_properties(${target} PROPERTIES UNITY_BUILD ON)
|
||||
set_target_properties(${target} PROPERTIES UNITY_BUILD_CODE_AFTER_INCLUDE "${unity_after}")
|
||||
set_target_properties(${target} PROPERTIES UNITY_BUILD_MODE GROUP)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(disable_pch target)
|
||||
set_target_properties(${target} PROPERTIES DISABLE_PRECOMPILE_HEADERS ON)
|
||||
function(ob_add_object_target target)
|
||||
add_library(${target} OBJECT "${${target}_cache_objects_}")
|
||||
config_target_unity(${target})
|
||||
endfunction()
|
||||
|
||||
function(ob_lib_add_target target)
|
||||
message(STATUS "ob_lib_add_target ${target}")
|
||||
ob_add_object_target(${target})
|
||||
target_link_libraries(${target} PUBLIC oblib_base)
|
||||
list(APPEND oblib_object_libraries ${target})
|
||||
set(oblib_object_libraries "${oblib_object_libraries}" CACHE INTERNAL "observer library list")
|
||||
endfunction()
|
||||
|
||||
function(ob_add_new_object_target target_name target_objects_list)
|
||||
message(STATUS "ob_add_new_object_target ${target_name}")
|
||||
add_library(${target_name} OBJECT EXCLUDE_FROM_ALL "${${target_objects_list}_cache_objects_}")
|
||||
config_target_unity(${target_name})
|
||||
endfunction()
|
||||
|
||||
Reference in New Issue
Block a user