24.09., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

Commit 82a6d86c authored by Artur Grunau's avatar Artur Grunau

CMake skeleton of the scripting feature

An option to enable CAMPVis scripting has been added to the top level
CMakeLists.txt. Moreover, a minimal sub-project for the scripting
feature has been created. There's also a new CMake macro, FindLua, that
locates Lua's include and library files.
parent 564215a7
......@@ -16,6 +16,7 @@ OPTION(CAMPVIS_DEBUG "Activate debug code?"
OPTION(CAMPVIS_BUILD_APPLICATION "Build CAMPVis Application" ON)
OPTION(CAMPVIS_BUILD_CORE "Build CAMPVis Core" ON)
OPTION(CAMPVIS_BUILD_MODULES "Build CAMPVis Modules" ON)
OPTION(CAMPVIS_ENABLE_SCRIPTING "Add support for scripting CAMPVis using Lua" ON)
OPTION(CAMPVIS_BUILD_LIB_TGT "Build TGT Library" ON)
OPTION(CAMPVIS_BUILD_LIB_LUA "Build Lua Library" OFF)
OPTION(CAMPVIS_BUILD_DOXYGEN "Build Doxygen Documentation" OFF)
......@@ -75,6 +76,10 @@ IF(CAMPVIS_BUILD_DOXYGEN)
ADD_SUBDIRECTORY(doc EXCLUDE_FROM_ALL)
ENDIF()
IF(CAMPVIS_ENABLE_SCRIPTING)
ADD_SUBDIRECTORY(scripting)
ENDIF()
#
# Copy External DLLs
......
# Try to find LUA library and include path. Once done this will define:
# LUA_FOUND
# LUA_DEFINITIONS
# LUA_INCLUDE_DIR
# LUA_LIBRARY
IF(WIN32)
SET(LUA_DIR "${CampvisHome}/ext/lua" CACHE PATH "If Lua is not found, set this path")
SET(LUA_INCLUDE_DIR "${LUA_DIR}/src" ${LUA_DIR})
IF(LUA_INCLUDE_DIR)
SET(LUA_LIBRARY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lua.lib")
SET(LUA_FOUND TRUE)
ELSE()
SET(LUA_FOUND FALSE)
ENDIF()
ELSE(WIN32)
# TODO: not tested
MESSAGE(FATAL_ERROR "FindLua.cmake doesn't support platforms other than Windows yet")
ENDIF(WIN32)
MARK_AS_ADVANCED(LUA_DIR LUA_INCLUDE_DIR LUA_LIBRARY)
PROJECT(campvis-scripting)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)
MESSAGE(STATUS "Configuring CAMPVis Scripting")
# Lua
FIND_PACKAGE(Lua REQUIRED)
IF(LUA_FOUND)
MESSAGE(STATUS "* Found Lua")
LIST(APPEND CampvisGlobalDefinitions ${LUA_DEFINITIONS})
LIST(APPEND CampvisGlobalIncludeDirs ${LUA_INCLUDE_DIR})
LIST(APPEND CampvisGlobalExternalLibs ${LUA_LIBRARY})
ELSE(LUA_FOUND)
MESSAGE(FATAL_ERROR "Lua not found!")
ENDIF(LUA_FOUND)
FILE(GLOB CampvisScriptingSources
*.cpp
*.c
)
FILE(GLOB CampvisScriptingHeaders
*.h
)
ADD_EXECUTABLE(campvis-scripting ${CampvisScriptingSources} ${CampvisScriptingHeaders})
ADD_DEFINITIONS(${CampvisGlobalDefinitions} ${CampvisScriptingDefinitions})
INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs})
TARGET_LINK_LIBRARIES(campvis-scripting campvis-core tgt ${CampvisGlobalExternalLibs})
-- Start
-- Script: script.lua
print("I am using Lua from within C")
-- End
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
int main()
{
int s = 0;
lua_State* L = luaL_newstate();
// load the libs
luaL_openlibs(L);
// run a Lua script here
luaL_dofile(L, "script.lua");
printf("\nI am done with Lua in C++.\n");
lua_close(L);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment