Merge pull request #17 from FabianWolff/cmake

Various improvements of the build system
This commit is contained in:
albertodemichelis 2016-03-18 02:07:18 +08:00
commit 6a4173aaa5
18 changed files with 208 additions and 115 deletions

View File

@ -1,39 +1,68 @@
cmake_minimum_required(VERSION 2.8)
project(squirrel)
# get machine
execute_process( COMMAND ${CMAKE_C_COMPILER} -dumpmachine OUTPUT_VARIABLE DUMP_MACHINE OUTPUT_STRIP_TRAILING_WHITESPACE)
message("Dump Machine : ${DUMP_MACHINE}")
# get architecture
if(NOT DEFINED ARCHITECTURE)
string(FIND ${DUMP_MACHINE} "-" DUMP_MACHINE_STRIP)
string(SUBSTRING ${DUMP_MACHINE} 0 ${DUMP_MACHINE_STRIP} ARCHITECTURE)
endif()
message("Architecture : ${ARCHITECTURE}")
# global includes
include_directories(
${PROJECT_SOURCE_DIR}/include
)
# global flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -Wall -fno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-exceptions -Wall -fno-strict-aliasing")
set(SQGLOB_FLAGS_RELEASE "-O2")
set(SQGLOB_FLAGS_DEBUG "-pg -pie -gstabs -g3")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${SQGLOB_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_DEBUG} ${SQGLOB_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SQGLOB_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} ${SQGLOB_FLAGS_DEBUG}")
if("${ARCHITECTURE}" STREQUAL "x86_64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_SQ64")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_SQ64")
if(MSVC)
cmake_minimum_required(VERSION 3.4)
else()
cmake_minimum_required(VERSION 2.8)
endif()
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}" CACHE PATH "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
project(squirrel C CXX)
include_directories(${CMAKE_SOURCE_DIR}/include)
if(CMAKE_COMPILER_IS_GNUCXX)
set(SQ_FLAGS -fno-exceptions -fno-strict-aliasing -Wall -Wextra -pedantic -Wcast-qual)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(SQ_FLAGS ${SQ_FLAGS} -O3)
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(SQ_FLAGS ${SQ_FLAGS} -O3 -g)
elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
set(SQ_FLAGS ${SQ_FLAGS} -Os)
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(SQ_FLAGS ${SQ_FLAGS} -pg -pie -gstabs -g3 -Og)
endif()
if(CMAKE_VERSION VERSION_GREATER 3)
add_compile_options(${SQ_FLAGS})
else()
add_definitions(${SQ_FLAGS})
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -std=c++0x")
elseif(MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
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 INSTALL_LIB_DIR)
set(INSTALL_LIB_DIR lib)
endif()
# subdirectories
add_subdirectory(squirrel)
add_subdirectory(sqstdlib)
add_subdirectory(sq)
if(NOT WIN32)
set_target_properties(squirrel sqstdlib PROPERTIES SOVERSION 0 VERSION 0.0.0)
endif()
if(DEFINED INSTALL_INC_DIR)
set(SQ_PUB_HEADERS include/sqconfig.h
include/sqstdaux.h
include/sqstdblob.h
include/sqstdio.h
include/sqstdmath.h
include/sqstdstring.h
include/sqstdsystem.h
include/squirrel.h)
install(FILES ${SQ_PUB_HEADERS} DESTINATION ${INSTALL_INC_DIR})
endif()

38
COMPILE
View File

@ -23,6 +23,44 @@ samples
HOW TO COMPILE
---------------------------------------------------------
CMAKE USERS
.........................................................
If you want to build the shared libraries under Windows using Visual
Studio, you will have to use CMake version 3.4 or newer. If not, an
earlier version will suffice. For a traditional out-of-source build
under Linux, type something like
$ mkdir build # Create temporary build directory
$ cd build
$ cmake .. # CMake will determine all the necessary information,
# including the platform (32- vs. 64-bit)
$ make
$ make install
$ cd ..; rm -r build
The default installation directory will be the top source directory,
i. e. the binaries will go into bin/ and the libraries into lib/. You
can change this behavior by calling CMake like this:
$ cmake .. -DCMAKE_INSTALL_PREFIX=/some/path/on/your/system
With the INSTALL_BIN_DIR and INSTALL_LIB_DIR options, the directories
the binaries & libraries will go in (relative to CMAKE_INSTALL_PREFIX)
can be specified. For instance,
$ cmake .. -DINSTALL_LIB_DIR=lib64
will install the libraries into a 'lib64' subdirectory in the top
source directory. If INSTALL_INC_DIR is set, the public header files
will be installed into the directory the value of INSTALL_INC_DIR
points to. There is no default directory - if you want only the
binaries and no headers, just don't specify INSTALL_INC_DIR, and no
header files will be installed.
Under Windows, it is probably easiest to use the CMake GUI interface,
although invoking CMake from the command line as explained above
should work as well.
GCC USERS
.........................................................
There is a very simple makefile that compiles all libraries and exes

