0

I know this general question has been asked before, but I have a specific unanswered issue that I can't find already posted.

I'm trying to link a local git submodule of the Lua source in myproj/dependencies/lua to my myproj/helloworld.c file. I'm making it get the Lua in my local directory because I was having issues where Fedora could find my system Lua headers with the FindLua.cmake but Ubuntu couldn't. I imagine this problem will only be compounded when I try and bring macOS and Windows into the mix down the road.

The FindLua.cmake module is still useful, so I want to force it to only search in the myproj/dependencies/lua directory. Which to my understanding means setting LUA_INCLUDE_DIRSby hand in my CMakeLists.txt.

So Issue A is I've tried many iterations of the below syntax in most of the ways I could think of:

set(LUA_INCLUDE_DIRS "{$CMAKE_SOURCE_DIR}/dependencies/lua")

Yet cmake . doesn't output anything suggesting it found Lua, and then make fails with fatal error: lua.h no such file or directory

Issue B is that even once it does find it, it's going to find this which has to be compiled on cue from CMake in a way that it produces something it can use to link. Just running make on it only produces a single executable. I've seen some people linking the headers, and some people linking .a or .so files. It's unclear which of these I should use in this situation and why.

(My reasoning in approaching Issue B this way is I want to ship Lua with the code, so that it can be compiled without having to install system Lua headers, update them to a new version, or hunt them down. It's going to be embedded in a C application. So it doesn't really need dynamic features)

Just to be thorough, here's the rest of the CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
project (learnopengl)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_executable(learnopengl
    helloworld.c
)

add_subdirectory(dependencies/glfw)
add_subdirectory(dependencies/glad)
set(LUA_INCLUDE_DIRS "{$CMAKE_SOURCE_DIR}/dependencies/lua")

find_package(Lua)
if (LUA_FOUND)
    include_directories(${LUA_INCLUDE_DIRS})
    target_link_libraries (learnopengl ${LUA_LIBRARIES})
endif (LUA_FOUND)

target_link_libraries(learnopengl glad)
target_link_libraries(learnopengl glfw)
oLen
  • 5,177
  • 1
  • 32
  • 48
Joshua Murphy
  • 23
  • 1
  • 6
  • As stated in the [FindLua.cmake](https://github.com/Kitware/CMake/blob/master/Modules/FindLua.cmake) script, it sets `LUA_INCLUDE_DIR` variable (not `LUA_INCLUDE_DIRS` one). As for hinting the script about Lua location, you may use LUA_DIR *environment* variable or generic [CMAKE_PREFIX_PATH](https://stackoverflow.com/questions/34795816/hinting-findname-cmake-files-with-a-custom-directory/34797156#34797156). – Tsyvarev Oct 31 '17 at 21:57
  • Hello, I fixed the typo and set both `LUA_INCLUDE_DIR` and `LUA_DIR` to what they should have been and appended the path onto my `CMAKE_PREFIX_PATH` with this like: `list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/dependencies/lua")` but the problem is still persisting, even after swapping out `LUA_INCLUDE_DIR` for `LUA_DIR` in the `include_directories` – Joshua Murphy Oct 31 '17 at 22:27
  • Instead of checking *LUA_FOUND* variable, just add *REQUIRED* keyword to the `find_package(Lua)` call. So, if Lua wouldn't found, CMake prints error message. And **do not set** `LUA_INCLUDE_DIR` manually, it should be set by `find_package()` call. – Tsyvarev Oct 31 '17 at 23:13

0 Answers0