Prepare for full appveyor build.

Add abort_clean so that CI does not get stuck on a message box that can never be answered
alignment rules do not apply to stack variables, so the tests cannot have the alignment check in the destructor: only for memory pushed into and coming straight out of Lua
This commit is contained in:
ThePhD 2017-12-25 11:44:04 -05:00
parent f2db7e3a6f
commit 6d2100e814
11 changed files with 223 additions and 98 deletions

View File

@ -55,18 +55,18 @@ if (MSVC)
add_definitions(/DUNICODE /D_UNICODE /D_SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING /D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING /D_CRT_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_DEPRECATE)
add_compile_options(/W4 /EHsc)
else()
add_compile_options(-Wno-unknown-warning -Wno-unknown-warning-option -Wall -Wextra -Wpedantic -pedantic -pedantic-errors -Wno-noexcept-type -ftemplate-depth=1024)
add_compile_options(-Wno-unknown-warning -Wno-unknown-warning-option -Wall -Wextra -Wpedantic -pedantic -pedantic-errors)
endif()
# # # General project output locations
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/x86")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/x86")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/x86")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x86/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x86/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x86/bin")
else()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/x64")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/x64")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/x64")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x64/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x64/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x64/bin")
endif()
# # # Modules
@ -85,14 +85,18 @@ include(CMakePackageConfigHelpers)
set(LUA_VERSION "5.3.4" CACHE STRING "The version of Lua needed. Can be 5.1, 5.2, 5.3, LuaJIT, or a more specific 3-part version number for a specifc Lua (e.g., 5.3.4 or luajit-2.0.5)")
set(BUILD_LUA TRUE CACHE BOOL "Always build Lua, do not search for it in the system")
set(BUILD_LUAJIT FALSE CACHE BOOL "Always build LuaJIT, do not search for it in the system")
option(CI "Enable build of tests" OFF)
option(TESTS "Enable build of tests" OFF)
option(EXAMPLES "Enable build of examples" OFF)
option(SINGLE "Enable build of single header files" ON)
# Single tests will only be turned on if both SINGLE and TESTS are defined
CMAKE_DEPENDENT_OPTION(TESTS_SINGLE "Enable build of tests using the generated single headers" ON
"SINGLE;TESTS" OFF)
CMAKE_DEPENDENT_OPTION(TESTS_EXAMPLES "Enable build of examples as tests" ON
"TESTS;EXAMPLES" ON)
if (TESTS AND EXAMPLES)
option(TESTS_EXAMPLES "Enable build of examples as tests" ON)
else()
option(TESTS_EXAMPLES "Enable build of examples as tests" OFF)
endif()
option(DOCS "Enable build of documentation" OFF)
@ -175,6 +179,10 @@ else()
endif()
endif()
if (CI)
message(STATUS "Contiguous Integration is on")
endif()
# # # Tests, Examples and other CI suites that come with sol2
if (TESTS OR TESTS_SINGLE OR EXAMPLES OR TESTS_EXAMPLES)
# # # Libraries
@ -203,9 +211,14 @@ if (TESTS OR TESTS_SINGLE OR EXAMPLES OR TESTS_EXAMPLES)
# # # Tests
# # Enable test harness for regular or single tests
if (TESTS OR TESTS_SINGLE)
# enable ctest and add subdir to get going
if (TESTS OR TESTS_SINGLE OR TESTS_EXAMPLES)
# enable ctest
enable_testing()
endif()
# # Add tests here
if (TESTS OR TESTS_SINGLE)
# add subdir to get going
message(STATUS "Adding sol2 tests...")
add_subdirectory(tests "${CMAKE_BINARY_DIR}/tests")
endif()
@ -213,6 +226,7 @@ if (TESTS OR TESTS_SINGLE OR EXAMPLES OR TESTS_EXAMPLES)
# # Enable examples to be built against the library
if (EXAMPLES OR TESTS_EXAMPLES)
# NOTE: will also add to tests if TESTS is defined
message(STATUS "Adding sol2 examples...")
add_subdirectory(examples "${CMAKE_BINARY_DIR}/examples")
endif()
endif()

View File

@ -63,6 +63,8 @@ Boston C++ Meetup November 2017 - CiC, Boston, MA
You can grab a single header (and the single forward header) out of the library [here](https://github.com/ThePhD/sol2/tree/develop/single/sol). For stable version, check the releases tab on github for a provided single header file for maximum ease of use. A script called `single.py` is provided in the repository if there's some bleeding edge change that hasn't been published on the releases page. You can run this script to create a single file version of the library so you can only include that part of it. Check `single.py --help` for more info.
If you use CMake, you can also configure and generate a project that will generate the sol2_single_header for you. You can also include the project using Cmake. Run CMake for more details. Thanks @Nava2, @alkino, @mrgreywater and others for help with making the CMake build a reality.
## Features
- [Fastest in the land](http://sol2.readthedocs.io/en/latest/benchmarks.html) (see: sol bar in graph).
@ -81,7 +83,7 @@ You can grab a single header (and the single forward header) out of the library
Sol makes use of C++11 **and** C++14 features. GCC 5.x.x and Clang 3.6.x (with `-std=c++1z` and appropriate standard library)
or higher should be able to compile without problems. However, the officially supported and CI-tested compilers are:
- GCC 5.x.x+
- GCC 5.x.x+ (MinGW 5.x.x+)
- Clang 3.6.x+
- Visual Studio 2015 Community (Visual C++ 14.0)+
@ -91,6 +93,14 @@ Please make sure you use the `-std=c++1y`, `-std=c++14`, `-std=c++1z`, `-std=c++
Older compilers (GCC 4.9.x, Clang 3.4.x seem to be the lowest) can work with versions as late
as [v2.17.5](https://github.com/ThePhD/sol2/releases/tag/v2.17.5), with the flag `-std=c++14` or `-std=c++1y`.
Is checked by-hand for other platforms as well, including Android-based builds with GCC and iOS-based builds out of XCode with Apple-clang. It should work on both of these platforms, so long as you have the proper standards flags.
## Running the Tests
Testing on Travis-CI and Appveyor use CMake. You can generate the tests by running CMake and configuring `TESTS`, `TESTS_SINGLE`, `TESTS_EXAMPLES`, and `EXAMPLES` to be on. Make sure `SINGLE` is also on.
You will need any flavor of python3 and an available compiler. The testing suite will build its own version of Lua and LuaJIT, so you do not have to.
## Supporting
You can help out the library by submitting pull requests to fix anything or add anything you think would be helpful! This includes making small, useful examples of something you haven't seen, or fixing typos and bad code in the documentation.

View File

@ -29,18 +29,33 @@ image:
- Visual Studio 2017
- Visual Studio 2015
configuration: Release
configuration:
- Release
environment:
matrix:
- LUA_VERSION: 5.3.4
- LUA_VERSION: 5.2.4
- LUA_VERSION: 5.1.5
- LUA_VERSION: 5.3.4
MINGW_VERSION: 6.3.0
- LUA_VERSION: 5.3.4
MINGW_VERSION: 5.3.0
platform:
- x86
- x64
matrix:
allow_failures:
- MINGW_VERSION: 5.3.0
- MINGW_VERSION: 6.3.0
exclude:
- image: Visual Studio 2017
MINGW_VERSION: 6.3.0
- image: Visual Studio 2017
MINGW_VERSION: 5.3.0
init:
- set arch=
- if "%PLATFORM%"=="x64" (set arch= Win64)
@ -48,23 +63,37 @@ init:
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" (set CMAKE_GENERATOR=Visual Studio 15 2017%arch%)
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" (set CMAKE_GENERATOR=Visual Studio 14 2015%arch%)
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2013" (set CMAKE_GENERATOR=Visual Studio 12 2013%arch%)
- if DEFINED MINGW_VERSION ( set CMAKE_GENERATOR=MinGW Makefiles)
- if "%MINGW_VERSION%"=="5.3.0" (set CMAKE_GENERATOR=Ninja)
- if "%MINGW_VERSION%"=="6.3.0" (set CMAKE_GENERATOR=Ninja)
- echo "%CMAKE_GENERATOR%"
# We need to use CMAKE_BUILD_TYPE=Release since there are no "configuration"
# toolsets for Ninja or Makefiles as far as cmake is concerned, so
# the --config / -C switches on builds do nothing...!
before_build:
- set PYTHON_PATH=C:\Python36
- if "%PLATFORM%"=="x64" (set PYTHON_PATH=C:\Python36-x64)
- set PATH=%PYTHON_PATH%;%PATH%
- set python_path=C:\Python36
- set mingw_path=
- set build_type=
- if "%CMAKE_GENERATOR%"=="MinGW Makefiles" (set build_type=-DCMAKE_BUILD_TYPE=Release)
- if "%CMAKE_GENERATOR%"=="Ninja" (set build_type=-DCMAKE_BUILD_TYPE=Release)
- if "%MINGW_VERSION%"=="5.3.0" (set mingw_path=C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0)
- if "%MINGW_VERSION%"=="6.3.0" ( if "%PLATFORM%"=="x64" (set mingw_path=C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1) else ( set mingw_path=C:\mingw-w64\i686-6.3.0-posix-dwarf-rt_v5-rev1))
- if "%PLATFORM%"=="x64" (set python_path=C:\Python36-x64)
- set PATH=%python_path%;%PATH%
- set PATH=%PATH%;%mingw_path%
- md build-sol2
- cd build-sol2
- cmake .. -G "%CMAKE_GENERATOR%" -DLUA_VERSION="%LUA_VERSION%" -DBUILD_LUA=ON -DBUILD_LUA_AS_DLL=OFF -DTESTS=ON -DEXAMPLES=ON -DSINGLE=ON -DTESTS_EXAMPLES=ON -DTESTS_SINGLE=ON
- cmake .. -G "%CMAKE_GENERATOR%" %build_type% -DLUA_VERSION="%LUA_VERSION%" -DBUILD_LUA=ON -DBUILD_LUA_AS_DLL=OFF -DTESTS=ON -DEXAMPLES=ON -DSINGLE=ON -DTESTS_EXAMPLES=ON -DTESTS_SINGLE=ON
# We do not build the debug versions because the compiler
# generates too much debug info for MinGW to handle
# TODO: fix the damn compilation space and time already
build_script:
- if "%PLATFORM%"=="x64" (cmake --build . --config Debug)
- if NOT "%build_type%"=="-DCMAKE_BUILD_TYPE=Release" (cmake --build . --config Debug)
- cmake --build . --config Release
test_script:
- if "%PLATFORM%"=="x64" (ctest -C Debug --output-on-failure)
- if NOT "%build_type%"=="-DCMAKE_BUILD_TYPE=Release" (ctest -C Debug --output-on-failure)
- ctest -C Release --output-on-failure
notifications:

View File

@ -98,6 +98,15 @@ set(LUA_VANILLA_SHA1_1.1 67209701eec5cc633e829d023fbff62d5d6c8e5e)
set(LUA_VANILLA_MD5_1.0 96e8399fc508d128badd8ac3aa8f2119)
set(LUA_VANILLA_SHA1_1.0 6a82d2ae7ce9ad98c7b4824a325b91522c0d6ebb)
# # Prepend function (is there an equivalent in CMake somewhere...?)
function(prepend var prefix)
set(l "")
foreach(f ${ARGN})
list(APPEND l "${prefix}${f}")
endforeach(f)
SET(${var} "${l}" PARENT_SCOPE)
ENDFUNCTION(prepend)
# Clean up some variables
if (LUA_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$")
# probably okay!
@ -143,25 +152,8 @@ else ()
set(LUA_VANILLA_DOWNLOAD_SHA1_COMMAND "")
endif()
function(prepend var prefix)
set(l "")
foreach(f ${ARGN})
list(APPEND l "${prefix}${f}")
endforeach(f)
SET(${var} "${l}" PARENT_SCOPE)
ENDFUNCTION(prepend)
# # # Makefile and self-build configurations
# # Final outputs for lib and dll files in the case we're using the makefile directly
set(LUA_VANILLA_LIB_FILE "${LUA_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${LUA_LIBRARY}${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(LUA_VANILLA_DLL_FILE "${LUA_BIN_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${LUA_LIBRARY}${CMAKE_SHARED_LIBRARY_SUFFIX}")
if (BUILD_LUA_AS_DLL)
set(LUA_VANILLA_BYPRODUCTS ${LUA_VANILLA_LIB_FILE} ${LUA_VANILLA_DLL_FILE})
else()
set(LUA_VANILLA_BYPRODUCTS ${LUA_VANILLA_LIB_FILE})
endif()
# # Potential compiler variables
if (MSVC)
set(LUA_VANILLA_LUA_LUAC_COMPILER_OPTIONS "/W1")
@ -177,7 +169,7 @@ endif()
# # Source files for natural build, if we have to go that far
# retrieve source files
if (LUA_VANILLA_VERSION MATCHES "^5.1")
if (LUA_VANILLA_VERSION MATCHES "^5\\.1")
set(LUA_VANILLA_LIB_SOURCES lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c
lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c
lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c
@ -186,7 +178,7 @@ if (LUA_VANILLA_VERSION MATCHES "^5.1")
set(LUA_VANILLA_LUA_SOURCES lua.c )
set(LUA_VANILLA_LUAC_SOURCES luac.c print.c )
set(LUA_VANILLA_GENERATE_LUA_HPP true)
elseif (LUA_VANILLA_VERSION MATCHES "^5.2")
elseif (LUA_VANILLA_VERSION MATCHES "^5\\.2")
set(LUA_VANILLA_LIB_SOURCES lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c
lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c
lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c
@ -196,7 +188,7 @@ elseif (LUA_VANILLA_VERSION MATCHES "^5.2")
set(LUA_VANILLA_LUAC_SOURCES luac.c )
set(LUA_VANILLA_GENERATE_LUA_HPP false)
else()
if (NOT LUA_VANILLA_VERSION MATCHES "^5.3")
if (NOT LUA_VANILLA_VERSION MATCHES "^5\\.3")
message(STATUS "Using the Lua 5.3 sources list for a version of Lua that is not 5.3: may result in an incomplete build or errors later")
endif()
set(LUA_VANILLA_LIB_SOURCES lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c
@ -243,26 +235,39 @@ ExternalProject_Add(LUA_VANILLA
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
BUILD_BYPRODUCTS ${LUA_VANILLA_BYPRODUCTS} "${LUA_VANILLA_LIB_SOURCES}" "${LUA_VANILLA_LUA_SOURCES}" "${LUA_VANILLA_LUAC_SOURCES}")
BUILD_BYPRODUCTS "${LUA_VANILLA_LIB_SOURCES}" "${LUA_VANILLA_LUA_SOURCES}" "${LUA_VANILLA_LUAC_SOURCES}")
# make a quick lua.hpp for 5.1 targets that don't have it
if (LUA_VANILLA_GENERATE_LUA_HPP)
file (WRITE "${LUA_VANILLA_SOURCE_DIR}/lua.hpp" "// lua.hpp
message(STATUS "Will generate lua.hpp for this version of Lua...")
set(LUA_VANILLA_LUA_HPP_CONTENT "// lua.hpp
// Lua header files for C++
// <<extern \"C\">> not supplied automatically because Lua also compiles as C++
extern \"C\" {
#include \"lua.h\"
#include \"lualib.h\"
#include \"liblua.h\"
#include \"lauxlib.h\"
}
")
set(LUA_VANILLA_SOURCE_LUA_HPP "${LUA_BUILD_TOPLEVEL}-tmp/lua.hpp")
set(LUA_VANILLA_DESTINATION_LUA_HPP "${LUA_VANILLA_SOURCE_DIR}/lua.hpp")
file(WRITE "${LUA_VANILLA_SOURCE_LUA_HPP}" "${LUA_VANILLA_HPP_CONTENT}")
file(TO_NATIVE_PATH "${LUA_VANILLA_SOURCE_LUA_HPP}" LUA_VANILLA_SOURCE_LUA_HPP)
file(TO_NATIVE_PATH "${LUA_VANILLA_DESTINATION_LUA_HPP}" LUA_VANILLA_DESTINATION_LUA_HPP)
ExternalProject_Add_Step(LUA_VANILLA
prebuild
# after download, before build
DEPENDEES download
DEPENDERS build
BYPRODUCTS "${LUA_VANILLA_TARGET_LUA_HPP}"
COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_VANILLA_SOURCE_LUA_HPP}" "${LUA_VANILLA_DESTINATION_LUA_HPP}")
endif()
# # Target names
set(lualib "lualib_${LUA_VANILLA_VERSION}")
set(luainterpreter "lua_${LUA_VANILLA_VERSION}")
set(luacompiler "luac_${LUA_VANILLA_VERSION}")
set(liblua "liblua-${LUA_VANILLA_VERSION}")
set(luainterpreter "lua-${LUA_VANILLA_VERSION}")
set(luacompiler "luac-${LUA_VANILLA_VERSION}")
# Lua does not out-of-the-box support building
# a shared library: http://lua-users.org/lists/lua-l/2006-10/msg00098.html
@ -273,8 +278,8 @@ set(luacompiler "luac_${LUA_VANILLA_VERSION}")
# make an actual, buildable target
# that other parts of the code can depend on
add_library(${lualib} ${LUA_BUILD_LIBRARY_TYPE} "${LUA_VANILLA_LIB_SOURCES}")
set_target_properties(${lualib}
add_library(${liblua} ${LUA_BUILD_LIBRARY_TYPE} "${LUA_VANILLA_LIB_SOURCES}")
set_target_properties(${liblua}
PROPERTIES
LANGUAGE C
LINKER_LANGUAGE C
@ -289,31 +294,31 @@ set_target_properties(${lualib}
RUNTIME_OUTPUT_NAME ${LUA_BUILD_LIBNAME}
LIBRARY_OUTPUT_NAME ${LUA_BUILD_LIBNAME}
ARCHIVE_OUTPUT_NAME ${LUA_BUILD_LIBNAME})
target_include_directories(${lualib}
target_include_directories(${liblua}
PRIVATE ${LUA_VANILLA_SOURCE_DIR}
PUBLIC ${LUA_VANILLA_SOURCE_DIR})
target_compile_definitions(${lualib}
target_compile_definitions(${liblua}
PUBLIC LUA_COMPAT_ALL ${LUA_VANILLA_DLL_DEFINE}
PRIVATE LUA_COMPAT_ALL ${LUA_VANILLA_DLL_DEFINE})
if (MSVC)
target_compile_options(${lualib}
target_compile_options(${liblua}
PRIVATE /W1)
endif()
if (WIN32)
#target_compile_definitions(${lualib}
#target_compile_definitions(${liblua}
# PRIVATE LUA_USE_WINDOWS)
else()
target_compile_definitions(${lualib}
target_compile_definitions(${liblua}
PRIVATE LUA_USE_LINUX)
endif()
target_compile_options(${lualib}
target_compile_options(${liblua}
PRIVATE ${LUA_VANILLA_LUALIB_COMPILER_OPTIONS})
add_dependencies(${lualib} LUA_VANILLA)
add_dependencies(${liblua} LUA_VANILLA)
if (CMAKE_DL_LIBS)
target_link_libraries(${lualib} ${CMAKE_DL_LIBS})
target_link_libraries(${liblua} ${CMAKE_DL_LIBS})
endif()
if (UNIX)
target_link_libraries(${lualib} m)
target_link_libraries(${liblua} m)
endif()
# we don't really need this section...
@ -344,7 +349,7 @@ else()
endif()
target_compile_options(${luainterpreter}
PRIVATE ${LUA_VANILLA_LUA_LUAC_COMPILER_OPTIONS})
target_link_libraries(${luainterpreter} ${lualib})
target_link_libraries(${luainterpreter} ${liblua})
if (CMAKE_DL_LIBS)
target_link_libraries(${luainterpreter} ${CMAKE_DL_LIBS})
endif()
@ -353,7 +358,7 @@ if (UNIX)
endif()
# LuaC Compiler
add_executable(${luacompiler} ${LUA_VANILLA_LUAC_SOURCES} ${LUA_VANILLA_LIB_SOURCES})
add_executable(${luacompiler} ${LUA_VANILLA_LUAC_SOURCES})
set_target_properties(${luacompiler}
PROPERTIES
LANGUAGE C
@ -379,7 +384,7 @@ else()
target_compile_definitions(${luacompiler}
PRIVATE LUA_USE_LINUX)
endif()
target_link_libraries(${luacompiler} ${lualib})
target_link_libraries(${luacompiler} ${liblua})
if (CMAKE_DL_LIBS)
target_link_libraries(${luacompiler} ${CMAKE_DL_LIBS})
endif()
@ -389,6 +394,5 @@ if (UNIX)
endif()
# set externally-visible target indicator
set(LUA_LIBRARIES ${lualib})
set(LUA_LIBRARIES ${liblua})
set(LUA_FOUND TRUE)

View File

@ -62,13 +62,17 @@ function (MAKE_EXAMPLE example_source_file is_single)
if(CMAKE_DL_LIBS)
target_link_libraries(${example_name} ${CMAKE_DL_LIBS})
endif()
# examples must be built in debug mode to allow assertions to fire
if (MSVC)
target_compile_options(${example_name} PRIVATE /UNDEBUG)
else()
target_compile_options(${example_name} PRIVATE -UNDEBUG)
if (CI)
target_compile_definitions(${example_name}
PRIVATE SOL2_CI)
endif()
if (MSVC)
else()
target_compile_options(${example_name}
PRIVATE -Wno-noexcept-type)
endif()
if (TESTS_EXAMPLES)
if ((NOT is_single) OR (is_single AND TESTS_SINGLE))
add_test(NAME ${example_output_name} COMMAND ${example_name})

View File

@ -24,17 +24,23 @@
#ifndef SOL_FEATURE_TEST_HPP
#define SOL_FEATURE_TEST_HPP
#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && _MSVC_LANG > 201402L)))
#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L))))
#ifndef SOL_CXX17_FEATURES
#define SOL_CXX17_FEATURES 1
#endif // C++17 features macro
#endif // C++17 features check
#if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)))
#ifdef SOL_CXX17_FEATURES
// TODO: there is a bug in the VC++ compiler??
// on /std:c++latest under x86 conditions (VS 15.5.2),
// compiler errors are tossed for noexcept markings being on function types
// that are identical in every other way to their non-noexcept marked types function types...
#if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && (defined(_MSVC_LANG) && ((_MSVC_LANG >= 201703L) && defined(_WIN64))))
#ifndef SOL_NOEXCEPT_FUNCTION_TYPE
#define SOL_NOEXCEPT_FUNCTION_TYPE 1
#endif // noexcept is part of a function's type
#endif
#endif // compiler-specific checks
#endif // C++17 only
#if defined(_WIN32) || defined(_MSC_VER)
#ifndef SOL_CODECVT_SUPPORT

View File

@ -35,7 +35,7 @@ function(CREATE_TEST test_target_name test_name is_single)
endif()
add_executable(${test_target_name} ${SOL2_TEST_SOURCES} ${header_files})
if (is_single)
add_dependencies(${test_target_name} sol2_single_header ${lualib})
add_dependencies(${test_target_name} sol2_single_header ${LUA_LIBRARIES})
target_include_directories(${test_target_name}
PRIVATE "${CMAKE_BINARY_DIR}/include/single/sol" "${LUA_INCLUDE_DIR}" "${CMAKE_BINARY_DIR}/Catch/include/")
else()
@ -45,6 +45,13 @@ function(CREATE_TEST test_target_name test_name is_single)
if (MSVC)
target_compile_options(${test_target_name}
PRIVATE /bigobj)
else()
target_compile_options(${test_target_name}
PRIVATE -Wno-noexcept-type -ftemplate-depth=1024)
endif()
if (CI)
target_compile_definitions(${test_target_name}
PRIVATE SOL2_CI)
endif()
target_compile_features(${test_target_name}
PRIVATE ${CXX_FEATURES})

View File

@ -0,0 +1,11 @@
#include <cstdlib>
struct pre_main {
pre_main() {
#ifdef SOL2_CI
#ifdef _MSC_VER
_set_abort_behavior(0, _WRITE_ABORT_MSG);
#endif
#endif
}
} pm;

View File

@ -1468,6 +1468,8 @@ TEST_CASE("functions/unique_usertype overloading", "make sure overloading can wo
};
}
#if !defined(_MSC_VER) || !(defined(_WIN32) && !defined(_WIN64))
TEST_CASE("functions/noexcept", "allow noexcept functions to be serialized properly into Lua using sol2") {
struct T {
static int noexcept_function() noexcept {
@ -1518,3 +1520,5 @@ TEST_CASE("functions/noexcept", "allow noexcept functions to be serialized prope
REQUIRE(v7 == 0x63);
REQUIRE(v8 == 0x63);
}
#endif // Strange VC++ stuff

View File

@ -621,7 +621,7 @@ TEST_CASE("gc/alignment", "test that allocation is always on aligned boundaries,
struct test {
std::function<void()> callback = []() { std::cout << "Hello world!" << std::endl; };
~test() {
void check_alignment() {
std::uintptr_t p = reinterpret_cast<std::uintptr_t>(this);
std::uintptr_t offset = p % std::alignment_of<test>::value;
REQUIRE(offset == 0);
@ -634,20 +634,52 @@ TEST_CASE("gc/alignment", "test that allocation is always on aligned boundaries,
test obj{};
lua["obj"] = &obj;
INFO("obj");
lua.script("obj.callback()");
{
// Do not check for stack-created object
//test& lobj = lua["obj"];
//lobj.check_alignment();
}
lua["obj0"] = std::ref(obj);
INFO("obj0");
lua.script("obj0.callback()");
{
// Do not check for stack-created object
//test& lobj = lua["obj0"];
//lobj.check_alignment();
}
lua["obj1"] = obj;
INFO("obj1");
lua.script("obj1.callback()");
{
test& lobj = lua["obj1"];
lobj.check_alignment();
}
lua["obj2"] = test{};
INFO("obj2");
lua.script("obj2.callback()");
{
test& lobj = lua["obj2"];
lobj.check_alignment();
}
lua["obj3"] = std::make_unique<test>();
INFO("obj3");
lua.script("obj3.callback()");
{
test& lobj = lua["obj3"];
lobj.check_alignment();
}
lua["obj4"] = std::make_shared<test>();
INFO("obj4");
lua.script("obj4.callback()");
{
test& lobj = lua["obj4"];
lobj.check_alignment();
}
}

View File

@ -1824,31 +1824,6 @@ TEST_CASE("usertype/meta-key-retrievals", "allow for special meta keys (__index,
}
}
TEST_CASE("usertype/noexcept-methods", "make sure noexcept functions and methods can be bound to usertypes without issues") {
struct T {
static int noexcept_function() noexcept {
return 0x61;
}
int noexcept_method() noexcept {
return 0x62;
}
};
sol::state lua;
lua.new_usertype<T>("T",
"nf", &T::noexcept_function,
"nm", &T::noexcept_method);
lua.safe_script("t = T.new()");
lua.safe_script("v1 = t.nf()");
lua.safe_script("v2 = t:nm()");
int v1 = lua["v1"];
int v2 = lua["v2"];
REQUIRE(v1 == 0x61);
REQUIRE(v2 == 0x62);
}
TEST_CASE("usertype/basic type information", "check that we can query some basic type information") {
struct my_thing {};
@ -1879,3 +1854,32 @@ TEST_CASE("usertype/basic type information", "check that we can query some basic
lua.safe_script("assert(not getmetatable(obj).__type.is(\"not a thing\"))");
lua.safe_script("print(getmetatable(obj).__type.name)");
}
#if !defined(_MSC_VER) || !(defined(_WIN32) && !defined(_WIN64))
TEST_CASE("usertype/noexcept-methods", "make sure noexcept functions and methods can be bound to usertypes without issues") {
struct T {
static int noexcept_function() noexcept {
return 0x61;
}
int noexcept_method() noexcept {
return 0x62;
}
};
sol::state lua;
lua.new_usertype<T>("T",
"nf", &T::noexcept_function,
"nm", &T::noexcept_method);
lua.safe_script("t = T.new()");
lua.safe_script("v1 = t.nf()");
lua.safe_script("v2 = t:nm()");
int v1 = lua["v1"];
int v2 = lua["v2"];
REQUIRE(v1 == 0x61);
REQUIRE(v2 == 0x62);
}
#endif // VC++ or my path/compiler settings doing strange bullshit (but it happens on Appveyor too???)