Skip to content

Commit aed0455

Browse files
committed
build - update dist.cmake to latest
1 parent 2d781da commit aed0455

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

dist.cmake

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ macro ( install_lua_executable _name _source )
9191
find_package ( Lua51 REQUIRED )
9292
include_directories ( ${LUA_INCLUDE_DIR} )
9393

94-
get_filename_component ( _source_name ${_source} NAME_WE )
9594
set ( _wrapper ${CMAKE_CURRENT_BINARY_DIR}/${_name}.c )
9695
set ( _code
9796
"// Not so simple executable wrapper for Lua apps
@@ -141,7 +140,7 @@ static int report (lua_State *L, int status) {
141140
if (status && !lua_isnil(L, -1)) {
142141
const char *msg = lua_tostring(L, -1)\;
143142
if (msg == NULL) msg = \"(error object is not a string)\"\;
144-
l_message(\"${_name}\", msg)\;
143+
l_message(\"${_source_name}\", msg)\;
145144
lua_pop(L, 1)\;
146145
}
147146
return status\;
@@ -184,10 +183,25 @@ L=lua_open()\;
184183
lua_gc(L, LUA_GCSTOP, 0)\;
185184
luaL_openlibs(L)\;
186185
lua_gc(L, LUA_GCRESTART, 0)\;
187-
getargs(L, argv, 0)\;
186+
int narg = getargs(L, argv, 0)\;
188187
lua_setglobal(L, \"arg\")\;
189-
// _PROGDIR global is only available when loadlib_rel.c is used in Lua
190-
int status = luaL_dostring(L, \"return dofile ( (_PROGDIR or '.') .. '/${_source_name}.lua')\")\;
188+
189+
// Script
190+
char script[500] = \"./${_source_name}.lua\"\;
191+
lua_getglobal(L, \"_PROGDIR\")\;
192+
if (lua_isstring(L, -1)) {
193+
sprintf( script, \"%s/${_source_name}.lua\", lua_tostring(L, -1))\;
194+
}
195+
lua_pop(L, 1)\;
196+
197+
// Run
198+
int status = luaL_loadfile(L, script)\;
199+
lua_insert(L, -(narg+1))\;
200+
if (status == 0)
201+
status = docall(L, narg, 0)\;
202+
else
203+
lua_pop(L, narg)\;
204+
191205
report(L, status)\;
192206
lua_close(L)\;
193207
return status\;
@@ -377,13 +391,15 @@ return dofile '${TESTFILEABS}'
377391
if ( ${ARGC} GREATER 1 )
378392
set ( _testcurrentdir ${ARGV1} )
379393
get_filename_component ( TESTCURRENTDIRABS ${_testcurrentdir} ABSOLUTE )
380-
set ( TESTWRAPPERSOURCE
381-
"require 'lfs'
382-
lfs.chdir('${TESTCURRENTDIRABS}' )
383-
${TESTWRAPPERSOURCE}" )
394+
# note: CMake 2.6 (unlike 2.8) lacks WORKING_DIRECTORY parameter.
395+
#old:
396+
# set ( TESTWRAPPERSOURCE
397+
#"require 'lfs'; lfs.chdir('${TESTCURRENTDIRABS}' )
398+
#${TESTWRAPPERSOURCE}" )
399+
set ( _pre ${CMAKE_COMMAND} -E chdir "${TESTCURRENTDIRABS}" )
384400
endif ()
385401
file ( WRITE ${TESTWRAPPER} ${TESTWRAPPERSOURCE})
386-
add_test ( NAME ${TESTFILEBASE} COMMAND ${LUA} ${TESTWRAPPER} $<CONFIGURATION> )
402+
add_test ( NAME ${TESTFILEBASE} COMMAND ${_pre} ${LUA} ${TESTWRAPPER} $<CONFIGURATION> )
387403
endif ()
388404
# see also http://gdcm.svn.sourceforge.net/viewvc/gdcm/Sandbox/CMakeModules/UsePythonTest.cmake
389405
endmacro ()

0 commit comments

Comments
 (0)