]> code.ossystems Code Review - openembedded-core.git/commitdiff
cmake: in SDK use OE env var to set default toolchain
authorCody P Schafer <dev@codyps.com>
Mon, 1 May 2017 19:29:39 +0000 (15:29 -0400)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 26 Jul 2018 12:16:31 +0000 (13:16 +0100)
Patch the location in cmake where the toolchain file is loaded
to use the (new) OE_CMAKE_TOOLCHAIN_FILE variable to select a default
toolchain if no toolchain has been specified. The cmake alias is
removed.

The alternatives:

 - shell alias fails when cmake is called indirectly (ex: a makefile
   managing several projects which calls cmake for some of them)
   because aliases are not inherited

 - wrapper script that unconditionally adds "-D..." breaks cmake's
   build tests and many other things as it causes cmake to believe it
   should be configuring things when it should not be. For example,
   `cmake -DCMAKE_TOOLCHAIN_FILE=... --build .` does not work (note
   that this also breaks people directly using `cmake --build .` with
   the current alias).

Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
meta/recipes-devtools/cmake/cmake/0001-CMakeDetermineSystem-use-oe-environment-vars-to-load.patch [new file with mode: 0644]
meta/recipes-devtools/cmake/cmake/environment.d-cmake.sh
meta/recipes-devtools/cmake/cmake_3.11.4.bb

diff --git a/meta/recipes-devtools/cmake/cmake/0001-CMakeDetermineSystem-use-oe-environment-vars-to-load.patch b/meta/recipes-devtools/cmake/cmake/0001-CMakeDetermineSystem-use-oe-environment-vars-to-load.patch
new file mode 100644 (file)
index 0000000..a233287
--- /dev/null
@@ -0,0 +1,45 @@
+From a42cfebcd6c684cccf8ad33e5bd5130f7cdba135 Mon Sep 17 00:00:00 2001
+From: Cody P Schafer <dev@codyps.com>
+Date: Thu, 27 Apr 2017 11:35:05 -0400
+Subject: [PATCH] CMakeDetermineSystem: use oe environment vars to load default
+ toolchain file in sdk
+
+Passing the toolchain by:
+
+ - shell aliases does not work if cmake is called by a script
+ - unconditionally by a wrapper script causes cmake to believe it is
+   configuring things when it is not (for example, `cmake --build` breaks).
+
+The OE_CMAKE_TOOLCHAIN_FILE variable is only used as a default if no
+toolchain is explicitly specified.
+
+Setting the CMAKE_TOOLCHAIN_FILE cmake variable is marked as cached
+because '-D' options are cache entries themselves.
+
+Upstream-Status: Inappropriate [oe-core specific]
+Signed-off-by: Cody P Schafer <dev@codyps.com>
+---
+ Modules/CMakeDetermineSystem.cmake | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/Modules/CMakeDetermineSystem.cmake b/Modules/CMakeDetermineSystem.cmake
+index f34ec5d61..bcac3ef16 100644
+--- a/Modules/CMakeDetermineSystem.cmake
++++ b/Modules/CMakeDetermineSystem.cmake
+@@ -74,6 +74,13 @@ else()
+   endif()
+ endif()
++if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
++  if(DEFINED ENV{OE_CMAKE_TOOLCHAIN_FILE})
++    set(CMAKE_TOOLCHAIN_FILE "$ENV{OE_CMAKE_TOOLCHAIN_FILE}" CACHE FILEPATH "toolchain file")
++    message(STATUS "Toolchain file defaulted to '${CMAKE_TOOLCHAIN_FILE}'")
++  endif()
++endif()
++
+ # if a toolchain file is used, the user wants to cross compile.
+ # in this case read the toolchain file and keep the CMAKE_HOST_SYSTEM_*
+ # variables around so they can be used in CMakeLists.txt.
+-- 
+2.12.2
+
index 0eb56b66fa16267f73e13fdf4399301a41342be4..64b6cf3c6a30160c1c2fcf640cef7d8627bb05fa 100644 (file)
@@ -1 +1 @@
-alias cmake="cmake -DCMAKE_TOOLCHAIN_FILE=$OECORE_NATIVE_SYSROOT/usr/share/cmake/OEToolchainConfig.cmake"
+export OE_CMAKE_TOOLCHAIN_FILE="$OECORE_NATIVE_SYSROOT/usr/share/cmake/OEToolchainConfig.cmake"
index 3f8fd7a9975f33a0b762faec04c96a147910b3b3..eb055b975719b554191f65c244a3ba4cdd586bd6 100644 (file)
@@ -6,7 +6,9 @@ DEPENDS += "curl expat zlib libarchive xz ncurses bzip2"
 
 SRC_URI_append_class-nativesdk = " \
     file://OEToolchainConfig.cmake \
-    file://environment.d-cmake.sh"
+    file://environment.d-cmake.sh \
+    file://0001-CMakeDetermineSystem-use-oe-environment-vars-to-load.patch \
+"
 
 # Strip ${prefix} from ${docdir}, set result into docdir_stripped
 python () {