Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua bindings #527

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build/
# Object files
*.o
*.lib
*.so.*
*.so
*.lo
*.la
Expand All @@ -20,3 +21,17 @@ package.json
binding.gyp
READMEFIRST
npm-debug.log

# lua files
src/lua/mraaLUA_wrap.cxx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kind of confused why all these are needed, if you use a build/ directory then everything will get ignored. Let's keep this stuff out unless there's a good reason

Copy link
Author

@dedok dedok Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i do not use build/ directory :)
Okay if you don't like these changes I can remove them out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

building in tree is not recommended for cmake (or any other builds really tbh), any good reason why you can't just build somewhere outside of git or simply add an ignore for your build directory? In any case such stuff doesn't belong in commits adding Lua support so please remove.


# CMake
CMakeFiles
CMakeCache.txt
cmake_install.cmake
CTestTestfile.cmake
Makefile

# Gen files
arch.c
src/mraa.pc
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ option (BUILDSWIG "Build swig modules." ON)
option (BUILDSWIGPYTHON "Build swig python modules." ON)
option (BUILDSWIGNODE "Build swig node modules." ON)
option (BUILDSWIGJAVA "Build Java API." OFF)
option (BUILDSWIGLUA "Build Lua API." OFF)
option (USBPLAT "Detection USB platform." OFF)
option (FIRMATA "Add Firmata support to mraa." OFF)
option (ONEWIRE "Add Onewire support to mraa." ON)
Expand All @@ -87,6 +88,7 @@ if (NOT BUILDSWIG)
set (BUILDSWIGPYTHON OFF)
set (BUILDSWIGNODE OFF)
set (BUILDSWIGJAVA OFF)
set (BUILDSWIGLUA OFF)
endif()

if (NOT BUILDARCH)
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ if (BUILDSWIG)
message (SEND_ERROR "SWIG is ${SWIG_VERSION}. Please upgrade to 3.0.5+ to build nodejs addon")
endif ()
endif ()
if (BUILDSWIGLUA)
add_subdirectory (lua)
endif()
endif ()
endif ()

Expand Down
50 changes: 50 additions & 0 deletions src/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
find_package (Lua REQUIRED)

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/..
${LUA_INCLUDE_DIR}
)

set_source_files_properties (mraa.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (mraa.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
swig_add_module (lua-mraa lua mraa.i)
swig_link_libraries (lua-mraa mraa ${LUA_LIBRARIES})

if (DOXYGEN_FOUND)
foreach (_file ${DOCCLASSES})
add_dependencies (${SWIG_MODULE_lua-mraa_REAL_NAME} ${_file}class_doc_i)
endforeach ()
add_dependencies (${SWIG_MODULE_lua-mraa_REAL_NAME} common_hpp_doc_i)

add_custom_target (pydoc
pydoc -w ${CMAKE_CURRENT_BINARY_DIR}/mraa.py ${CMAKE_CURRENT_BINARY_DIR}/
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with pydoc" VERBATIM
)
endif ()

set_target_properties (${SWIG_MODULE_lua-mraa_REAL_NAME} PROPERTIES
OUTPUT_NAME mraa
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIG=${SWIG_FOUND}"
)

execute_process (
COMMAND lua -e
"string.gsub(package.path, '[^;]+', function(e)
if e:find('/usr/local') == 1 then
p = e:gsub('(?.lua)', '')
io.write(p)
os.exit(0)
end
end)
os.exit(1)
"
OUTPUT_VARIABLE LUA_SITE_DIR
)

install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.so
DESTINATION ${LUA_SITE_DIR})

message(STATUS "Lua site dir: ${LUA_SITE_DIR}")

add_subdirectory (docs)
41 changes: 41 additions & 0 deletions src/lua/docs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
if (DOXYGEN_FOUND)
find_package (Sphinx)
if (SPHINX_FOUND)
if (NOT DEFINED SPHINX_THEME)
set (SPHINX_THEME default)
endif ()

if (NOT DEFINED SPHINX_THEME_DIR)
set (SPHINX_THEME_DIR)
endif ()

# configured documentation tools and intermediate build results
set (BINARY_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}")

# Sphinx cache with pickled ReST documents
set (SPHINX_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/doctrees")

# HTML output directory
set (SPHINX_HTML_DIR "${CMAKE_CURRENT_BINARY_DIR}/html")

# doc .rst locations
set (SPHINX_DOC_LOATION "${CMAKE_CURRENT_SOURCE_DIR}")

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in"
"${BINARY_BUILD_DIR}/conf.py"
@ONLY
)

add_custom_target(sphinx ALL
${SPHINX_EXECUTABLE} -b html
-c "${BINARY_BUILD_DIR}"
-d "${SPHINX_CACHE_DIR}"
"${SPHINX_DOC_LOATION}"
"${SPHINX_HTML_DIR}"
COMMENT "Building HTML documentation with Sphinx"
)

add_dependencies (sphinx ${SWIG_MODULE_python-mraa_REAL_NAME})
Copy link
Contributor

@arfoll arfoll Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems odd - do the docs build work for LUA? at least the target is wrong here. edit: I see it's fixed later. so these work?

endif ()
endif ()