Utils.cmake 1.8 KB
Newer Older
O
oceanbase-admin 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
macro(ob_define VAR DEFAULT)
  if (NOT DEFINED ${VAR})
    set(${VAR} ${DEFAULT})
  endif()
endmacro()

function(ob_replace_in_file INFILE OUTFILE MATCH-STRING REPLACE-STRING)
  file(READ ${INFILE} CONTENT)
  string(REPLACE ${MATCH-STRING} ${REPLACE-STRING} NEW-CONTENT ${CONTENT})
  file(WRITE ${OUTFILE} ${NEW-CONTENT})
endfunction()

function(ob_set_subtarget target group)
  list(APPEND "${target}_cache_objects_" ${ARGN})
  set("${target}_cache_objects_" ${${target}_cache_objects_} PARENT_SCOPE)
16
  if (OB_ENABLE_UNITY)
O
oceanbase-admin 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    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()
  endif()
endfunction()

set(unity_after [[
#ifdef USING_LOG_PREFIX
#undef USING_LOG_PREFIX
#endif
]])

function(ob_add_target target)
  if(ARGC EQUAL 1)
    add_library(${target} OBJECT "${${target}_cache_objects_}")
44
    if (OB_ENABLE_UNITY)
O
oceanbase-admin 已提交
45 46 47 48 49 50 51 52 53 54 55 56
      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})
  endif()
endfunction()

function(disable_pch target)
  set_target_properties(${target} PROPERTIES DISABLE_PRECOMPILE_HEADERS ON)
endfunction()