Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

CMake #160

Open
moteus opened this issue Feb 7, 2014 · 13 comments
Open

CMake #160

moteus opened this issue Feb 7, 2014 · 13 comments

Comments

@moteus
Copy link

moteus commented Feb 7, 2014

I want maintain my modules to LuaDist. Before I never used cmake or luadist.
I start with module llthreads2.
This is my CMakeLists.txt based on this file:

cmake_minimum_required ( VERSION 2.8 )

project ( lua-llthreads2 C )
include ( cmake/dist.cmake )
include ( lua )

set ( CMAKE_THREAD_PREFER_PTHREAD TRUE )
include ( FindThreads )

include_directories ( ${CMAKE_CURRENT_SOURCE_DIR}/src )

set ( LUA_LLTHREADS_SRC src/l52util.c src/llthread.c )

install_lua_module ( llthreads ${LUA_LLTHREADS_SRC} LINK ${CMAKE_THREAD_LIBS_INIT} )
install_data ( COPYRIGHT.llthreads README.md LICENSE )
install_example ( examples/ )
install_test ( tests/ )

On my machine I have installed Lua 5.1/5.2 and when I run CMake I get:
-- Found Lua: G:/lua/5.2/lib/lua52.lib (found version "5.1.5")
And in project Include dirs point to G:/lua/5.1/include and lib is G:/lua/5.2/lib/lua52.lib

Whether it is possible to install LuaDist so that it used existing Lua?

@drahosp
Copy link
Member

drahosp commented Feb 7, 2014

The luadist utility was designed to create standalone installations, that means it will try to install its own lua. However if you use the CMake build manually you can specify which lua to link against. The detection process may not always find the desired library so for that purpose you can use the cmake-gui frontend to configure the build manually. In case of lua libraries the variables LUA_LIBRARY and LUA_INCLUDE_DIR are needed. You can override these using the commandline of luadist and cmake with the following syntax:

cmake -DLUA_LIBRARY=[PATH TO LIB] -DLUA_INCLUDE_DIR=[PATH TO DIR]

For more details on CMake FindLibrary behavior

@moteus
Copy link
Author

moteus commented Feb 7, 2014

In fact I need install some environment to write and test LuaDist packages.
Can I just run cmake like that:
cmake -DLUA_LIBRARY=%LUA_DIR%\lib\lua51.lib -DLUA_INCLUDE_DIR=%LUA_DIR%\include ..
And if it make correct than package correct?

@drahosp
Copy link
Member

drahosp commented Feb 7, 2014

You can also use luadist make [path to your module] -verbose to test it. Now I see you want to test against lua-5.1 and lua-5.2 also. For this I recommend setting up two directories, one with lua-5.1 and other with lua-5.2. To do this you can use luadist as follows:

# Setup different Lua versions to test against
luadist C:\Lua-5.1.5 install lua-5.1.5
luadist C:\Lua-5.2.3 install lua-5.2.3
luadist C:\LuaJIT-2.0.2 install luajit
# Test out the build against the lua versions
luadist C:\Lua-5.1.5 make [path to your module]
luadist C:\Lua-5.2.3 make [path to your module]
luadist C:\LuaJIT-2.0.2 make [path to your module]

This will call the CMake build of your project with settings that force the library detection mechanism in CMake to search for libraries in the destination locations first.

If the above works your package should be good to go. Also note that the luadist make command assumes you have installed the dependencies of your module already if there are any.

@moteus
Copy link
Author

moteus commented Feb 7, 2014

Thanks. this is what i need. But I get error when i try make my project.
I install Lua with LuaDist in separate dirs.
When I try my module i get

> luadist g:\lua\dist-5.1 make f:\Projects\lua-llthreads2 -verbose
cmake version 2.8.10.2
Building lua-llthreads2...
loading initial cache file cache.cmake
CMake Error: Error processing file:cache.cmake
CMake Error: your RC compiler: "rc" was not found.   Please set CMAKE_RC_COMPILER to a valid compiler path or name.
DIST_NAME: lua-llthreads2
DIST_VERSION: 0.1.1
DIST_LICENSE: MIT/X11
DIST_AUTHOR: Alexey Melnichuk
DIST_MAINTAINER: Alexey Melnichuk
DIST_URL: https://github.com/moteus/lua-llthreads2
DIST_DESC: A simple Lua wrapper for pthreads & WIN32 threads.
DIST_DEPENDS:
-- Configuring incomplete, errors occurred!
Error preloading the CMake cache script 'g:\lua\dist-5.1\tmp\lua-llthreads2-0.1.1-CMake-build\cmake.cache'

