Skip to content

Instantly share code, notes, and snippets.

@pboyer
Forked from floooh/CMakeLists.txt
Last active June 21, 2018 18:04
Show Gist options
  • Save pboyer/a82dab7014176ee6e12e89b455d0f5ff to your computer and use it in GitHub Desktop.
Save pboyer/a82dab7014176ee6e12e89b455d0f5ff to your computer and use it in GitHub Desktop.
copy asset files as fips code-gen job
# a code-gen job must be added to the application's CMakeLists.txt through a call to fips_generate()
fips_begin_app(dragons windowed)
fips_src(.)
fips_generate(FROM files.yml TYPE filecopy OUT_OF_SOURCE ARGS "{ deploy_dir: \"${FIPS_PROJECT_DEPLOY_DIR}\" }")
# REMOVE THIS: n3h5_files(files.yml)
fips_deps(emsctest)
fips_end_app()
'''
A generic file-copy asset job, goes to fips-generators
in your project directory.
'''
Version = 1
import genutil as util
import subprocess
import shutil
import yaml
import os
import platform
#-------------------------------------------------------------------------------
def copy_files(src_dir, dst_dir, yml):
for filename in yml['files']:
src = src_dir + filename
dst = dst_dir + filename
if not os.path.exists(os.path.dirname(dst)):
os.makedirs(os.path.dirname(dst))
shutil.copyfile(src, dst)
#-------------------------------------------------------------------------------
def gen_header(out_hdr, yml):
with open(out_hdr, 'w') as f:
f.write('#pragma once\n')
f.write('//------------------------------------------------------------------------------\n')
f.write('// #version:{}#\n'.format(Version))
f.write('// machine generated, do not edit!\n')
f.write('//------------------------------------------------------------------------------\n')
f.write('// JUST A DUMMY FILE, NOTHING TO SEE HERE\n')
#-------------------------------------------------------------------------------
def check_dirty(src_root_path, input, out_hdr, yml):
out_files = [out_hdr]
in_files = [input]
for filename in yml['files']:
in_files.append(os.path.abspath(src_root_path + filename))
return util.isDirty(Version, in_files, out_files)
#-------------------------------------------------------------------------------
def generate(input, out_src, out_hdr, args):
with open(input, 'r') as f:
try:
yml = yaml.load(f)
except yaml.YAMLError, exc:
# show a proper error if YAML parsing fails
util.setErrorLocation(exc.problem_mark.name, exc.problem_mark.line-1)
util.fmtError('YAML error: {}'.format(exc.problem))
src_root_path = os.path.dirname(input) + '/'
if 'root' in yml:
src_root_path += yml['root'] + '/'
deploy_dir = args['deploy_dir'] + '/'
if not os.path.exists(deploy_dir):
os.makedirs(deploy_dir)
if check_dirty(src_root_path, input, out_hdr, yml):
copy_files(src_root_path, deploy_dir, yml)
gen_header(out_hdr, yml)
---
# an example file list, this is somewhere in the source code directory (for instance where
# the application executable's CMakeLists.txt file resides...
# set root directory to the project directory root (this is relative to the
# CMakeLists.txt file which references this YAML file), the files could also
# be anywhere else in the project directory
root: '../../..'
# copy the entire export directory content to the deployment directory,
# and re-create the directory hierarchy given in the paths
# NOTE: create the file list with 'tree -fi'
files: [
'export/anims/characters/dragon_brood_animations.nax3',
'export/anims/characters/dragon_brood_combat_idle_01.nac',
'export/anims/characters/dragon_brood_death.nac',
'export/anims/characters/dragon_brood_hit.nac',
'export/anims/characters/dragon_brood_hit_run.nac',
'export/anims/characters/dragon_brood_mount_animations.nax3',
'export/anims/characters/dragon_brood_mount_mount_idle_dragon_01.nac',
'export/anims/characters/dragon_brood_mount_mount_run_dragon_01.nac',
'export/anims/characters/dragon_brood_mount_variations.nax3',
'export/anims/characters/dragon_brood_run_01.nac',
'export/anims/characters/dragon_brood_skill_01.nac',
'export/anims/characters/dragon_brood_skill_02.nac',
'export/anims/characters/dragon_brood_spawn.nac',
'export/anims/characters/dragon_brood_stunned.nac',
'export/anims/characters/dragon_brood_variations.nax3',
'export/meshes/characters/dragon_brood/skins/body/body/dragon_brood_warrior_sk_0.nvx2',
'export/meshes/system/placeholder_s_0.nvx2',
'export/meshes/system/pointlightshape_s_0.nvx2',
'export/models/characters/dragon_brood.n3',
'export/models/system/placeholder.n3',
'export/textures/creatures/dragon_brood_01_bump.dds',
'export/textures/creatures/dragon_brood_01_color.dds',
'export/textures/creatures/dragon_brood_01_emsv.dds',
'export/textures/creatures/dragon_brood_01_spec.dds',
'export/textures/dummies/gray.dds',
'export/textures/environment/env_qube_reflect.dds',
'export/textures/system/black.dds',
'export/textures/system/nobump.dds',
'export/textures/system/placeholder.dds',
'export/textures/system/zeroalpha.dds',
'export/textures/ui/tahoma.dds',
'export/ui/tahoma_info.bytes'
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment