使用 dockcross 从 ExternalProject_Add 构建项目

Build project from ExternalProject_Add using dockcross

我正在尝试使用 ExternalProject_Add 构建 tinyxml2。它在我的主系统 (Arch Linux) 上工作正常,但是当 运行 它在 dockcross 中时我遇到了一些问题(更具体地说,dockcross/linux-armv6)。

以下最小 CMakeLists.txt 工作(配置和构建)来自 dockcross:

cmake_minimum_required(VERSION 3.1)

project(external-tinyxml2)
include(ExternalProject)

ExternalProject_add(
    tinyxml2
    URL https://github.com/leethomason/tinyxml2/archive/7.0.1.tar.gz
    PREFIX tinyxml2
    )

但以下不是(注意添加的行:CONFIGURE_COMMAND ${CMAKE_COMMAND} -S<SOURCE_DIR>):

cmake_minimum_required(VERSION 3.1)

project(external-tinyxml2)
include(ExternalProject)

ExternalProject_add(
    tinyxml2
    URL https://github.com/leethomason/tinyxml2/archive/7.0.1.tar.gz
    PREFIX tinyxml2
    CONFIGURE_COMMAND ${CMAKE_COMMAND} -S<SOURCE_DIR>
    )

它实际上会导致以下错误输出:

[ 25%] No patch step for 'tinyxml2'
[ 37%] No update step for 'tinyxml2'
[ 50%] Performing configure step for 'tinyxml2'
CMake Deprecation Warning at CMakeLists.txt:11 (cmake_policy):
  The OLD behavior for policy CMP0063 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.


CMake Error at /usr/share/cmake-3.13/Modules/CMakeDetermineCompilerId.cmake:161 (file):
  file problem creating directory: /CMakeFiles/3.13.2/CompilerIdC
Call Stack (most recent call first):
  /usr/share/cmake-3.13/Modules/CMakeDetermineCompilerId.cmake:31 (CMAKE_DETERMINE_COMPILER_ID_BUILD)
  /usr/share/cmake-3.13/Modules/CMakeDetermineCCompiler.cmake:112 (CMAKE_DETERMINE_COMPILER_ID)
  CMakeLists.txt:14 (project)

[... other similar errors ...]

CMake Error at /usr/share/cmake-3.13/Modules/CMakeTestCCompiler.cmake:37 (try_compile):
  Failed to set working directory to /CMakeFiles/CMakeTmp/testCCompiler.c :
  No such file or directory
Call Stack (most recent call first):
  CMakeLists.txt:14 (project)


-- Configuring incomplete, errors occurred!
CMake Error: Cannot open file for write: /CMakeCache.txt.tmp
CMake Error: : System Error: Permission denied
CMake Error: Unable to open cache file for save. /CMakeCache.txt
CMake Error: : System Error: Permission denied
CMakeFiles/tinyxml2.dir/build.make:108: recipe for target 'tinyxml2/src/tinyxml2-stamp/tinyxml2-configure' failed
make[2]: *** [tinyxml2/src/tinyxml2-stamp/tinyxml2-configure] Error 1
make[2]: Leaving directory '/work/build'
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/tinyxml2.dir/all' failed
make[1]: *** [CMakeFiles/tinyxml2.dir/all] Error 2
make[1]: Leaving directory '/work/build'
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
make: Leaving directory '/work/build

直接从 dockcross 构建 tinyxml2(即不使用 ExternalProject_Add)效果很好。

那里可能出了什么问题?

据报告(并已修复),这实际上是 CMake 中的一个错误 here

对于有 bug 的 CMake 版本,解决方法是 运行 像这样(注意 -S<SOURCE_DIR> 变成 <SOURCE_DIR>):

ExternalProject_add(
    tinyxml2
    URL https://github.com/leethomason/tinyxml2/archive/7.0.1.tar.gz
    PREFIX tinyxml2
    CONFIGURE_COMMAND ${CMAKE_COMMAND} <SOURCE_DIR>
    )