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?