I split commits to several - style, refactoring, and bugfix.
Erasing LUA_INCLUDE_PREFIX from cache is needed, because in case with several lua installed, several lua.h files exists and without erasing find_path function will always find first occurence, that may be inappropriate version.
Thanks! Would you mind filing a Merge Request with the patches instead? It would help make reviewing a lot easier.
Erasing LUA_INCLUDE_PREFIX from cache is needed, because in case with several lua installed, several lua.h files exists and without erasing find_path function will always find first occurence, that may be inappropriate version.
I think this should only happen if the lua.h found there is invalid since I may have Lua installed in some path that isn't searched by default which means that it can't be found here (or the module keeps erasing my path and then using the wrong Lua).
Hello,
I still have some issues with the FindLua package. I'm using CMake 2.6.1.
EDIT: oh your patch hasn't been released...
I have an ArchLinux system with Lua 5.1, 5.2 and 5.3 installed.
I want to build a Lua C library with CMake. The library is written for Lua 5.1. I have two choices:
Compiling with Lua 5.1 headers,
Compiling with Lua 5.2/5.3 headers with compatibility flags (LUA_COMPAT_ALL for Lua 5.2 and LUA_COMPAT_51 for Lua 5.3)
Sadly, I'm quite new to CMake, so I may be wrong with the following, but:
My problem is that is seems impossible to compile a Lua library with the standard FindLua using simple code such as find_package(Lua "5.1" EXACT REQUIRED), given the directory archecture chosen by ArchLinux and Debian to handle multiple Lua versions.
CMake finds the good library files *.so but the include is always /usr/include and include paths for other versions like /usr/include/lua5.1 never appears. Even when using the old (mark it as depreciated ?) Lua51 package, LUA_INCLUDE_DIR stays at /usr/include and thus uses Lua 5.3 headers instead of Lua 5.1 headers.
When I try find_package(Lua "5.1" EXACT REQUIRED) I get:
CMake Error at /usr/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:148 (message): Could NOT find Lua: Found unsuitable version "5.3.3", but required is exact version "5.1" (found /usr/lib64/liblua5.1.so;/usr/lib64/libm.so)Call Stack (most recent call first): /usr/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:386 (_FPHSA_FAILURE_MESSAGE) /usr/share/cmake-3.6/Modules/FindLua.cmake:168 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) CMakeLists.txt:26 (FIND_PACKAGE)-- Configuring incomplete, errors occurred!
And with find_package(Lua "5.2" EXACT REQUIRED) I get:
CMake Error at /usr/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:148 (message): Could NOT find Lua: Found unsuitable version "5.3.3", but required is exact version "5.2" (found /usr/lib64/liblua5.2.so;/usr/lib64/libm.so)Call Stack (most recent call first): /usr/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:386 (_FPHSA_FAILURE_MESSAGE) /usr/share/cmake-3.6/Modules/FindLua.cmake:168 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) CMakeLists.txt:26 (FIND_PACKAGE)-- Configuring incomplete, errors occurred!
But with find_package(Lua "5.3" EXACT REQUIRED) it works as expected.
The conclusion is that you can't compile with Lua 5.1 or Lua 5.2 headers but you have to compile with Lua 5.3 headers while enabling compatibility flags.
I also noticed that when I do find_package(Lua), CMake chooses Lua 5.2 rather than Lua 5.3. The default Lua version used should be changed (Lua 5.3 seems not to be supported in FindLua).
-- Found Lua: /usr/lib64/liblua5.2.so;/usr/lib64/libm.so (found version "5.3.3")
So what happens when I do find_package(Lua) is that CMake uses liblua5.2.so instead of the latest version available but uses Lua 5.3 headers.
My final goal would be to have something like this, that would use the correct headers and the correct "*.so" file:
Hi,
I have tested with CMake master branch and there is still one little bug (with Lua 5.1, 5.2, and 5.3 installed as described before):
FIND_PACKAGE(Lua REQUIRED)MESSAGE(${LUA_VERSION_STRING} " " ${LUA_INCLUDE_DIR} " " ${LUA_LIBRARIES})# outputs:# Found Lua: /usr/lib64/liblua5.2.so;/usr/lib64/libm.so (found version "5.3.3") # 5.3.3 /usr/include /usr/lib64/liblua5.2.so/usr/lib64/libm.so
So CMake finds the latest version and uses the correct include paths (/usr/include where Lua 5.3 headers are) but links against the wrong liblua. I have this in the Makefile: cc -fPIC -shared -llua5.2 -lm.
But if you write FIND_PACKAGE(Lua "5.1" EXACT REQUIRED) or any later version, it works as expected :)
AFAIK, there is no portable way to determine shared object or dll version from cmake. So, when I wrote the patch, I leave behavior, that was already existed.
Btw, there is a proposal to add version matching into find_library() : #8396 (see mantis issue).
But it's possible to resrtict library names for searching according to found (from include file) version like that:
fft/cmake@8f3c7ad6
I think, this must work for most cases (exept you have liblua of version 5.2 inside file 'lua5.1.so' or something similar). If this is sufficient, I will do merge request.