Download and build Lua with modern CMake

雨燕双飞 提交于 2020-12-13 04:01:33

问题


Let's try to build lua via cmake!

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.

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)

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

But the build fails:

[ 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

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/

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


回答1:


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


来源:https://stackoverflow.com/questions/59436450/download-and-build-lua-with-modern-cmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!