Skip to contentSkip to conversation

CMake cleanup

PATCH New Samuel Martin 3 participants 14 messages Aug 21, 2014 – Sep 28, 2014

lore
Share & tools
lore
#0 lore raw

v2 cover CMake cleanup

Hi all,

Quick respin of this series cleaning up the {host-,}cmake-package infrastructure (more specifically how the {C,CXX,LD}FLAGS are handled) and fix the bug #7280.

For this round, I have discarded the 6th patch which is an RFC. The only others changes are typo fixes in the commit message of the patch 5/5

Cheers,

Samuel Martin (5):
package/pkg-cmake.mk: remove the USE_CCACHE CMake flag for
host-package
package/pkg-cmake.mk: set the {C,CXX,LD}FLAGS for host packages toolchainfile.cmake.in: set linker flags
package/cdrkit: clean {HOST_,}CDRKIT_CONF_OPT toolchainfile.cmake.in: do not force the CMAKE_{C,CXX}_FLAGS to the
cache

 package/cdrkit/cdrkit.mk            | 7 -------
 package/pkg-cmake.mk                | 5 ++++-
 support/misc/toolchainfile.cmake.in | 5 +++--
 3 files changed, 7 insertions(+), 10 deletions(-)

--
2.1.0

#1 lore raw

PATCH v2 1/5 package/pkg-cmake.mk: remove the USE_CCACHE CMake flag for host-package

The USE_CCACHE CMake flag is only useful when building target package (only the toolchainfile.cmake uses it).

---
changes v1 -> v2:
- no change

---
 package/pkg-cmake.mk | 1 -
 1 file changed, 1 deletion(-)
package/pkg-cmake.mk +0 -1
index 30198a9..f5aefae 100644
@@ -86,7 +86,6 @@ define $(2)_CONFIGURE_CMDS
 		-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY="BOTH" \
 		-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE="BOTH" \
 		-DCMAKE_INSTALL_PREFIX="$$(HOST_DIR)/usr" \
-		-DUSE_CCACHE=$$(if $$(BR2_CCACHE),ON,OFF) \
 		-DBUILD_TESTING=OFF \
 		$$($$(PKG)_CONF_OPT) \
 	)
Signature · 1 line
2.1.0
#2 lore raw

PATCH v2 1/5 package/pkg-cmake.mk: remove the USE_CCACHE CMake flag for host-package

Samuel, All,

On 2014-08-21 22:45 +0200, Samuel Martin spake thusly:

Quoted 4 lines

The USE_CCACHE CMake flag is only useful when building target package (only the toolchainfile.cmake uses it).

Regards,
Yann E. MORIN.

Quoted 26 lines

---
changes v1 -> v2:
- no change

---
 package/pkg-cmake.mk | 1 -
 1 file changed, 1 deletion(-)
package/pkg-cmake.mk +0 -1
index 30198a9..f5aefae 100644
@@ -86,7 +86,6 @@ define $(2)_CONFIGURE_CMDS
 		-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY="BOTH" \
 		-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE="BOTH" \
 		-DCMAKE_INSTALL_PREFIX="$$(HOST_DIR)/usr" \
-		-DUSE_CCACHE=$$(if $$(BR2_CCACHE),ON,OFF) \
 		-DBUILD_TESTING=OFF \
 		$$($$(PKG)_CONF_OPT) \
 	)
Signature · 6 lines
2.1.0

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#4 lore raw

PATCH v2 2/5 package/pkg-cmake.mk: set the {C, CXX, LD}FLAGS for host packages

In reply to Samuel Martin

---
changes v1 -> v2:
- no change

---
 package/pkg-cmake.mk | 3 +++
 1 file changed, 3 insertions(+)
package/pkg-cmake.mk +3 -0
index f5aefae..3655751 100644
@@ -86,6 +86,9 @@ define $(2)_CONFIGURE_CMDS
 		-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY="BOTH" \
 		-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE="BOTH" \
 		-DCMAKE_INSTALL_PREFIX="$$(HOST_DIR)/usr" \
