用现代化的CMake工具下载和构建Lua

让我们尝试通过CMake来构建Lua!

动机:CMake通过IDE(如CLion或者甚至是Visual Studio 2017及更高版本)获得更多的关注和支持。这对于提供跨平台的开源代码以及促进整个构建过程非常有利。

现在的问题是,在我看来,创建一个正确的CMakeLists.txt并不那么简单:

cmake_minimum_required(VERSION 3.16)
include(ExternalProject)

set(LUA_VERSION "lua-5.3.5")

ExternalProject_Add(lua
  URL https://www.lua.org/ftp/${LUA_VERSION}.tar.gz
  CONFIGURE_COMMAND ""
  BUILD_COMMAND make
  BUILD_ALWAYS true
)
add_library(liblua STATIC IMPORTED)

当你执行cmake ./make时,这将自动下载.tar.gz文件,解压缩它,并尝试进行构建,这非常棒。

但是构建失败了:

[ 75%] Performing build step for 'lua'
make[3]: *** No targets were specified and no "make" control file was found.  End.
CMakeFiles/lua.dir/build.make:113: recipe for target 'lua-prefix/src/lua-stamp/lua-build' failed

我感觉make/cmake在错误的文件夹中寻找。 在自动下载后,文件夹的结构如下所示:

CMakeLists.txt
…
lua-prefix/
   src/
     lua/
        doc/
        src/
           lua.c
           luac.c
           …
           Makefile
        Makefile
        README
     lua-build/
     lua-stamp/
       …
   tmp/

上面的CMakeLists.txt文件缺少什么?通常你会如何处理?

原文链接 https://stackoverflow.com/questions/59436450

点赞
stackoverflow用户1511417
stackoverflow用户1511417

Tsyvarev的提示很有用!现在这个CMakeLists.txt可以工作了:

cmake_minimum_required(VERSION 3.10)
include(ExternalProject)

ExternalProject_Add(lua
   URL "https://www.lua.org/ftp/lua-5.3.5.tar.gz"
   CONFIGURE_COMMAND ""
   BUILD_COMMAND make generic
   BUILD_ALWAYS true
   BUILD_IN_SOURCE true
   INSTALL_COMMAND ""
)
add_library(liblua STATIC IMPORTED)
ExternalProject_Get_property(lua SOURCE_DIR)
message("liblua will be found at \'${SOURCE_DIR}/src\'")
2019-12-22 13:26:37