Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 4/4] toolchainfile.cmake: set CXX variables wrt BR2_INSTALL_LIBSTDCPP value
Date: Mon, 16 Mar 2015 22:24:58 +0100	[thread overview]
Message-ID: <20150316222458.4616098c@free-electrons.com> (raw)
In-Reply-To: <1425808043-32292-5-git-send-email-s.martin49@gmail.com>

Dear Samuel Martin,

On Sun,  8 Mar 2015 10:47:23 +0100, Samuel Martin wrote:
> Signed-off-by: Samuel Martin <s.martin49@gmail.com>

This is a non-trivial patch, and the commit log is empty. Why?

> diff --git a/support/misc/toolchainfile.cmake.in b/support/misc/toolchainfile.cmake.in
> index cd41254..395cf3f 100644
> --- a/support/misc/toolchainfile.cmake.in
> +++ b/support/misc/toolchainfile.cmake.in
> @@ -17,6 +17,7 @@ set(CMAKE_C_FLAGS "@@TARGET_CFLAGS@@ ${CMAKE_C_FLAGS}" CACHE STRING "Buildroot C
>  set(CMAKE_CXX_FLAGS "@@TARGET_CXXFLAGS@@ ${CMAKE_CXX_FLAGS}" CACHE STRING "Buildroot CXXFLAGS")
>  set(CMAKE_EXE_LINKER_FLAGS "@@TARGET_LDFLAGS@@ ${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "Buildroot LDFLAGS")
>  set(CMAKE_INSTALL_SO_NO_EXE 0)
> +set(TARGET_HAS_LIBSTDCXX @@TARGET_HAS_LIBSTDCXX@@)
>  
>  set(CMAKE_PROGRAM_PATH "${RELOCATED_HOST_DIR}/usr/bin")
>  set(CMAKE_FIND_ROOT_PATH "${RELOCATED_HOST_DIR}/@@STAGING_SUBDIR@@")
> @@ -35,25 +36,45 @@ if(DEFINED USE_CCACHE)
>  	if(USE_CCACHE)
>  		set(CMAKE_ASM_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CC_NOCCACHE@@")
>  		set(CMAKE_C_COMPILER "${RELOCATED_HOST_DIR}/usr/bin/ccache")
> -		set(CMAKE_CXX_COMPILER "${RELOCATED_HOST_DIR}/usr/bin/ccache")
>  		set(CMAKE_C_COMPILER_ARG1 "${RELOCATED_HOST_DIR}/@@TARGET_CC_NOCCACHE@@")
> -		set(CMAKE_CXX_COMPILER_ARG1 "${RELOCATED_HOST_DIR}/@@TARGET_CXX_NOCCACHE@@")
> +		if(TARGET_HAS_LIBSTDCXX)
> +			set(CMAKE_CXX_COMPILER "${RELOCATED_HOST_DIR}/usr/bin/ccache")
> +			set(CMAKE_CXX_COMPILER_ARG1 "${RELOCATED_HOST_DIR}/@@TARGET_CXX_NOCCACHE@@")
> +		else()
> +			message(STATUS "Disabling C++ compiler because libstdc++ is not installed in the target filsystem")
> +			set(CMAKE_CXX_COMPILER "CMAKE_CXX_COMPILER-NOTFOUND")
> +		endif()
>  	else()
>  		set(CMAKE_C_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CC_NOCCACHE@@")
> -		set(CMAKE_CXX_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CXX_NOCCACHE@@")
> +		if(TARGET_HAS_LIBSTDCXX)
> +			set(CMAKE_CXX_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CXX_NOCCACHE@@")
> +		else()
> +			message(STATUS "Disabling C++ compiler because libstdc++ is not installed in the target filsystem")
> +			set(CMAKE_CXX_COMPILER "CMAKE_CXX_COMPILER-NOTFOUND")
> +		endif()
>  	endif()
>  else()
>  	find_program(CCACHE ccache HINTS "${RELOCATED_HOST_DIR}/usr/bin")
>  	if(CCACHE)
>  		set(CMAKE_ASM_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CC_NOCCACHE@@")
>  		set(CMAKE_C_COMPILER "${CCACHE}")
> -		set(CMAKE_CXX_COMPILER "${CCACHE}")
>  		set(CMAKE_C_COMPILER_ARG1 "${RELOCATED_HOST_DIR}/@@TARGET_CC_NOCCACHE@@")
> -		set(CMAKE_CXX_COMPILER_ARG1 "${RELOCATED_HOST_DIR}/@@TARGET_CXX_NOCCACHE@@")
> +		if(TARGET_HAS_LIBSTDCXX)
> +			set(CMAKE_CXX_COMPILER "${CCACHE}")
> +			set(CMAKE_CXX_COMPILER_ARG1 "${RELOCATED_HOST_DIR}/@@TARGET_CXX_NOCCACHE@@")
> +		else()
> +			message(STATUS "Disabling C++ compiler because libstdc++ is not installed in the target filsystem")
> +			set(CMAKE_CXX_COMPILER "CMAKE_CXX_COMPILER-NOTFOUND")
> +		endif()
>  		message(STATUS "ccache program has been found and will be used for the build.")
>  		message(STATUS "  To disable ccache, add -DUSE_CCACHE=OFF on the cmake command line.")
>  	else()
>  		set(CMAKE_C_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CC_NOCCACHE@@")
> -		set(CMAKE_CXX_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CXX_NOCCACHE@@")
> +		if(TARGET_HAS_LIBSTDCXX)
> +			set(CMAKE_CXX_COMPILER "${RELOCATED_HOST_DIR}/@@TARGET_CXX_NOCCACHE@@")
> +		else()
> +			message(STATUS "Disabling C++ compiler because libstdc++ is not installed in the target filsystem")
> +			set(CMAKE_CXX_COMPILER "CMAKE_CXX_COMPILER-NOTFOUND")
> +		endif()
>  	endif()
>  endif()

This is doing multiple times the same thing.

First of all, why do we have those two cases for the ccache support:

if(DEFINED USE_CCACHE)
        if(USE_CCACHE)
	...
	else()
	...
	endif()
else()
	find_program(CCACHE ccache HINTS "${RELOCATED_HOST_DIR}/usr/bin")
	if(CCACHE)
	...
	else()
	...
	endif()
endif()

The first case is when the toolchain file is used by Buildroot itself,
the second case when it's used outside of Buildroot. But why don't we
use the find_program() trick in both cases ?

Shouldn't we instead do:

find_program(CCACHE ccache HINTS "${RELOCATED_HOST_DIR}/usr/bin")
if (CCACHE and USE_CCACHE)
	...
else()

	...
endif()

Regarding the C++ stuff, the non-C++ case is the same between having
ccache and not having ccache, so you could factorize that a bit.

Could you rework this a bit?

Thanks a lot,

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

      reply	other threads:[~2015-03-16 21:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-08  9:47 [Buildroot] [PATCH 0/4] CMake package and infra improvements Samuel Martin
2015-03-08  9:47 ` [Buildroot] [PATCH 1/4 v5] package/cmake: make ctest a target package too Samuel Martin
2015-03-08  9:53   ` Baruch Siach
2015-03-08 11:29     ` Samuel Martin
2015-03-15 17:41   ` Thomas Petazzoni
2015-03-08  9:47 ` [Buildroot] [PATCH 2/4 v2] package/cmake: only build what is necessary Samuel Martin
2015-03-15 17:52   ` Thomas Petazzoni
2015-03-08  9:47 ` [Buildroot] [PATCH 3/4] toolchainfile.cmake: only search the sysroot for CMake module Samuel Martin
2015-03-08 10:23   ` Yegor Yefremov
2015-03-16 21:17   ` Thomas Petazzoni
2015-03-08  9:47 ` [Buildroot] [PATCH 4/4] toolchainfile.cmake: set CXX variables wrt BR2_INSTALL_LIBSTDCPP value Samuel Martin
2015-03-16 21:24   ` Thomas Petazzoni [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150316222458.4616098c@free-electrons.com \
    --to=thomas.petazzoni@free-electrons.com \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox