[v2] configure: better check for the C++ compiler

Submitted by Yann E. MORIN on March 8, 2017, 5:23 p.m.

Details

Message ID 1488993829-13686-1-git-send-email-yann.morin.1998@free.fr
State New
Headers show
Series "configure: better check for the C++ compiler" ( rev: 2 ) in Wayland

Not browsing as part of any series.

Commit Message

Yann E. MORIN March 8, 2017, 5:23 p.m.
When a C++ compiler is not found, then AC_PROG_CXX will set CXX to
'false'.

However, we test that we can find $CXX, and indeed false exists in
the PATH, for virtually all systems we have a chance to be compiled
on. So we conclude that we do have a C++ compiler, when this is
clearly wrong.

Improve our hack by trying to run the C++ compiler with a benign call,
that should succeed if the CXX is really a C++ compiler: tell it to dump
its pre-defined macros.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>

---
Changes v1 -> v2:
  - fix typo in commit log  (Peter)

---
Note: this is not a replacement for the patch I sent earlier [0].
It is complementary.
---
 configure.ac | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/configure.ac b/configure.ac
index 738d744..8b022c1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,11 +33,11 @@  AM_PROG_AS
 # check if we have C++ compiler. This is hacky workaround,
 # for a reason why it is this way see
 # http://lists.gnu.org/archive/html/bug-autoconf/2010-05/msg00001.html
-have_cpp_compiler=yes
-
-if ! which "$CXX" &>/dev/null; then
-	have_cpp_compiler=no
-fi
+AS_IF([! which "$CXX" &>/dev/null];
+	[have_cpp_compiler=no],
+	[AS_IF([! $CXX -dM -E - < /dev/null >/dev/null],
+		[have_cpp_compiler=no],
+		[have_cpp_compiler=yes])])
 
 AM_CONDITIONAL(ENABLE_CPP_TEST, test "x$have_cpp_compiler" = "xyes")
 

Comments

Hello,

On 2017-03-08 18:23 +0100, Yann E. MORIN spake thusly:
> When a C++ compiler is not found, then AC_PROG_CXX will set CXX to
> 'false'.
> 
> However, we test that we can find $CXX, and indeed false exists in
> the PATH, for virtually all systems we have a chance to be compiled
> on. So we conclude that we do have a C++ compiler, when this is
> clearly wrong.
> 
> Improve our hack by trying to run the C++ compiler with a benign call,
> that should succeed if the CXX is really a C++ compiler: tell it to dump
> its pre-defined macros.
> 
> Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>

Ping? ;-)

Regards,
Yann E. MORIN.

> ---
> Changes v1 -> v2:
>   - fix typo in commit log  (Peter)
> 
> ---
> Note: this is not a replacement for the patch I sent earlier [0].
> It is complementary.
> ---
>  configure.ac | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 738d744..8b022c1 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -33,11 +33,11 @@ AM_PROG_AS
>  # check if we have C++ compiler. This is hacky workaround,
>  # for a reason why it is this way see
>  # http://lists.gnu.org/archive/html/bug-autoconf/2010-05/msg00001.html
> -have_cpp_compiler=yes
> -
> -if ! which "$CXX" &>/dev/null; then
> -	have_cpp_compiler=no
> -fi
> +AS_IF([! which "$CXX" &>/dev/null];
> +	[have_cpp_compiler=no],
> +	[AS_IF([! $CXX -dM -E - < /dev/null >/dev/null],
> +		[have_cpp_compiler=no],
> +		[have_cpp_compiler=yes])])
>  
>  AM_CONDITIONAL(ENABLE_CPP_TEST, test "x$have_cpp_compiler" = "xyes")
>  
> -- 
> 2.7.4
>
On 2 April 2017 at 15:11, Yann E. MORIN <yann.morin.1998@free.fr> wrote:
> Hello,
>
> On 2017-03-08 18:23 +0100, Yann E. MORIN spake thusly:
>> When a C++ compiler is not found, then AC_PROG_CXX will set CXX to
>> 'false'.
>>
>> However, we test that we can find $CXX, and indeed false exists in
>> the PATH, for virtually all systems we have a chance to be compiled
>> on. So we conclude that we do have a C++ compiler, when this is
>> clearly wrong.
>>
>> Improve our hack by trying to run the C++ compiler with a benign call,
>> that should succeed if the CXX is really a C++ compiler: tell it to dump
>> its pre-defined macros.
>>
>> Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
>> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
>
> Ping? ;-)
>
Renamed g++ and c++ and CXX and ends up being set to g++ :-\
Perhaps there's something broken on my end ?

An alternative solutions is drop the "which" all together and make
this a configure toggle. Default to disabled and toggle at make
distcheck via AM_DISTCHECK_CONFIGURE_FLAGS.
This way the release manager will ensure that tarballs with 'broken'
headers are not shipped.

That should also work if CXX is set to "false", is and empty string or
set to the wrong value.

-Emil