CMake create correct project.

@drahosp
Copy link
Member

drahosp commented Feb 7, 2014

What version of MinGW are you using? I have just tried to set up the project with your CMakeLists.txt on my box without issues (removed examples and tests). I am using MinGW Builds 4.8.1.

@moteus
Copy link
Author

moteus commented Feb 7, 2014

I'll chick it later.
But i also has msvc 2010 and cmake use it by default. May be this is reason?

@drahosp
Copy link
Member

drahosp commented Feb 7, 2014

Yes, it is default for CMake but LuaDist overrides it to "MinGW Makefiles" (see LuaDist/lib/lua/dist/config.lua). My guess is that you have leftover cmake cache files in the project directory that includes settings from your manual build. You should clean these out first (CMakeCache.txt, CPack_, CTest_, cmake_install.cmake). Usually when building with CMake we build "out of source" so the source is not poisoned with these files. The luadist utility does this so problems like this are avoided.

Note that LuaDist packages can be built with MSVC compiler also but we do not support it yet.

@moteus
Copy link
Author

moteus commented Feb 10, 2014

If i run from non project dir all works.

G:\lua>luadist g:\lua\dist-5.1 make f:\e\Projects\lua-llthreads2 -verbose
cmake version 2.8.10.2
Building lua-llthreads2...
loading initial cache file cache.cmake
-- The C compiler identification is GNU 4.6.2
-- Check for working C compiler: c:/MinGW/bin/gcc.exe
-- Check for working C compiler: c:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
DIST_NAME: lua-llthreads2
DIST_VERSION: 0.1.1
DIST_LICENSE: MIT/X11
DIST_AUTHOR: Alexey Melnichuk
DIST_MAINTAINER: Alexey Melnichuk
DIST_URL: https://github.com/moteus/lua-llthreads2
DIST_DESC: A simple Lua wrapper for pthreads & WIN32 threads.
DIST_DEPENDS:
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found Lua: G:/lua/dist-5.1/lib/liblua.dll.a (found version "5.1.5")
-- Configuring done
-- Generating done
-- Build files have been written to: G:/lua/dist-5.1/tmp/lua-llthreads2-0.1.1-CMake-build
Scanning dependencies of target llthreads2
[ 50%] [100%] Building C object CMakeFiles/llthreads2.dir/src/l52util.c.obj
Building C object CMakeFiles/llthreads2.dir/src/llthread.c.obj
Linking C shared module llthreads2.dll
[100%] Built target llthreads2
-- Install configuration: "MinSizeRel"
-- Install component: "Runtime"
-- Installing: G:/lua/dist-5.1/lib/lua/llthreads2.dll
-- Install configuration: "MinSizeRel"
-- Install component: "Library"
-- Install configuration: "MinSizeRel"
-- Install component: "Header"
-- Install configuration: "MinSizeRel"
-- Install component: "Data"
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/COPYRIGHT.llthreads
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/README.md
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/LICENSE
-- Install configuration: "MinSizeRel"
-- Install component: "Documentation"
-- Install configuration: "MinSizeRel"
-- Install component: "Example"
-- Install configuration: "MinSizeRel"
-- Install component: "Test"
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test/
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test//test_alive.lua
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test//test_join_detach.lua
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test//test_join_error.lua
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test//test_join_timeout.lua
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test//test_llthreads.lua
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test//test_load_llthreads2.lua
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test//test_logger.lua
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test//test_pass_cfunction.lua
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test//test_register_ffi.lua
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test//test_register_llthreads.lua
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test//test_table_copy.lua
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test//test_threads.lua
-- Installing: G:/lua/dist-5.1/share/lua-llthreads2/test//utils.lua
-- Install configuration: "MinSizeRel"
-- Install component: "Other"
-- Install configuration: "MinSizeRel"
-- Install component: "Unspecified"
Deployment successful.

luadist g:\lua\dist-5.1 remove lua-llthreads2
Removed modules: 1

But when i run from project dir i get error.
I clear all cmake caches from project dir.
Only additianal files are

CMakeLists.txt
cmake\FindLua.cmake
cmake\dist.cmake
cmake\lua.cmake
dist.info
G:\lua>cd /d F:\Projects\lua-llthreads2\