+		-DCMAKE_C_FLAGS="$$(HOST_CFLAGS)" \
+		-DCMAKE_CXX_FLAGS="$$(HOST_CXXFLAGS)" \
+		-DCMAKE_EXE_LINKER_FLAGS="$$(HOST_LDFLAGS)" \
 		-DBUILD_TESTING=OFF \
 		$$($$(PKG)_CONF_OPT) \
 	)
Signature · 1 line
2.1.0
#5 lore raw

PATCH v2 2/5 package/pkg-cmake.mk: set the {C, CXX, LD}FLAGS for host packages

Samuel, All,

On 2014-08-21 22:45 +0200, Samuel Martin spake thusly:

Quoted 1 line

As I am not a cmake expert, I'd like a bit more explanations in the commit log.

What puzzles me is that, for the target case, these flags are passed via support/misc/toolchainfile.cmake.in, while for the host, we pass them on the command line. This is not consistent.

Why don't we also use a host.cmake.in file like we have for the target?

Note that us having support/misc/toolchainfile.cmake.in does not even help for building a cmake package outside of Buildroot (but still using our toolchain), since the user may forget to define CMAKE_TOOLCHAIN_FILE when calling cmake on his own.

Note: I know you have a good answer, but I'm a bit lost as to all those special-casing in cmake, which makes reviewing a bit difficult, and a bit of comments in the commit log (a pointer to the cmake doc would be enough!) would make it easier.

Regards,
Yann E. MORIN.

Quoted 28 lines

---
changes v1 -> v2:
- no change

---
 package/pkg-cmake.mk | 3 +++
 1 file changed, 3 insertions(+)
package/pkg-cmake.mk +3 -0
index f5aefae..3655751 100644
@@ -86,6 +86,9 @@ define $(2)_CONFIGURE_CMDS
 		-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY="BOTH" \
 		-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE="BOTH" \
 		-DCMAKE_INSTALL_PREFIX="$$(HOST_DIR)/usr" \
+		-DCMAKE_C_FLAGS="$$(HOST_CFLAGS)" \
+		-DCMAKE_CXX_FLAGS="$$(HOST_CXXFLAGS)" \
+		-DCMAKE_EXE_LINKER_FLAGS="$$(HOST_LDFLAGS)" \
 		-DBUILD_TESTING=OFF \
 		$$($$(PKG)_CONF_OPT) \
 	)
Signature · 6 lines
2.1.0

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#6 lore raw

PATCH v2 2/5 package/pkg-cmake.mk: set the {C, CXX, LD}FLAGS for host packages

In reply to Samuel Martin
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Samuel" == Samuel Martin <[email protected]> writes:

Committed, thanks.

I do agree with Yann though that it would be good if the commit messages were more detailed. Why do we use a toolchain files for target, but not for host?

Signature · 1 line
Bye, Peter Korsgaard
#7 lore raw

PATCH v2 3/5 toolchainfile.cmake.in: set linker flags

In reply to Samuel Martin

The linker flags are part of the toolchain configuration, so set them for the CMake-based packages.

---
changes v1 -> v2:
- no change

---
 package/pkg-cmake.mk                | 1 +
 support/misc/toolchainfile.cmake.in | 1 +
 2 files changed, 2 insertions(+)
package/pkg-cmake.mk +1 -0
index 3655751..2006b76 100644
@@ -177,6 +177,7 @@ $(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake:
 		-e 's:@@STAGING_SUBDIR@@:$(call qstrip,$(STAGING_SUBDIR)):' \
 		-e 's:@@TARGET_CFLAGS@@:$(call qstrip,$(TARGET_CFLAGS)):' \
 		-e 's:@@TARGET_CXXFLAGS@@:$(call qstrip,$(TARGET_CXXFLAGS)):' \
+		-e 's:@@TARGET_LDFLAGS@@:$(call qstrip,$(TARGET_LDFLAGS)):' \
 		-e 's:@@TARGET_CC_NOCCACHE@@:$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_CC_NOCCACHE))):' \
 		-e 's:@@TARGET_CXX_NOCCACHE@@:$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_CXX_NOCCACHE))):' \
 		$(TOPDIR)/support/misc/toolchainfile.cmake.in \
support/misc/toolchainfile.cmake.in +1 -0
index 46ed932..1dfbdba 100644
@@ -14,6 +14,7 @@ set(CMAKE_SYSTEM_NAME Linux)
 
 set(CMAKE_C_FLAGS "@@TARGET_CFLAGS@@ ${CMAKE_C_FLAGS}" CACHE STRING "Buildroot CFLAGS" FORCE)
 set(CMAKE_CXX_FLAGS "@@TARGET_CXXFLAGS@@ ${CMAKE_CXX_FLAGS}" CACHE STRING "Buildroot CXXFLAGS" FORCE)
+set(CMAKE_EXE_LINKER_FLAGS "@@TARGET_LDFLAGS@@ ${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "Buildroot LDFLAGS")
 set(CMAKE_INSTALL_SO_NO_EXE 0)
 
 set(CMAKE_PROGRAM_PATH "${RELOCATED_HOST_DIR}/usr/bin")
Signature · 1 line
2.1.0
#8 lore raw

PATCH v2 3/5 toolchainfile.cmake.in: set linker flags

Samuel, All,

On 2014-08-21 22:45 +0200, Samuel Martin spake thusly:

Quoted 4 lines

The linker flags are part of the toolchain configuration, so set them for the CMake-based packages.

This patch does not add the FORCE option, like for CFLAGS and CXXFLAGS, which make it a bit incoherent. But since we're removing in the following patch, that's OK.

Regards,
Yann E. MORIN.

Quoted 39 lines

---
changes v1 -> v2:
- no change

---
 package/pkg-cmake.mk                | 1 +
 support/misc/toolchainfile.cmake.in | 1 +
 2 files changed, 2 insertions(+)
package/pkg-cmake.mk +1 -0
index 3655751..2006b76 100644
@@ -177,6 +177,7 @@ $(HOST_DIR)/usr/share/buildroot/toolchainfile.cmake:
 		-e 's:@@STAGING_SUBDIR@@:$(call qstrip,$(STAGING_SUBDIR)):' \
 		-e 's:@@TARGET_CFLAGS@@:$(call qstrip,$(TARGET_CFLAGS)):' \
 		-e 's:@@TARGET_CXXFLAGS@@:$(call qstrip,$(TARGET_CXXFLAGS)):' \
+		-e 's:@@TARGET_LDFLAGS@@:$(call qstrip,$(TARGET_LDFLAGS)):' \
 		-e 's:@@TARGET_CC_NOCCACHE@@:$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_CC_NOCCACHE))):' \
 		-e 's:@@TARGET_CXX_NOCCACHE@@:$(subst $(HOST_DIR)/,,$(call qstrip,$(TARGET_CXX_NOCCACHE))):' \
 		$(TOPDIR)/support/misc/toolchainfile.cmake.in \
support/misc/toolchainfile.cmake.in +1 -0
index 46ed932..1dfbdba 100644
@@ -14,6 +14,7 @@ set(CMAKE_SYSTEM_NAME Linux)
 
 set(CMAKE_C_FLAGS "@@TARGET_CFLAGS@@ ${CMAKE_C_FLAGS}" CACHE STRING "Buildroot CFLAGS" FORCE)
 set(CMAKE_CXX_FLAGS "@@TARGET_CXXFLAGS@@ ${CMAKE_CXX_FLAGS}" CACHE STRING "Buildroot CXXFLAGS" FORCE)
+set(CMAKE_EXE_LINKER_FLAGS "@@TARGET_LDFLAGS@@ ${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "Buildroot LDFLAGS")
 set(CMAKE_INSTALL_SO_NO_EXE 0)
 
 set(CMAKE_PROGRAM_PATH "${RELOCATED_HOST_DIR}/usr/bin")
Signature · 6 lines
2.1.0

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#10 lore raw

PATCH v2 4/5 package/cdrkit: clean {HOST_, }CDRKIT_CONF_OPT

In reply to Samuel Martin

Extending {C,LD}FLAGS for both host and target cdrkit package is not needed because it is already handled by the {host-,}cmake-package infrastructure.

---
changes v1 -> v2:
- no change

---
 package/cdrkit/cdrkit.mk | 7 -------
 1 file changed, 7 deletions(-)
package/cdrkit/cdrkit.mk +0 -7
index ee98013..3cb64b2 100644
@@ -18,12 +18,5 @@ endif
 
 CDRKIT_CONF_OPT += $(CMAKE_ENDIAN_OPT)
 
-## cdrkit isn't completely re-rooted by CMAKE_FIND_ROOT_PATH, so add
-## some extra flags so it finds needed libs and headers.
-CDRKIT_CONF_OPT += -DCMAKE_C_FLAGS="-I$(STAGING_DIR)/usr/include"
-CDRKIT_CONF_OPT += -DCMAKE_EXE_LINKER_FLAGS="$(TARGET_LDFLAGS)"
-HOST_CDRKIT_CONF_OPT += -DCMAKE_C_FLAGS="-I$(HOST_DIR)/usr/include"
-HOST_CDRKIT_CONF_OPT += -DCMAKE_EXE_LINKER_FLAGS="$(HOST_LDFLAGS)"
-
 $(eval $(cmake-package))
 $(eval $(host-cmake-package))
Signature · 1 line
2.1.0
#11 lore raw

PATCH v2 4/5 package/cdrkit: clean {HOST_, }CDRKIT_CONF_OPT

Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Samuel" == Samuel Martin <[email protected]> writes:

Extending {C,LD}FLAGS for both host and target cdrkit package is not needed because it is already handled by the {host-,}cmake-package infrastructure.

No longer applied, but I've fixed it up and committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard
#12 lore raw

PATCH v2 5/5 toolchainfile.cmake.in: do not force the CMAKE_{C, CXX}_FLAGS to the cache

In reply to Samuel Martin

Fix #7280 [1]

When the FORCE option is passed to the set command, the variable is added/updated in the CMake cache every single time CMake processes this command.

Because the toolchainfile.cmake prepends architecture/toolchain flags to the CMAKE_{C,CXX}_FLAGS, this makes the CFLAGS being updated in the generated Makefiles each time one reconfigures its project. So it forces the compilation of everything, even when nothing has changed.

[1] https://bugs.busybox.net/show_bug.cgi?id=7280

(tested the SimpleApp reproduction scenario described in the bug report)

---
changes v1 -> v2:
- fix typoes in commit log (ThomasDS)
- update A/R/T tags

---
 support/misc/toolchainfile.cmake.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
support/misc/toolchainfile.cmake.in +2 -2
index 1dfbdba..4ca3d35 100644
@@ -12,8 +12,8 @@ string(REPLACE "/usr/share/buildroot" "" RELOCATED_HOST_DIR ${CMAKE_CURRENT_LIST
 
 set(CMAKE_SYSTEM_NAME Linux)
 
-set(CMAKE_C_FLAGS "@@TARGET_CFLAGS@@ ${CMAKE_C_FLAGS}" CACHE STRING "Buildroot CFLAGS" FORCE)
-set(CMAKE_CXX_FLAGS "@@TARGET_CXXFLAGS@@ ${CMAKE_CXX_FLAGS}" CACHE STRING "Buildroot CXXFLAGS" FORCE)
+set(CMAKE_C_FLAGS "@@TARGET_CFLAGS@@ ${CMAKE_C_FLAGS}" CACHE STRING "Buildroot CFLAGS")
+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)
 
Signature · 1 line
2.1.0
#13 lore raw

PATCH v2 5/5 toolchainfile.cmake.in: do not force the CMAKE_{C, CXX}_FLAGS to the cache

Quoted 12 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Samuel" == Samuel Martin <[email protected]> writes:

Fix #7280 [1]
When the FORCE option is passed to the set command, the variable is added/updated in the CMake cache every single time CMake processes this command.

Because the toolchainfile.cmake prepends architecture/toolchain flags to the CMAKE_{C,CXX}_FLAGS, this makes the CFLAGS being updated in the generated Makefiles each time one reconfigures its project. So it forces the compilation of everything, even when nothing has changed.

Quoted 5 lines

[1] https://bugs.busybox.net/show_bug.cgi?id=7280

(tested the SimpleApp reproduction scenario described in the bug report)

Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard