使用现代CMake下载并构建Lua [英] Download and build Lua with modern CMake

查看:126
本文介绍了使用现代CMake下载并构建Lua的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们尝试通过cmake构建lua!

Let's try to build lua via cmake!

动机:cmake通过诸如CLion 甚至是Visual的IDE越来越受到关注和支持Studio 2017(及更高版本).

Motivation: cmake is gaining more attention and support through IDEs like CLion or even Visual Studio 2017 (and newer).

如果您要提供独立于平台的开放源代码并简化整个构建过程,那就太好了.

This is great if you want to provide platform-independent open-sources and faciliate the entire build-process.

现在的问题是,我认为创建适当的 CMakeLists.txt 并不是那么简单:

Now the problem is that creating a proper CMakeLists.txt isn't that straightforward in my opinion:

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文件,将其提取并尝试 make (构建),真棒.

When you cmake ./ and make, this automatically downloads the .tar.gz-file, extracts it and tries to make (build) it, which is awesome.

但是构建失败:

[ 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在错误的文件夹中查找.自动下载后,文件夹结构如下:

I feel that make/cmake is looking in the wrong folder. After the automatic download the folder structure looks like this:

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

上面的CMakeList中缺少什么?您总体上会如何做?

What is missing in the CMakeLists above? How would you do it in general?

推荐答案

Tsyvarev的提示很有用!此 CMakeLists.txt 现在可以使用:

Tsyvarev's hint was useful! This CMakeLists.txt works now:

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\'")

这篇关于使用现代CMake下载并构建Lua的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