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_DIRS
by 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)