From: Samuel Martin <s.martin49@gmail.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v6 3/9] toolchainfile.cmake: set per-config appended {C, CXX}FLAGS
Date: Sun, 16 Oct 2016 13:12:39 +0200 [thread overview]
Message-ID: <20161016111245.1847-4-s.martin49@gmail.com> (raw)
In-Reply-To: <20161016111245.1847-1-s.martin49@gmail.com>
When a build type is set, CMake does append some flags that can override
those set by Buildroot due to the gcc option parser (in which the last
argument controling an option wins).
Hereafter is a summary of the optimization and debug flags set by
Buildroot and appended by CMake.
* Flags set by Buildroot depending on the configuration:
BR2_ENABLE_DEBUG | Optim. level | Buildroot {C,CXX}FLAGS
=================+=====================+=======================
y | BR2_OPTIMIZE_S | -Os -gx
y | BR2_OPTIMIZE_G | -Og -gx
y | BR2_OPTIMIZE_{0..3} | -On -gx
n | BR2_OPTIMIZE_S | -Os
n | BR2_OPTIMIZE_G | -Og
n | BR2_OPTIMIZE_{0..3} | -On
* Default flags appended by CMake depending on the build type:
Build type | Flags | Effects on {C,CXX}FLAGS
===============+=================+===========================================
Debug | -g | Force -g, compatible with BR2_ENABLE_DEBUG
MinSizeRel | -Os -DNDEBUG | Set -Os, compatible with BR2_OPTIMIZE_S
Release | -O3 -DNDEBUG | Set -O3, closest to the others cases,
| | though the optimization level is forced.
RelWithDebInfo | -O2 -g -DNDEBUG | Force -g and set -O2, not friendly with BR
To avoid the CMake flags take precedence over the Buildroot ones, this
change sets in toolchainfile.cmake the per-config compiler flags CMake
can append depending on the build type Buildroot defined.
So, CMake does not mess up with the compilation flags Buildroot sets.
It is still possible to override these per-config flags on the cmake
command line.
Note:
If a CMake-based project forces the compiler and/or linker flag
definitions (the default ones or the per-config ones - e.g.
CMAKE_C_FLAGS/CMAKE_C_FLAGS_{DEBUG,RELEASE}), there is not much
Buildroot can do about it.
So, the flags will be overwritten anyway in these cases.
Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Cc: Maxime Hadjinlian <maxime.hadjinlian@gmail.com>
Signed-off-by: Samuel Martin <s.martin49@gmail.com>
---
changes v5->v6:
- reword commit log
changes v4->v5:
- fix cmake set call
changes v3->v4:
- new patch
---
support/misc/toolchainfile.cmake.in | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/support/misc/toolchainfile.cmake.in b/support/misc/toolchainfile.cmake.in
index 1c5031f..2ace940 100644
--- a/support/misc/toolchainfile.cmake.in
+++ b/support/misc/toolchainfile.cmake.in
@@ -13,6 +13,17 @@ string(REPLACE "/usr/share/buildroot" "" RELOCATED_HOST_DIR ${CMAKE_CURRENT_LIST
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR @@CMAKE_SYSTEM_PROCESSOR@@)
+# Set the {C,CXX}FLAGS appended by CMake depending on the build type
+# sets by Buildroot.
+#
+# Note:
+# if the project forces some of these flag variables, Buildroot is
+# screwed up and there is nothing Buildroot can do about that :(
+set(CMAKE_C_FLAGS_DEBUG "" CACHE STRING "Debug CFLAGS")
+set(CMAKE_CXX_FLAGS_DEBUG "" CACHE STRING "Debug CXXFLAGS")
+set(CMAKE_C_FLAGS_RELEASE " -DNEBUG" CACHE STRING "Release CFLAGS")
+set(CMAKE_CXX_FLAGS_RELEASE " -DNEBUG" CACHE STRING "Release CXXFLAGS")
+
# Build type from the Buildroot configuration
set(CMAKE_BUILD_TYPE @@CMAKE_BUILD_TYPE@@ CACHE STRING "Buildroot build configuration")
--
2.10.0
next prev parent reply other threads:[~2016-10-16 11:12 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-16 11:12 [Buildroot] [PATCH v6 0/9] Misc. CMake fixes Samuel Martin
2016-10-16 11:12 ` [Buildroot] [PATCH v6 1/9] Revert "package/cmake: with BR2_ENABLE_DEBUG use RelWithDebInfo" Samuel Martin
2016-10-16 18:53 ` Arnout Vandecappelle
2016-10-16 11:12 ` [Buildroot] [PATCH v6 2/9] package/pkg-cmake.mk: move CMAKE_BUILD_TYPE definition into toolchainfile.cmake Samuel Martin
2016-10-16 19:05 ` Arnout Vandecappelle
2016-10-22 14:43 ` Thomas Petazzoni
2016-10-16 11:12 ` Samuel Martin [this message]
2016-10-16 19:09 ` [Buildroot] [PATCH v6 3/9] toolchainfile.cmake: set per-config appended {C, CXX}FLAGS Arnout Vandecappelle
2016-10-22 14:43 ` Thomas Petazzoni
2016-10-16 11:12 ` [Buildroot] [PATCH v6 4/9] package/gflags: include TARGET_CXXFLAGS to the overloaded CXXFLAGS Samuel Martin
2016-10-16 11:12 ` [Buildroot] [PATCH v6 5/9] package/gnuradio: include TARGET_CFLAGS to the overloaded CFLAGS Samuel Martin
2016-10-16 11:12 ` [Buildroot] [PATCH v6 6/9] package/libcec: include TARGET_{C, CXX}FLAGS to the overloaded {C, CXX}FLAGS Samuel Martin
2016-10-16 11:12 ` [Buildroot] [PATCH v6 7/9] package/opencv3: fix CMAKE_CXX_FLAGS Samuel Martin
2016-10-16 11:12 ` [Buildroot] [PATCH v6 8/9] package/rpi-userland: include TARGET_CFLAGS to the overloaded CFLAGS Samuel Martin
2016-10-16 11:12 ` [Buildroot] [PATCH v6 9/9] toochainfile.cmake: rework the way Buildroot sets flags Samuel Martin
2016-10-16 19:13 ` Arnout Vandecappelle
2016-10-22 14:42 ` [Buildroot] [PATCH v6 0/9] Misc. CMake fixes Thomas Petazzoni
2016-10-22 15:09 ` Samuel Martin
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=20161016111245.1847-4-s.martin49@gmail.com \
--to=s.martin49@gmail.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