F:\Projects\lua-llthreads2>luadist g:\lua\dist-5.1 make . -verbose
cmake version 2.8.10.2
Building ....
loading initial cache file cache.cmake
CMake Error: Error processing file:cache.cmake
-- Building for: Visual Studio 10
-- The C compiler identification is MSVC 16.0.30319.1
-- Check for working C compiler using: Visual Studio 10
-- Check for working C compiler using: Visual Studio 10 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
DIST_NAME: lua-llthreads2
DIST_VERSION: 0.1.1
DIST_LICENSE: MIT/X11
DIST_AUTHOR: Alexey Melnichuk
DIST_MAINTAINER: Alexey Melnichuk
DIST_URL: https://github.com/moteus/lua-llthreads2
DIST_DESC: A simple Lua wrapper for pthreads & WIN32 threads.
DIST_DEPENDS:
-- Looking for include file pthread.h
-- Looking for include file pthread.h - not found
-- Found Threads: TRUE
-- Found Lua: G:/lua/5.2/lib/lua52.lib (found version "5.1.5")
-- Configuring incomplete, errors occurred!
Error preloading the CMake cache script 'G:\lua\dist-5.1\tmp\lua-llthreads2-0.1.1-CMake-build\cmake.cache'

@drahosp
Copy link
Member

drahosp commented Feb 10, 2014

I believe you have found a bug in the luadist utility, can you please post the contents of the cmake.cache file in the error message.

@moteus
Copy link
Author

moteus commented Feb 10, 2014

In error message file name is G:\lua\dist-5.1\tmp\lua-llthreads2-0.1.1-CMake-build\cmake.cache.
But real file is G:\lua\dist-5.1\tmp\lua-llthreads2-0.1.1-CMake-build\cache.cmake
Also luadist create local cmake files in project dir.

@moteus
Copy link
Author

moteus commented Feb 12, 2014

LuaDist dir g:\lua\dist; LuaDist tree for Lua 5.1 g:\lua\dist-5.1
luadist1 is simple bat file with luadist g:\lua\dist-5.1 %*
When i run luadist1 install luasql-odbc -verbose -binary=false from disk g: all works as expected.
But when I run this command from disk e: (my system disk) at first run I get error while try using MSVC 10 compiler and after that I get:

Downloading repository information...
Finding out available versions of luasql-odbc...
Getting luasql-odbc-2.3.0 (source)...
cmake version 2.8.10.2
Building luasql-odbc-2.3.0...
loading initial cache file cache.cmake
CMake Error: Error processing file:cache.cmake
CMake Error: The source "G:/lua/dist-5.1/tmp/luasql-odbc-2.3.0/CMakeLists.txt" does not match the source "F:/installs/LUA/ZeroMQ/llthread/CMakeLists.txt" used to generate cache.  Re-run cmake with a different source directory.
Error preloading the CMake cache script 'G:\lua\dist-5.1\tmp\luasql-odbc-2.3.0-CMake-build\cmake.cache'

F:/installs/LUA/ZeroMQ this is very old dir and i do no use it several months.
F:/installs/LUA/ZeroMQ/llthread/ directory does not exist.

@drahosp
Copy link
Member

drahosp commented Feb 13, 2014

This may be MinGW related issue. I have experienced failed builds and detections when using resources on multiple drives and network mounts. Generally I would advise you to keep all your resources and workdirs on a single drive when building.

@drahosp drahosp self-assigned this Feb 13, 2014
@cjrh
Copy link

cjrh commented Mar 12, 2014

As mentioned above, I am also finding a problem with expected cmake.cache versus actual cache.cmake:

Example:

F:\Binaries-LuaDist-batteries-0.9.8-Windows-x86\bin>luadist test05 install luajit-scm
Finding out available versions of luajit...
Getting luajit-scm (source)...
Building luajit-scm...
Error preloading the CMake cache script 'F:\Binaries-LuaDist-batteries-0.9.8-Windows-x86\bin\test05\tmp\luajit-2.0.2-CMake-build\cmake.cache'

F:\Binaries-LuaDist-batteries-0.9.8-Windows-x86\bin>dir test05\tmp\luajit-2.0.2-CMake-build\
 Volume in drive F is DATA
 Volume Serial Number is AA6C-8BC0

 Directory of F:\Binaries-LuaDist-batteries-0.9.8-Windows-x86\bin\test05\tmp\luajit-2.0.2-CMake-build

12/03/2014  04:08 PM    <DIR>          .
12/03/2014  04:08 PM    <DIR>          ..
12/03/2014  04:08 PM             1,459 cache.cmake
12/03/2014  04:08 PM             4,051 CMakeCache.txt
12/03/2014  04:08 PM    <DIR>          CMakeFiles
               2 File(s)          5,510 bytes
               3 Dir(s)  712,974,213,120 bytes free

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants