Search code examples
dwaf

How do i add compile options for only one of the files of a library in WAF?


I am experimenting with waf for my d project. One of the nice features of D is the "import" of entire files into the code at compile time. To do this you have to specify the folders that will be looked in for the files to import. In the case of the dmd compiler you have to use the -Jpath command-line option.

I am building a library with a hundred files in different folders, and i want to be able to specify the -J option only for the copilation of some specific files. This is done in cmake with something like:

set_source_files_properties( 
    core/shader.d PROPERTIES COMPILE_FLAGS 
        -J${CMAKE_CURRENT_SOURCE_DIR}/core/gl2/shaders )

But in waf i don't know how to do it. My wscript lookes like this but this passes the -J flags to all the files:

#! /usr/bin/env python
# encoding: utf-8

def build(bld):

 bld.stlib(
  source   = 
   '''
   app/action.d
   app/client.d
<...snip..>
   core/shader.d
   core/stream.d
   ''',
  includes = ['..', '../extern' ],
  name     = 'mylib',
  target   = 'mylib
  dflags  = '-J/some/path/core/gl2/shaders')

Solution

  • You can do:

    bld(
     target="specialfile",
     features="d",
     source="specialfile.c",
     defines=["SPECIAL=1"],
    )
    
    bld.stlib(
     ...,
     use=["specialfile"],
    )