Search code examples
luacmake

Unable to find Lua headers with find_package in cmake


I'm trying to use CMake to build generate the make file for a project of mine that uses Lua. When I run make I get this error:

/path/to/my/project/luaudio/luaudio.c:1:17: fatal error: lua.h: No such file or directory

In the CMakeLists.txt file, I have the following lines, which I thought would do it, but apparently they're not enough:

find_package(Lua51 REQUIRED) 
set(Luaudio_INCLUDE_DIRS ${Luaudio_SOURCE_DIR} ${Lua51_INCLUDE_DIRS} PARENT_SCOPE)
include_directories(${Luaudio_INCLUDE_DIRS})

Lua51_Include_Dirs appears to be empty (attempting to run it though the message command doesn't print anything) so I suspect that it just can't find it. Do I need to specify where to look for Lua? I was under the impression that the whole point of find_package was that it would look in a set a predefined places so that I don't need to specify where it is specifically.

(This is on an Ubuntu machine and I do have the Lua packages installed.)


Solution

  • Exploring FindLua51.cmake from cmake 2.8 I found that it sets LUA_INCLUDE_DIR variable instead of Lua51_INCLUDE_DIRS. So cmake code should be

    find_package(Lua51 REQUIRED) 
    set(Luaudio_INCLUDE_DIRS ${Luaudio_SOURCE_DIR} ${LUA_INCLUDE_DIR} PARENT_SCOPE)
    include_directories(${Luaudio_INCLUDE_DIRS})