赞
踩
自动生成 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版本
- # home.zhenliang@gmail.com
- # auto unity build
-
- import os
- import sys
-
- def walk(path) :
- for filename in os.listdir(path) :
- abspath = path + '\\\\' + filename
- if os.path.isdir(abspath) :
- walk(abspath)
- elif filename.endswith('.cpp') and filename != 'unity_build.cpp' :
- print '#include "' + abspath[2:] + '"'
-
- sys.stdout = open('./unity_build.cpp', 'w')
- walk(os.curdir)
- #该片段来自于http://outofmemory.cn
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。