当前位置:   article > 正文

自动构建 Unity Build 编译方式的 CMake 脚本_build_unity_support

build_unity_support

自动生成 unity_build.cpp 并构建 Unity Build 编译方式 ,提高编译速度。 

# author: home.zhenliang@gmail.com 
# purpose: 自动构建 Unity Build 编译方式的 CMake 脚本

# 描述:自动构建 Unity Build 编译方式
#
# 用例:
# file(GLOB SOURCE_FILES ${PROJECT_SOURCE_DIR}/*.cpp)
# set_unity_build(SOURCE_FILES true)
#
# 作用:自动生成 unity_build.cpp 并构建 Unity Build 编译方式 ,提高编译速度。

macro(set_unity_build filesVarName enable)

 set(PROJECT_SOURCES ${${filesVarName}}) 
 foreach(filename ${PROJECT_SOURCES})
 set_property(SOURCE ${filename} PROPERTY HEADER_FILE_ONLY ${enable})
 endforeach(filename ${PROJECT_SOURCES})

 set(UNITY_BUILD_FILE ${PROJECT_SOURCE_DIR}/unity_build.cpp) 
 if (${enable})
 file(WRITE ${UNITY_BUILD_FILE}"// unity_build.cppnn")
 foreach(filename ${PROJECT_SOURCES})
 if (NOT filename MATCHES"unity_build.cpp")
 file(APPEND ${UNITY_BUILD_FILE}"#include ""${filename}""n")
 endif(NOT filename MATCHES"unity_build.cpp")
 endforeach(filename ${PROJECT_SOURCES})
 set_property(SOURCE ${UNITY_BUILD_FILE} PROPERTY HEADER_FILE_ONLY FALSE)
 else (${enable})
 file(APPEND ${UNITY_BUILD_FILE}"")
 set_property(SOURCE ${UNITY_BUILD_FILE} PROPERTY HEADER_FILE_ONLY TRUE) 
endif(${enable})

 list(APPEND ${filesVarName} ${UNITY_BUILD_FILE})

endmacro(set_unity_build filesVarName enable)
python版本
  1. # home.zhenliang@gmail.com
  2. # auto unity build
  3. import os
  4. import sys
  5. def walk(path) :
  6. for filename in os.listdir(path) :
  7. abspath = path + '\\\\' + filename
  8. if os.path.isdir(abspath) :
  9. walk(abspath)
  10. elif filename.endswith('.cpp') and filename != 'unity_build.cpp' :
  11. print '#include "' + abspath[2:] + '"'
  12. sys.stdout = open('./unity_build.cpp', 'w')
  13. walk(os.curdir)
  14. #该片段来自于http://outofmemory.cn

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/112029
推荐阅读
相关标签
  

闽ICP备14008679号