automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Conditional nodist_EXTRA_*_SOURCES C++ linking idiom


From: Matt Turner
Subject: Conditional nodist_EXTRA_*_SOURCES C++ linking idiom
Date: Mon, 17 Sep 2012 17:10:52 -0700

Hi,

I'd like to be able to conditionally link with C++. Consider a case
where a shared library is C-only, except for when an optional feature
is enabled which causes it to be linked with static C++ libraries.
When linking with the static C++ libraries, C++ linking must be used
in order to link with libstdc++.

I've tried using the nodist_EXTRA_foo_SOURCES = dummy.cpp idiom, but
it even causes C++ linkage when inside an false AM_CONDITIONAL.

configure.ac:
=============
AC_INIT([foo], [1.0])
AM_INIT_AUTOMAKE([foreign -Wall])

AC_PROG_CC
AC_PROG_CXX
AM_PROG_CC_C_O

AC_ARG_ENABLE([cplusplus],
        AS_HELP_STRING([--enable-cplusplus],
                       [enable C++ linking (default: no)]),
        [LINK_CPLUSPLUS=$enableval], [LINK_CPLUSPLUS=no])

AM_CONDITIONAL([LINK_CPLUSPLUS], [test "x$LINK_CPLUSPLUS" = xyes])

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

Makefile.am:
============
bin_PROGRAMS = foo
foo_SOURCES = foo.c

if LINK_CPLUSPLUS
nodist_EXTRA_foo_SOURCES = dummy.cpp
endif

foo.c:
======
#include <stdio.h>

int main(void) {
        return 0;
}

I would have expected that
   - passing --enable-cplusplus to configure would cause C++ linking
   - not passing --enable-cplusplus to configure to let normal C linking happen

I can see that the nodist_EXTRA_foo_SOURCES is commented out in the
generated Makefile, telling me that the AM_CONDITIONAL worked as I
expected.

Is this behavior by design? Is there some other way I can force C++
linking conditionally?

Thanks,
Matt



reply via email to

[Prev in Thread] Current Thread [Next in Thread]