23
README
View File

@ -1,16 +1,26 @@
The programming language SQUIRREL 3.1 stable
--------------------------------------------------
The project has been compiled and run on Windows(x86 and x64) and
Linux(x86 and x64) and Solaris(x86 and x64).
This project has successfully been compiled and run on
* Windows (x86 and amd64)
* Linux (x86, amd64 and ARM)
* Solaris (x86 and amd64)
Has been tested with the following compilers:
MS Visual C++ 6.0,7.0,7.1,8.0,9.0,10.0 (32 and 64bits)
The following compilers have been confirmed to be working:
MS Visual C++ 6.0 (all on x86 and amd64)
7.0 |
7.1 v
8.0
9.0
10.0 ---
12.0 (only on x86)
MinGW gcc 3.2 (mingw special 20020817-1)
Cygnus gcc 3.2
Linux gcc 3.2.3
Linux gcc 4.0.0 (x86 & 64bits)
Solaris gcc 4.0.0 (x86 & 64bits)
4.0.0 (x86 and amd64)
5.3.1 (amd64)
Solaris gcc 4.0.0 (x86 and amd64)
ARM Linux gcc 4.6.3 (Raspberry Pi Model B)
Feedback and suggestions are appreciated
@ -20,4 +30,3 @@ wiki - http://wiki.squirrel-lang.org
author - alberto@demichelis.net
END OF README

View File

@ -392,6 +392,12 @@ SQUIRREL_API void sq_setnativedebughook(HSQUIRRELVM v,SQDEBUGHOOK hook);
#define SQ_FAILED(res) (res<0)
#define SQ_SUCCEEDED(res) (res>=0)
#ifdef __GNUC__
# define SQ_UNUSED_ARG(x) __attribute__((unused)) x
#else
# define SQ_UNUSED_ARG(x) x
#endif
#ifdef __cplusplus
} /*extern "C"*/
#endif

View File

@ -1,22 +1,23 @@
cmake_minimum_required(VERSION 2.8)
project(libsquirrel)
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})
# sources
set(SQ_SRCS
sq.c
)
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})
endif()
# libs
set(SQ_LIBS
sqstd
squirrel
)
if(DEFINED LONG_OUTPUT_NAMES)
set_target_properties(sq PROPERTIES OUTPUT_NAME squirrel3)
# shared lib
add_executable(sq ${SQ_SRCS})
target_link_libraries(sq ${SQ_LIBS})
if(NOT DEFINED DISABLE_STATIC)
set_target_properties(sq_static PROPERTIES OUTPUT_NAME squirrel3_static)
endif()
endif()
# static lib
add_executable(sq_static ${SQ_SRCS})
set_target_properties(sq_static PROPERTIES COMPILE_FLAGS "-static -Wl,-static")
target_link_libraries(sq_static ${SQ_LIBS})
if(CMAKE_COMPILER_IS_GNUCXX AND (NOT DEFINED DISABLE_STATIC))
set_target_properties(sq_static PROPERTIES COMPILE_FLAGS "-static -Wl,-static")
endif()

View File

@ -46,7 +46,7 @@ SQInteger quit(HSQUIRRELVM v)
return 0;
}
void printfunc(HSQUIRRELVM v, const SQChar *s,...)
void printfunc(HSQUIRRELVM SQ_UNUSED_ARG(v),const SQChar *s,...)
{
va_list vl;
va_start(vl, s);
@ -55,13 +55,12 @@ void printfunc(HSQUIRRELVM v, const SQChar *s,...)
(void)v; /* UNUSED */
}
void errorfunc(HSQUIRRELVM v, const SQChar *s,...)
void errorfunc(HSQUIRRELVM SQ_UNUSED_ARG(v),const SQChar *s,...)
{
va_list vl;
va_start(vl, s);
scvprintf(stderr, s, vl);
va_end(vl);
(void)v; /* UNUSED */
}
void PrintVersionInfos()

View File

