stschindler
stschindler

Reputation: 937

How to search for libraries/headers in custom paths using waf?

I try to search for a library and headers in a waf wscript file. Generally, that's possible with:

def configure( conf ):
  conf.load( "compiler_cxx" )
  conf.check_cxx( lib = "thelib" )
  conf.check_cxx( header_name "header.hpp" )

That works fine on Unix-like systems, where libraries and headers are mostly in common places. However, I'd like to add custom search paths to the check_cxx() command, especially to give the users on Windows systems the chance to find the library, which is often somewhere in the file system.

I'm aware of the libpath argument, however it still needs to be filled somehow, and I wonder if there isn't a more general or even built-in solution I missed.

I'd also be happy to hear about other approaches, solutions or good practices for such things in waf.

Upvotes: 4

Views: 4995

Answers (3)

Gaslight Deceive Subvert
Gaslight Deceive Subvert

Reputation: 20354

Wafs C and C++ compilation tools respects environment variables on Windows too. So you would simply set CXXFLAGS and LDFLAGS before running Waf:

> set CXXFLAGS=/IC:\\path\\to\\header.hpp-file
> set LDFLAGS=/LIBPATH:C:\\path\\thelib
> python waf configure build
...

/I and /LIBPATH are switches that Waf will pass to the C compiler and linker. In this case, Microsoft Visual C. Use -I and -L instead if you are using gcc or clang.

Upvotes: 0

neuro
neuro

Reputation: 15180

The best practice is to use the use facility of WAF for your check (§10.3 of the wafbook) and define the paths for your external/system libs (§10.3.3)

It will looks like :

def configure(conf):

    conf.load('compiler_cxx')
    conf.env.LIBPATH_MYLIB = ['/usr/local/lib']
    conf.env.INCLUDES_MYLIB  = ['/usr/local/include']

    if sys.platform == 'win32':
            conf.env.LIBPATH_MYLIB   = ['/custom/windows/path/lib']
            conf.env.INCLUDES_MYLIB  = ['/custom/windows/path/include']

    # use MYLIB in your check
    conf.check_cxx(lib = 'somelib', use = 'MYLIB', cxxflags = '-O2')

def build(bld):

    # Of course you can use the defined MYLIB in build ^^
    bld.program(source = 'main.cpp', use = 'MYLIB')

Upvotes: 4

drahnr
drahnr

Reputation: 6886

def build(bld):
    bld.program(
        ...
        stdlibpath=['list/of','various/paths','the/linker/checks/for','libraries'],
        ...
    )

Upvotes: 1

Related Questions