Skip to content

Commit

Permalink
Auto-detect Lua compatible with installed Luabind
Browse files Browse the repository at this point in the history
  • Loading branch information
alex85k committed Sep 18, 2014
1 parent 8e72c3d commit 5a690da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ else()
endif()

find_package( Luabind REQUIRED )
include(check_luabind)

include_directories(${LUABIND_INCLUDE_DIR})
target_link_libraries(osrm-extract ${LUABIND_LIBRARY})
target_link_libraries(osrm-prepare ${LUABIND_LIBRARY})
Expand Down
29 changes: 29 additions & 0 deletions cmake/check_luabind.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
INCLUDE (CheckCXXSourceCompiles)
unset(LUABIND_WORKS52 CACHE)
unset(LUABIND_WORKS51 CACHE)
SET (LUABIND_CHECK_SRC "#include \"lua.h\"\n#include <luabind/luabind.hpp>\n int main() { lua_State *myLuaState = luaL_newstate(); luabind::open(myLuaState); return 0;}")
SET (CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
SET (CMAKE_REQUIRED_INCLUDES "${Boost_INCLUDE_DIR};${LUABIND_INCLUDE_DIR};${LUA_INCLUDE_DIR}")
SET (CMAKE_REQUIRED_LIBRARIES "${LUABIND_LIBRARY};${LUA_LIBRARY}")

CHECK_CXX_SOURCE_COMPILES("${LUABIND_CHECK_SRC}" LUABIND_WORKS)

if( LUABIND_WORKS )
MESSAGE("Luabind works with ${LUA_LIBRARY}")
else()
MESSAGE("Luabind does not work with ${LUA_LIBRARY}, will try Lua 5.1.")
unset(LUA_FOUND CACHE)
unset(LUA_INCLUDE_DIR CACHE)
unset(LUA_LIBRARY CACHE)
find_package(Lua51)
SET (CMAKE_REQUIRED_INCLUDES "${Boost_INCLUDE_DIR};${LUABIND_INCLUDE_DIR};${LUA_INCLUDE_DIR}")
SET (CMAKE_REQUIRED_LIBRARIES "${LUABIND_LIBRARY};${LUA_LIBRARY}")

CHECK_CXX_SOURCE_COMPILES("${LUABIND_CHECK_SRC}" LUABIND51_WORKS)

if( LUABIND51_WORKS )
MESSAGE("Luabind works with Lua 5.1 at ${LUA_LIBRARY}")
else()
MESSAGE(FATAL_ERROR "Luabind does not work with Lua 5.1 at ${LUA_LIBRARY}, no working Luabind found")
endif()
endif()

0 comments on commit 5a690da

Please sign in to comment.