grasingerm
grasingerm

Reputation: 1953

How do I set build rules for a file using autotools (automake, configure, etc.)?

I have inherited code that is set up to be built using autotools, but I've always used CMake. Some of the C++ source uses C++11 and C++14 standards. However, when I run

CXXFLAGS="$CXXFLAGS -std=c++14" ./configure
make

only some of the C++ source files are being built with the -std=c++14 flag. If this was a simple Makefile and I noticed that foo.cc was not built with the correct flags, I might look to change

foo.o: foo.cc foo.h
    $(CXX) -c foo.c

to

foo.o: foo.cc foo.h
    $(CXX) $(CXXFLAGS) -c foo.c

Is there an analog to this in autotools? I've checked configure.ac and Makefile.am but haven't found the solution.

Upvotes: 1

Views: 435

Answers (2)

Vicente Bolea
Vicente Bolea

Reputation: 1563

In the case that CXXFLAGS was already defined with another -std=... you need to execute the configure script in this way instead:

./configure CXXFLAGS=" -std=c++14"

Note that @ptomato is right about the difference between AM_CXXFLAGS and CXXFLAGS.

Upvotes: 0

ptomato
ptomato

Reputation: 57850

What you are doing, setting CXXFLAGS when calling configure, ought to work. However, often Makefile.am authors make the mistake of setting CXXFLAGS inside the makefile, which overrides your setting, rather than setting AM_CXXFLAGS as they should. That might be the case here.

In any case, if your program requires C++14, then you should probably check out the AX_CXX_COMPILE_STDCXX([14]) macro, and put it in your configure.ac, rather than setting flags.

Upvotes: 1

Related Questions