This commit is contained in:
albertodemichelis 2017-04-23 04:01:16 +08:00
commit 8471ad1aea
5 changed files with 55 additions and 25 deletions

View File

@ -9,7 +9,7 @@ set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
project(squirrel C CXX)
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
if(CMAKE_COMPILER_IS_GNUCXX)
set(SQ_FLAGS -fno-exceptions -fno-strict-aliasing -Wall -Wextra -pedantic -Wcast-qual)
@ -33,25 +33,28 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -std=c++0x")
elseif(MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions(-D_SQ64)
endif()
if(NOT DEFINED INSTALL_BIN_DIR)
set(INSTALL_BIN_DIR bin)
endif()
if(NOT DEFINED SQ_DISABLE_INSTALLER)
if(NOT DEFINED INSTALL_BIN_DIR)
set(INSTALL_BIN_DIR bin)
endif()
if(NOT DEFINED INSTALL_LIB_DIR)
set(INSTALL_LIB_DIR lib)
if(NOT DEFINED INSTALL_LIB_DIR)
set(INSTALL_LIB_DIR lib)
endif()
endif()
add_subdirectory(squirrel)
add_subdirectory(sqstdlib)
add_subdirectory(sq)
if(NOT WIN32)
if(NOT WIN32 AND NOT DEFINED DISABLE_DYNAMIC)
set_target_properties(squirrel sqstdlib PROPERTIES SOVERSION 0 VERSION 0.0.0)
endif()

View File

@ -1,17 +1,25 @@
add_executable(sq sq.c)
set_target_properties(sq PROPERTIES LINKER_LANGUAGE C)
target_link_libraries(sq squirrel sqstdlib)
install(TARGETS sq RUNTIME DESTINATION ${INSTALL_BIN_DIR})
if(NOT DEFINED DISABLE_DYNAMIC)
add_executable(sq sq.c)
set_target_properties(sq PROPERTIES LINKER_LANGUAGE C)
target_link_libraries(sq squirrel sqstdlib)
if(NOT DEFINED SQ_DISABLE_INSTALLER)
install(TARGETS sq RUNTIME DESTINATION ${INSTALL_BIN_DIR})
endif()
endif()
if(NOT DEFINED DISABLE_STATIC)
add_executable(sq_static sq.c)
set_target_properties(sq_static PROPERTIES LINKER_LANGUAGE C)
target_link_libraries(sq_static squirrel_static sqstdlib_static)
install(TARGETS sq_static RUNTIME DESTINATION ${INSTALL_BIN_DIR})
if(NOT DEFINED SQ_DISABLE_INSTALLER)
install(TARGETS sq_static RUNTIME DESTINATION ${INSTALL_BIN_DIR})
endif()
endif()
if(DEFINED LONG_OUTPUT_NAMES)
set_target_properties(sq PROPERTIES OUTPUT_NAME squirrel3)
if(NOT DEFINED DISABLE_DYNAMIC)
set_target_properties(sq PROPERTIES OUTPUT_NAME squirrel3)
endif()
if(NOT DEFINED DISABLE_STATIC)
set_target_properties(sq_static PROPERTIES OUTPUT_NAME squirrel3_static)

View File

@ -7,19 +7,27 @@ set(SQSTDLIB_SRC sqstdaux.cpp
sqstdstring.cpp
sqstdsystem.cpp)
add_library(sqstdlib SHARED ${SQSTDLIB_SRC})
target_link_libraries(sqstdlib squirrel)
install(TARGETS sqstdlib RUNTIME DESTINATION ${INSTALL_BIN_DIR}
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
if(NOT DEFINED DISABLE_DYNAMIC)
add_library(sqstdlib SHARED ${SQSTDLIB_SRC})
target_link_libraries(sqstdlib squirrel)
if(NOT DEFINED SQ_DISABLE_INSTALLER)
install(TARGETS sqstdlib RUNTIME DESTINATION ${INSTALL_BIN_DIR}
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
endif()
endif()
if(NOT DEFINED DISABLE_STATIC)
add_library(sqstdlib_static STATIC ${SQSTDLIB_SRC})
install(TARGETS sqstdlib_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
if(NOT DEFINED SQ_DISABLE_INSTALLER)
install(TARGETS sqstdlib_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
endif()
endif()
if(DEFINED LONG_OUTPUT_NAMES)
set_target_properties(sqstdlib PROPERTIES OUTPUT_NAME sqstdlib3)
if(NOT DEFINED DISABLE_DYNAMIC)
set_target_properties(sqstdlib PROPERTIES OUTPUT_NAME sqstdlib3)
endif()
if(NOT DEFINED DISABLE_STATIC)
set_target_properties(sqstdlib_static PROPERTIES OUTPUT_NAME sqstdlib3_static)

View File

@ -69,7 +69,10 @@ SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen
const SQChar *format;
SQChar *dest;
SQChar fmt[MAX_FORMAT_LEN];
sq_getstring(v,nformatstringidx,&format);
const SQRESULT res = sq_getstring(v,nformatstringidx,&format);
if (SQ_FAILED(res)) {
return res; // propagate the error
}
SQInteger format_size = sq_getsize(v,nformatstringidx);
SQInteger allocated = (format_size+2)*sizeof(SQChar);
dest = sq_getscratchpad(v,allocated);

View File

@ -11,18 +11,26 @@ set(SQUIRREL_SRC sqapi.cpp
sqtable.cpp
sqvm.cpp)
add_library(squirrel SHARED ${SQUIRREL_SRC})
install(TARGETS squirrel RUNTIME DESTINATION ${INSTALL_BIN_DIR}
if(NOT DEFINED DISABLE_DYNAMIC)
add_library(squirrel SHARED ${SQUIRREL_SRC})
if(NOT DEFINED SQ_DISABLE_INSTALLER)
install(TARGETS squirrel RUNTIME DESTINATION ${INSTALL_BIN_DIR}
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
endif()
endif()
if(NOT DEFINED DISABLE_STATIC)
add_library(squirrel_static STATIC ${SQUIRREL_SRC})
install(TARGETS squirrel_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
if(NOT DEFINED SQ_DISABLE_INSTALLER)
install(TARGETS squirrel_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
endif()
endif()
if(DEFINED LONG_OUTPUT_NAMES)
set_target_properties(squirrel PROPERTIES OUTPUT_NAME squirrel3)
if(NOT DEFINED DISABLE_DYNAMIC)
set_target_properties(squirrel PROPERTIES OUTPUT_NAME squirrel3)
endif()
if(NOT DEFINED DISABLE_STATIC)
set_target_properties(squirrel_static PROPERTIES OUTPUT_NAME squirrel3_static)