Commit 2be90976 authored by Artur Grunau's avatar Artur Grunau
Browse files

Clean up how CAMPVis' Lua modules are built

There were several problems with how CAMPVis' Lua modules were built:
- modules were placed in the same directory as all other CAMPVis'
  libraries, which polluted Lua's module path and could lead to name
  clashes
- SWIG interface files included instead of importing one another; this
  resulted in duplicated bindings being generated

To fix these probles place all of CAMPVis' Lua modules in one
sub-directory and let the code know what that sub-directory is so that
it can instruct Lua to search it. Moreover, use %import instead of
%include when one SWIG interface file needs to have access to
definitions from another one.

References #1
parent 36d964b1
......@@ -19,6 +19,7 @@ FIND_PACKAGE(SWIG REQUIRED)
MESSAGE(STATUS "* Found SWIG")
INCLUDE(${SWIG_USE_FILE})
FILE(GLOB CampvisScriptingSources
*.cpp
*.c
......@@ -28,13 +29,46 @@ FILE(GLOB CampvisScriptingHeaders
*.h
)
# Declare Lua modules to be generated by SWIG
SET_SOURCE_FILES_PROPERTIES(tgt.i PROPERTIES CPLUSPLUS ON)
SWIG_ADD_MODULE(tgt-lua-mod lua tgt.i)
SWIG_LINK_LIBRARIES(tgt-lua-mod tgt ${CampvisGlobalExternalLibs})
SET_SOURCE_FILES_PROPERTIES(campvis.i PROPERTIES CPLUSPLUS ON)
SWIG_ADD_MODULE(campvis lua campvis.i)
SWIG_LINK_LIBRARIES(campvis campvis-core tgt ${CampvisGlobalExternalLibs})
SWIG_ADD_MODULE(campvis-lua-mod lua campvis.i)
SWIG_LINK_LIBRARIES(campvis-lua-mod campvis-core tgt ${CampvisGlobalExternalLibs})
SET_SOURCE_FILES_PROPERTIES(vis.i PROPERTIES CPLUSPLUS ON)
SWIG_ADD_MODULE(vis lua vis.i)
SWIG_LINK_LIBRARIES(vis campvis-core campvis-modules tgt ${CampvisGlobalExternalLibs})
SWIG_ADD_MODULE(vis-lua-mod lua vis.i)
SWIG_LINK_LIBRARIES(vis-lua-mod campvis-core campvis-modules tgt ${CampvisGlobalExternalLibs})
# Place all of CAMPVis' Lua modules in one sub-directory and shorten their names. This is done to
# make Lua modules easier to import and avoid mixing them with other CAMPVis' libraries.
SET(CampvisLuaModules tgt-lua-mod campvis-lua-mod vis-lua-mod)
SET(CampvisLuaModulesDirectory "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/lua-mods/")
# Lua modules will be placed in a sub-directory that won't be picked up by Lua automatically. Let
# the code know via a #define what that sub-directory is so that it can instruct Lua to search it.
LIST(APPEND CampvisScriptingDefinitions "-DCAMPVIS_LUA_MODS_PATH=\"${CampvisLuaModulesDirectory}?${CMAKE_SHARED_MODULE_SUFFIX}\"")
FOREACH(LuaMod ${CampvisLuaModules})
STRING(REPLACE "-lua-mod" "" LuaModShortName ${LuaMod})
SET(LuaModFullPath "${CampvisLuaModulesDirectory}${CMAKE_SHARED_LIBRARY_PREFIX}${LuaModShortName}${CMAKE_SHARED_LIBRARY_SUFFIX}")
# The most reliable approach to changing a target's output directory to a sub-directory of the
# main build folder if a multi-config generator (e.g. Visual Studio or XCode) may be used is
# to invoke a custom command to copy the necessary files after the build finishes. For more
# details see: http://www.cmake.org/pipermail/cmake/2008-June/022358.html
ADD_CUSTOM_COMMAND(
TARGET ${LuaMod}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CampvisLuaModulesDirectory}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${LuaMod}> ${LuaModFullPath}
)
ENDFOREACH(LuaMod ${CampvisLuaModules})
# Generate header with SWIG run-time functions
ADD_CUSTOM_COMMAND(
......@@ -53,12 +87,3 @@ ADD_LIBRARY(campvis-scripting
${CampvisScriptingSources} ${CampvisScriptingHeaders}
)
TARGET_LINK_LIBRARIES(campvis-scripting campvis-core campvis-modules tgt ${CampvisGlobalExternalLibs})
# If a multi-config generator is used (e.g. Visual Studio or XCode), CAMPVis Lua modules will be
# placed in a sub-directory that won't be picked up by Lua automatically. Let the code know via
# a #define what that sub-directory is so that it can instruct Lua to search it.
FOREACH(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES})
STRING(TOUPPER ${CONFIG_TYPE} CONFIG_TYPE_UPPER)
SET_DIRECTORY_PROPERTIES(PROPERTIES COMPILE_DEFINITIONS_${CONFIG_TYPE_UPPER}
"CAMPVIS_LUA_MODS_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CONFIG_TYPE}/?${CMAKE_SHARED_MODULE_SUFFIX}")
ENDFOREACH(CONFIG_TYPE CMAKE_CONFIGURATION_TYPES)
%module campvis
%include factory.i
%include std_string.i
%include tgt.i
%import tgt.i
%{
#include "core/properties/genericproperty.h"
#include "core/properties/numericproperty.h"
......
......@@ -26,26 +26,12 @@ namespace campvis {
// load the libs
luaL_openlibs(_luaState);
/*
* Defined if CAMPVis Lua modules are placed in a location that won't be picked up by Lua
* automatically
*/
#ifdef CAMPVIS_LUA_MODS_PATH
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
/* Let Lua know where CAMPVis modules are located */
if (luaL_dostring(_luaState, "package.cpath = package.cpath .. ';" TOSTRING(CAMPVIS_LUA_MODS_PATH) "'")) {
if (luaL_dostring(_luaState, "package.cpath = '" CAMPVIS_LUA_MODS_PATH "'")) {
this->logLuaError();
return;
}
#undef TOSTRING
#undef STRINGIFY
#endif // CAMPVIS_LUA_MODS_PATH
if (luaL_dostring(_luaState, "require(\"campvis\")")) {
this->logLuaError();
return;
......
require("tgt")
require("vis")
pipeline = campvis.newPipeline()
......@@ -7,12 +8,12 @@ function pipeline:ctor()
self.image_reader = vis.MhdImageReader()
self.addProcessor(instance, self.image_reader)
local iv = campvis.ivec2(50, 10)
local iv = tgt.ivec2(50, 10)
print(vis.first(iv))
print(vis.first(campvis.ivec2_zero))
print(vis.first(tgt.ivec2_zero))
local ivp = campvis.IVec2Property("a", "b", iv, campvis.ivec2_zero, campvis.ivec2(100, 30))
local ivp = campvis.IVec2Property("a", "b", iv, tgt.ivec2_zero, tgt.ivec2(100, 30))
self.ve = vis.VolumeExplorer(ivp)
self.resampler = vis.GlImageResampler(ivp)
......
%module vis
%include std_string.i
%include campvis.i
%import campvis.i
%{
#include "modules/io/processors/mhdimagereader.h"
#include "modules/preprocessing/processors/glimageresampler.h"
......
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