All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cmake.bbclass: pass mandatory compiler flags through CMAKE_<LANG>_COMPILER_ARG1
@ 2019-05-14 15:04 Nikolai Merinov
  2019-05-14 15:49 ` Bach, Pascal
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Nikolai Merinov @ 2019-05-14 15:04 UTC (permalink / raw)
  To: openembedded-core

The CMake takes mandatory compiler arguments from the following variables:
- CMAKE_SYSROOT -- path to sysroot that should be passed to compiler.
- CMAKE_<LANG>_COMPILER_TARGET -- target architecture, used for compilers
  that supports several targets through command line options.
  e.g. "clang --target ${CMAKE_C_COMPILER_TARGET}".
- CMAKE_<LANG>_COMPILER_EXTERNAL_TOOLCHAIN -- path to external toolchain,
  used for compilers that support build with external toolchain.
  e.g. "clang --gcc-toolchain ${CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN}".
- CMAKE_<LANG>_COMPILER_ARG1 -- other mandatory arguments to a compiler
  command.

CMAKE_<LANG>_COMPILER_ARG1 is the most suitable variable to pass mandatory
arguments, that belongs to CC variable with other build systems, to a
compiler.

Additionally usage of CMAKE_<LANG>_COMPILER_ARG1 instead of
CMAKE_<LANG>_FLAGS reduce the risk that a variable can be overrided by
CMakeLists.txt files.
---
 meta/classes/cmake.bbclass | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/meta/classes/cmake.bbclass b/meta/classes/cmake.bbclass
index d3f0d70847..4da4c00a09 100644
--- a/meta/classes/cmake.bbclass
+++ b/meta/classes/cmake.bbclass
@@ -27,27 +27,33 @@ python() {
         cc_list = d.getVar('CC').split()
         if cc_list[0] == 'ccache':
             d.setVar('OECMAKE_C_COMPILER', '%s %s' % (cc_list[0], cc_list[1]))
+            cc_arg1 = ' '.join(cc_list[2:])
         else:
             d.setVar('OECMAKE_C_COMPILER', cc_list[0])
+            cc_arg1 = ' '.join(cc_list[1:])
+        if not d.getVar('OECMAKE_C_COMPILER_ARG1'):
+            d.setVar('OECMAKE_C_COMPILER_ARG1', cc_arg1)
 
     if not d.getVar('OECMAKE_CXX_COMPILER'):
         cxx_list = d.getVar('CXX').split()
         if cxx_list[0] == 'ccache':
             d.setVar('OECMAKE_CXX_COMPILER', '%s %s' % (cxx_list[0], cxx_list[1]))
+            cxx_arg1 = ' '.join(cxx_list[2:])
         else:
             d.setVar('OECMAKE_CXX_COMPILER', cxx_list[0])
+            cxx_arg1 = ' '.join(cxx_list[1:])
+        if not d.getVar('OECMAKE_CXX_COMPILER_ARG1'):
+            d.setVar('OECMAKE_CXX_COMPILER_ARG1', cxx_arg1)
 }
 OECMAKE_AR ?= "${AR}"
 
 # Compiler flags
-OECMAKE_C_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CFLAGS}"
-OECMAKE_CXX_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS}"
+OECMAKE_C_FLAGS ?= "${CFLAGS}"
+OECMAKE_CXX_FLAGS ?= "${CXXFLAGS}"
 OECMAKE_C_FLAGS_RELEASE ?= "-DNDEBUG"
 OECMAKE_CXX_FLAGS_RELEASE ?= "-DNDEBUG"
-OECMAKE_C_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CPPFLAGS} ${LDFLAGS}"
-OECMAKE_CXX_LINK_FLAGS ?= "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} ${CXXFLAGS} ${LDFLAGS}"
-CXXFLAGS += "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS}"
-CFLAGS += "${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS}"
+OECMAKE_C_LINK_FLAGS ?= "${CPPFLAGS} ${LDFLAGS}"
+OECMAKE_CXX_LINK_FLAGS ?= "${CXXFLAGS} ${LDFLAGS}"
 
 OECMAKE_RPATH ?= ""
 OECMAKE_PERLNATIVE_DIR ??= ""
@@ -85,8 +91,11 @@ $cmake_crosscompiling
 set( CMAKE_SYSTEM_NAME `echo ${TARGET_OS} | sed -e 's/^./\u&/' -e 's/^\(Linux\).*/\1/'` )
 set( CMAKE_SYSTEM_PROCESSOR ${@map_target_arch_to_uname_arch(d.getVar('TARGET_ARCH'))} )
 set( CMAKE_C_COMPILER ${OECMAKE_C_COMPILER} )
+set( CMAKE_C_COMPILER_ARG1 "${OECMAKE_C_COMPILER_ARG1}" )
 set( CMAKE_CXX_COMPILER ${OECMAKE_CXX_COMPILER} )
+set( CMAKE_CXX_COMPILER_ARG1 "${OECMAKE_CXX_COMPILER_ARG1}" )
 set( CMAKE_ASM_COMPILER ${OECMAKE_C_COMPILER} )
+set( CMAKE_ASM_COMPILER_ARG1 "${OECMAKE_C_COMPILER_ARG1}" )
 set( CMAKE_AR ${OECMAKE_AR} CACHE FILEPATH "Archiver" )
 set( CMAKE_C_FLAGS "${OECMAKE_C_FLAGS}" CACHE STRING "CFLAGS" )
 set( CMAKE_CXX_FLAGS "${OECMAKE_CXX_FLAGS}" CACHE STRING "CXXFLAGS" )
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-06-25 12:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-14 15:04 [PATCH] cmake.bbclass: pass mandatory compiler flags through CMAKE_<LANG>_COMPILER_ARG1 Nikolai Merinov
2019-05-14 15:49 ` Bach, Pascal
2019-05-15  9:19   ` Nikolai Merinov
2019-05-20 20:41 ` Khem Raj
2019-06-20 14:16   ` [PATCHv2] " Nikolai Merinov
2019-06-24 10:24     ` [PATCHv3] " Nikolai Merinov
2019-06-25  8:03       ` Richard Purdie
2019-06-25 12:39         ` Nikolai Merinov
2019-06-20 14:30 ` ✗ patchtest: failure for cmake.bbclass: pass mandatory compiler flags through CMAKE_<LANG>_COMPILER_ARG1 (rev2) Patchwork

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.