@ -1,20 +1,27 @@
cmake_minimum_required(VERSION 2.8)
project(sqstd)
set(SQSTDLIB_SRC sqstdaux.cpp
sqstdblob.cpp
sqstdio.cpp
sqstdmath.cpp
sqstdrex.cpp
sqstdstream.cpp
sqstdstring.cpp
sqstdsystem.cpp)
# sources
set(SQSTD_SRCS
sqstdblob.cpp
sqstdio.cpp
sqstdstream.cpp
sqstdmath.cpp
sqstdsystem.cpp
sqstdstring.cpp
sqstdaux.cpp
sqstdrex.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})
# shared lib
add_library(sqstd SHARED ${SQSTD_SRCS})
if(NOT DEFINED DISABLE_STATIC)
add_library(sqstdlib_static STATIC ${SQSTDLIB_SRC})
install(TARGETS sqstdlib_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
endif()
# static lib
add_library(sqstd_static STATIC ${SQSTD_SRCS})
if(DEFINED LONG_OUTPUT_NAMES)
set_target_properties(sqstdlib PROPERTIES OUTPUT_NAME sqstdlib3)
if(NOT DEFINED DISABLE_STATIC)
set_target_properties(sqstdlib_static PROPERTIES OUTPUT_NAME sqstdlib3_static)
endif()
endif()

View File

@ -114,7 +114,7 @@ static SQInteger _blob__typeof(HSQUIRRELVM v)
return 1;
}
static SQInteger _blob_releasehook(SQUserPointer p, SQInteger /*size*/)
static SQInteger _blob_releasehook(SQUserPointer p, SQInteger SQ_UNUSED_ARG(size))
{
SQBlob *self = (SQBlob*)p;
self->~SQBlob();

View File

@ -115,7 +115,7 @@ static SQInteger _file__typeof(HSQUIRRELVM v)
return 1;
}
static SQInteger _file_releasehook(SQUserPointer p, SQInteger /*size*/)
static SQInteger _file_releasehook(SQUserPointer p, SQInteger SQ_UNUSED_ARG(size))
{
SQFile *self = (SQFile*)p;
self->~SQFile();

View File

@ -350,7 +350,7 @@ static SQInteger _string_endswith(HSQUIRRELVM v)
SQRex *self = NULL; \
sq_getinstanceup(v,1,(SQUserPointer *)&self,0);
static SQInteger _rexobj_releasehook(SQUserPointer p, SQInteger /*size*/)
static SQInteger _rexobj_releasehook(SQUserPointer p, SQInteger SQ_UNUSED_ARG(size))
{
SQRex *self = ((SQRex *)p);
sqstd_rex_free(self);

View File

@ -1,24 +1,30 @@
cmake_minimum_required(VERSION 2.8)
project(libsquirrel)
set(SQUIRREL_SRC sqapi.cpp
sqbaselib.cpp
sqclass.cpp
sqcompiler.cpp
sqdebug.cpp
sqfuncstate.cpp
sqlexer.cpp
sqmem.cpp
sqobject.cpp
sqstate.cpp
sqtable.cpp
sqvm.cpp)
# sources
set(SQUIRREL_SRCS
sqapi.cpp
sqbaselib.cpp
sqfuncstate.cpp
sqdebug.cpp
sqlexer.cpp
sqobject.cpp
sqcompiler.cpp
sqstate.cpp
sqtable.cpp
sqmem.cpp
sqvm.cpp
sqclass.cpp
)
add_library(squirrel SHARED ${SQUIRREL_SRC})
install(TARGETS squirrel RUNTIME DESTINATION ${INSTALL_BIN_DIR}
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
# shared lib
add_library(squirrel SHARED ${SQUIRREL_SRCS})
if(NOT DEFINED DISABLE_STATIC)
add_library(squirrel_static STATIC ${SQUIRREL_SRC})
install(TARGETS squirrel_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
endif()
# static lib
add_library(squirrel_static STATIC ${SQUIRREL_SRCS})
if(DEFINED LONG_OUTPUT_NAMES)
set_target_properties(squirrel PROPERTIES OUTPUT_NAME squirrel3)
if(NOT DEFINED DISABLE_STATIC)
set_target_properties(squirrel_static PROPERTIES OUTPUT_NAME squirrel3_static)
endif()
endif()

View File

@ -180,7 +180,7 @@ SQBool sq_release(HSQUIRRELVM v,HSQOBJECT *po)
#endif
}
SQUnsignedInteger sq_getvmrefcount(HSQUIRRELVM /*v*/, const HSQOBJECT *po)
SQUnsignedInteger sq_getvmrefcount(HSQUIRRELVM SQ_UNUSED_ARG(v), const HSQOBJECT *po)
{
if (!ISREFCOUNTED(type(*po))) return 0;
return po->_unVal.pRefCounted->_uiRef;

View File

@ -40,7 +40,7 @@ static bool str2num(const SQChar *s,SQObjectPtr &res,SQInteger base)
return true;
}
static SQInteger base_dummy(HSQUIRRELVM /*v*/)
static SQInteger base_dummy(HSQUIRRELVM SQ_UNUSED_ARG(v))
{
return 0;
}
@ -721,7 +721,7 @@ static bool _hsort_sift_down(HSQUIRRELVM v,SQArray *arr, SQInteger root, SQInteg
return true;
}
static bool _hsort(HSQUIRRELVM v,SQObjectPtr &arr, SQInteger /*l*/, SQInteger /*r*/, SQInteger func)
static bool _hsort(HSQUIRRELVM v,SQObjectPtr &arr, SQInteger SQ_UNUSED_ARG(l), SQInteger SQ_UNUSED_ARG(r),SQInteger func)
{
SQArray *a = _array(arr);
SQInteger i;
@ -1263,4 +1263,3 @@ const SQRegFunction SQSharedState::_weakref_default_delegate_funcz[] = {
{_SC("tostring"),default_delegate_tostring,1, _SC(".")},
{NULL,(SQFUNCTION)0,0,NULL}
};

View File

@ -189,7 +189,7 @@ SQInstance::~SQInstance()
if(_class){ Finalize(); } //if _class is null it was already finalized by the GC
}
bool SQInstance::GetMetaMethod(SQVM * /*v*/, SQMetaMethod mm, SQObjectPtr &res)
bool SQInstance::GetMetaMethod(SQVM SQ_UNUSED_ARG(*v),SQMetaMethod mm,SQObjectPtr &res)
{
if(type(_class->_metamethods[mm]) != OT_NULL) {
res = _class->_metamethods[mm];

View File

@ -982,8 +982,8 @@ public:
SQInteger val = _fs->PopTarget();
SQInteger key = _fs->PopTarget();
SQInteger attrs = hasattrs ? _fs->PopTarget():-1;
((void)attrs);
assert((hasattrs && (attrs == key-1)) || !hasattrs);
(void)attrs; // UNUSED
unsigned char flags = (hasattrs?NEW_SLOT_ATTRIBUTES_FLAG:0)|(isstatic?NEW_SLOT_STATIC_FLAG:0);
SQInteger table = _fs->TopTarget(); //<<BECAUSE OF THIS NO COMMON EMIT FUNC IS POSSIBLE
if(separator == _SC(',')) { //hack recognizes a table from the separator

View File

@ -5,7 +5,7 @@
#ifndef SQ_EXCLUDE_DEFAULT_MEMFUNCTIONS
void *sq_vm_malloc(SQUnsignedInteger size){ return malloc(size); }
void *sq_vm_realloc(void *p, SQUnsignedInteger /*oldsize*/, SQUnsignedInteger size){ return realloc(p, size); }
void *sq_vm_realloc(void *p, SQUnsignedInteger SQ_UNUSED_ARG(oldsize), SQUnsignedInteger size){ return realloc(p, size); }
void sq_vm_free(void *p, SQUnsignedInteger /*size*/) { free(p); }
void sq_vm_free(void *p, SQUnsignedInteger SQ_UNUSED_ARG(size)){ free(p); }
#endif

View File

@ -250,8 +250,7 @@ void SQSharedState::MarkObject(SQObjectPtr &o,SQCollectable **chain)
}
}
void SQSharedState::RunMark(SQVM * /*vm*/, SQCollectable **tchain)
void SQSharedState::RunMark(SQVM SQ_UNUSED_ARG(*vm),SQCollectable **tchain)
{
SQVM *vms = _thread(_root_vm);

View File

@ -514,7 +514,7 @@ SQRESULT SQVM::Suspend()
#define _FINISH(howmuchtojump) {jump = howmuchtojump; return true; }
bool SQVM::FOREACH_OP(SQObjectPtr &o1,SQObjectPtr &o2,SQObjectPtr
&o3,SQObjectPtr &o4,SQInteger /*arg_2*/,int exitpos,int &jump)
&o3,SQObjectPtr &o4,SQInteger SQ_UNUSED_ARG(arg_2),int exitpos,int &jump)
{
SQInteger nrefidx;
switch(type(o1)) {
@ -1573,7 +1573,7 @@ SQInteger prevstackbase = _stackbase;
return true;
}
bool SQVM::CallMetaMethod(SQObjectPtr &closure,SQMetaMethod /*mm*/,SQInteger nparams,SQObjectPtr &outres)
bool SQVM::CallMetaMethod(SQObjectPtr &closure,SQMetaMethod SQ_UNUSED_ARG(mm),SQInteger nparams,SQObjectPtr &outres)
{
//SQObjectPtr closure;