diff --git a/CMakeLists.txt b/CMakeLists.txt index 42185e1..4a37b6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/sq/CMakeLists.txt b/sq/CMakeLists.txt index 3d05006..2ce35c3 100644 --- a/sq/CMakeLists.txt +++ b/sq/CMakeLists.txt @@ -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) diff --git a/sqstdlib/CMakeLists.txt b/sqstdlib/CMakeLists.txt index 493b0a5..86ad721 100644 --- a/sqstdlib/CMakeLists.txt +++ b/sqstdlib/CMakeLists.txt @@ -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) diff --git a/sqstdlib/sqstdstring.cpp b/sqstdlib/sqstdstring.cpp index bce6043..e624646 100644 --- a/sqstdlib/sqstdstring.cpp +++ b/sqstdlib/sqstdstring.cpp @@ -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); diff --git a/squirrel/CMakeLists.txt b/squirrel/CMakeLists.txt index 6efef84..8ba67fb 100644 --- a/squirrel/CMakeLists.txt +++ b/squirrel/CMakeLists.txt @@ -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)