lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Apr 29, 2014 at 11:30:07AM +0200, Axel Kittenberger wrote:
> 
>    Hello,
>    has anybody an example project out there that uses cmake and depends on
>    (lib)lua?
>    I get it that cmake has a module findlua, but I don't know how to use
>    it. I'm completely new to cmake.
>    ( So far I've been using autotools for my project (Lsyncd), I think
>    that I had the only project using autotools to find lua ;-) it got
>    obnoxious enough with cascaded ifs, especially checking if the found
>    luac and liblua are compatible, checking if LUA_COMPAT was turned on if
>    is was not 5.1 etc., I got enough of autotools and decided to give
>    cmake a chance )

Not quite what you were asking for, but I maintain a POSIX shell script that
will locate Lua header files, Lua interpreters, and luac compilers,
including making sure that the correct versions are found. It'll use
pkg-config as well as search the filesystem, test the located files to
ensure they're the correct version, and if not continue searching. It makes
it really easy to compile even in the presence of multiple Lua and LuaJIT
installations.

http://www.25thandclement.com/~william/projects/luapath.html

I use it directly inside a custom GNUmakefile, rather than messing around
with autotools or cmake. Usually like this (using GNU-style macros):

#
# Usage: $(call LUAPATH, 5.2, cppflags)
#
LUAPATH = $(shell env CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" luapath -krxm3 \
  -I$(DESTDIR)$(includedir) -I$(includedir) -I/usr/include \
  -I/usr/local/include -P$(DESTDIR)$(bindir) -P$(bindir) -v$(1) $(2))

#
# Grok dynamic linker flags
#
ifeq ($(shell uname -s), Darwin)
SOFLAGS = -bundle -undefined dynamic_lookup
else # BSD, GNU, Solaris
SOFLAGS = -shared
endif

#
# Sample build rules
#
# NOTE: I usually make the following a template, so I can easily support
# 5.1, 5.2, and 5.3 targets. But for simplicity I've hardcoded for 5.2.
#
foo.so: foo.o
	$(CC) -o $@ $< $(SOFLAGS) $(LDFLAGS)

foo.o: foo.c
	test 5.2 = $(call LUAPATH, 5.2, version) # test for 5.2 headers
	$(CC) $(CFLAGS) $(call LUAPATH, 5.2, cppflags) $(CPPFLAGS) -c -o $@ $<

$(DESTDIR)$(luapath)/foo.lua: foo.lua
	$(or $(call LUAPATH, 5.2, luac), true) -p $< # luac might not exist
	$(MKDIR) -p $(@D)
	$(CP) -p $< $@

#
# Sample install rules
#
$(DESTDIR)$(luacpath)/foo.so: foo.so
	$(MKDIR) -p $(@D)
	$(CP) -p $< $@