Fixes for Windows ;_;
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-01-12 18:20:59 +01:00
parent ca707e5384
commit 72c2e38ea8
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
14 changed files with 71 additions and 49 deletions

View File

@ -61,6 +61,5 @@ steps:
- cmake --build build-release-windows --target all -- -j 4
- cp /usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll /drone/src/build-release-windows/bin/
- cp /drone/src/build-release-windows/lib/libpkmnLib.so /drone/src/build-release-windows/bin/
- cp /drone/src/build-release-windows/lib/libpkmnLib-angelscript.so /drone/src/build-release-windows/bin/
- export WINEARCH=win64
- wine build-release-windows/bin/pkmnLibTests.exe -s

View File

@ -20,14 +20,12 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
endif(WINDOWS)
message(STATUS "Using:
\t C ${CMAKE_C_COMPILER}
\t C++ ${CMAKE_CXX_COMPILER}
\t CXX ABI ${CMAKE_CXX_COMPILER_ABI}
\t C++ Version ${CMAKE_CXX_STANDARD}")
message(STATUS "Script Provider: ${SCRIPT_PROVIDER}")
if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
message(WARNING "The file conanbuildinfo.cmake doesn't exist, running conan install.")
@ -39,7 +37,7 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
endif()
if (NOT WINDOWS)
execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing
-s compiler=clang -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION} -o AngelScript:shared=True)
-s compiler=clang -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION})
else()
execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing
-s compiler=gcc -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION} -s os=Windows)
@ -54,42 +52,57 @@ foreach (_conanLib ${CONAN_LIBS})
endforeach()
# Create Core library with files in src/Core
file(GLOB_RECURSE CORE_SRC_FILES "src/Battling/*.cpp" "src/Battling/*.hpp" "src/Library/*.cpp" "src/Library/*.hpp")
SET(FILE_SOURCE
"src/Battling/*.cpp"
"src/Battling/*.hpp"
"src/Library/*.cpp"
"src/Library/*.hpp"
)
if (SCRIPT_PROVIDER STREQUAL "angelscript")
SET(FILE_SOURCE ${FILE_SOURCE}
"src/AngelScript/AngelScripResolver.cpp"
"src/AngelScript/AngelScripResolver.hpp"
"src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp"
"src/AngelScript/TypeRegistry/RegisterPokemonTypes.hpp"
"extern/angelscript_addons/*.cpp"
"extern/angelscript_addons/*.h"
)
endif()
message(STATUS "${FILE_SOURCE}")
file(GLOB_RECURSE CORE_SRC_FILES ${FILE_SOURCE})
add_library(pkmnLib SHARED ${CORE_SRC_FILES})
foreach (_variableName ${CONAN_LIBS})
message(STATUS "Lib: ${_variableName}")
endforeach()
SET(_LINKS CreatureLibCore CreatureLibLibrary CreatureLibBattling)
SET(_TESTLINKS pkmnLib CreatureLibCore CreatureLibLibrary CreatureLibBattling)
if (SCRIPT_PROVIDER STREQUAL "angelscript")
SET(_LINKS angelscript ${_LINKS} )
SET(_TESTLINKS angelscript ${_TESTLINKS} )
endif()
if (WINDOWS)
message(STATUS "Using Windows build.")
set(CMAKE_CXX_FLAGS "-L ${CMAKE_BINARY_DIR}/bin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L ${CMAKE_BINARY_DIR}/bin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -Wa,-mbig-obj -Wl,-allow-multiple-definition")
# Statically link libraries we need in Windows.
SET(_LINKS ${_LINKS} -static-libgcc -static-libstdc++)
SET(_TESTLINKS ${_TESTLINKS} -static-libgcc -static-libstdc++)
endif (WINDOWS)
if (SCRIPT_PROVIDER STREQUAL "angelscript")
message(STATUS "Creating angelscript implementation.")
file(GLOB_RECURSE ANGELSCRIPT_SRC_FILES "src/AngelScript/*.cpp" "src/AngelScript/*.hpp" "extern/angelscript_addons/*.cpp" "extern/angelscript_addons/*.h")
add_library(pkmnLib-angelscript SHARED ${ANGELSCRIPT_SRC_FILES} )
SET(SCRIPT_PROVIDER_LIB_NAME "pkmnLib-angelscript")
SET(_LINKS ${_LINKS} angelscript)
endif()
target_link_libraries(pkmnLib PUBLIC ${_LINKS})
if (SCRIPT_PROVIDER STREQUAL "angelscript")
SET(GCC_COVERAGE_COMPILE_FLAGS "-fno-strict-aliasing")
target_link_libraries(pkmnLib-angelscript PUBLIC ${_LINKS})
endif()
if (NOT DEFINED CONAN_EXPORTED)
# Create Test executable
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
add_executable(pkmnLibTests ${TEST_FILES} extern/catch.hpp)
target_link_libraries(pkmnLibTests PUBLIC ${_TESTLINKS} ${SCRIPT_PROVIDER_LIB_NAME})
message(STATUS "${_TESTLINKS}")
target_link_libraries(pkmnLibTests PUBLIC ${_TESTLINKS})
# Add a definition for the test library
target_compile_definitions(pkmnLibTests PRIVATE TESTS_BUILD)
@ -100,3 +113,4 @@ endif ()

View File

@ -1,4 +1,5 @@
from conans import ConanFile, CMake
from conans.errors import ConanInvalidConfiguration
class PkmnLibConan(ConanFile):
@ -7,14 +8,11 @@ class PkmnLibConan(ConanFile):
url = "https://git.p-epsilon.com/Deukhoofd/CreatureLib"
description = "The core implementation for turn based battling using creatures."
settings = "os", "compiler"
options = {"shared": [True, False]}
default_options = {"shared": True}
options = {"shared": [True, False], "script_handler": ["angelscript"]}
default_options = {"shared": True, "script_handler": "angelscript"}
generators = "cmake"
exports_sources = "*"
compiler = "clang"
requires = \
"CreatureLib/779f0b08cfc7d2b19ee0bd27c61a28807172bc1f@creaturelib/master", \
"AngelScript/2.34@AngelScript/Deukhoofd"
def build(self):
cmake = CMake(self)
@ -33,3 +31,17 @@ class PkmnLibConan(ConanFile):
def imports(self):
if self.settings.os == "Windows":
self.copy("*.dll", "bin", "bin")
def configure(self):
if self.options.script_handler == "angelscript":
self.options["AngelScript"].shared = True
if self.settings.os == "Windows":
self.options["AngelScript"].link_std_statically = True
def requirements(self):
self.requires("CreatureLib/b02577554f4dfe2141318a440fc99c11de97daca@creaturelib/master")
if self.options.script_handler == "angelscript":
self.requires("AngelScript/2.34@AngelScript/Deukhoofd")
else:
raise ConanInvalidConfiguration("Invalid Script Handler was specified: " + self.options.script_handler)

View File

@ -975,7 +975,8 @@ string ScriptGetExceptionInfo()
void RegisterExceptionRoutines(asIScriptEngine *engine)
{
int r;
[[maybe_unused]]
int r;
// The string type must be available
assert(engine->GetTypeInfoByDecl("string"));

View File

@ -112,7 +112,8 @@ static void StringJoin_Generic(asIScriptGeneric *gen)
// The string type must have been registered first.
void RegisterStdStringUtils(asIScriptEngine *engine)
{
int r;
[[maybe_unused]]
int r;
if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
{

View File

@ -6,6 +6,7 @@
CreatureLib::Battling::ScriptResolver* PkmnLib::Battling::BattleLibrary::CreateScriptResolver(){
return new AngelScripResolver();
}
void AngelScripResolver::Initialize(CreatureLib::Battling::BattleLibrary* library) {
_engine = asCreateScriptEngine();

View File

@ -4,9 +4,8 @@
#include <Battling/ScriptHandling/ScriptResolver.hpp>
#include "../Battling/Library/BattleLibrary.hpp"
#undef GetProperty
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
#include <angelscript.h>
#include <cassert>
#include <iostream>
#include "AngelScriptScript.hpp"
#include "AngelScriptTypeInfo.hpp"

View File

@ -1,2 +1 @@
#undef GetProperty
#include "AngelScriptScript.hpp"

View File

@ -1,7 +1,7 @@
#ifndef PKMNLIB_ANGELSCRIPTSCRIPT_HPP
#define PKMNLIB_ANGELSCRIPTSCRIPT_HPP
#include <Battling/ScriptHandling/Script.hpp>
#undef GetProperty
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
#include <angelscript.h>
#include "AngelScriptTypeInfo.hpp"
#include "ContextPool.hpp"
@ -15,20 +15,20 @@ private:
public:
AngelScriptScript(const std::string& name, AngelScriptTypeInfo* type, asIScriptObject* obj, ContextPool* ctxPool)
: CreatureLib::Battling::Script(name), _type(type), _ctxPool(ctxPool), _obj(obj) {
}
: CreatureLib::Battling::Script(name), _type(type), _ctxPool(ctxPool), _obj(obj) {}
~AngelScriptScript() override { _obj->Release(); }
void InvokeMethod(const char* name) {
auto func = _type->GetFunction(name);
if (func == nullptr) return;
if (func == nullptr)
return;
auto ctx = _ctxPool->RequestContext();
ctx->Prepare(func);
ctx->SetObject(_obj);
auto result = ctx->Execute();
if (result != asEXECUTION_FINISHED){
if (result == asEXECUTION_EXCEPTION){
if (result != asEXECUTION_FINISHED) {
if (result == asEXECUTION_EXCEPTION) {
throw CreatureException(ctx->GetExceptionString());
}
throw CreatureException("Function failed.");
@ -36,20 +36,16 @@ public:
_ctxPool->ReturnContextToPool(ctx);
}
asIScriptObject* GetScriptObject(){
return _obj;
}
asIScriptObject* GetScriptObject() { return _obj; }
asIScriptFunction* PrepareMethod(const char* name, asIScriptContext* ctx){
asIScriptFunction* PrepareMethod(const char* name, asIScriptContext* ctx) {
auto func = _type->GetFunction(name);
ctx->Prepare(func);
ctx->SetObject(_obj);
return func;
}
ContextPool* GetContextPool(){
return _ctxPool;
}
ContextPool* GetContextPool() { return _ctxPool; }
};
#endif // PKMNLIB_ANGELSCRIPTSCRIPT_HPP

View File

@ -1,6 +1,7 @@
#ifndef PKMNLIB_ANGELSCRIPTTYPEINFO_HPP
#define PKMNLIB_ANGELSCRIPTTYPEINFO_HPP
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
#include <angelscript.h>
#include <unordered_map>
#include <Core/Exceptions/CreatureException.hpp>

View File

@ -8,13 +8,14 @@ void RegisterPokemonTypes::Register(asIScriptEngine* engine) {
}
void RegisterPokemonTypes::RegisterGenderEnum(asIScriptEngine* engine) {
int r = engine->RegisterEnum("Gender"); assert(r >= 0);
[[maybe_unused]] int r = engine->RegisterEnum("Gender"); assert(r >= 0);
r = engine->RegisterEnumValue("Gender", "Male", 0); assert(r >= 0);
r = engine->RegisterEnumValue("Gender", "Female", 1); assert(r >= 0);
r = engine->RegisterEnumValue("Gender", "Genderless", 2); assert(r >= 0);
}
void RegisterPokemonTypes::RegisterSpeciesType(asIScriptEngine* engine) {
[[maybe_unused]]
int r = engine->RegisterObjectType("Species", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("Species", "const string& get_Name() const property",
@ -32,5 +33,4 @@ void RegisterPokemonTypes::RegisterSpeciesType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Species", "Gender GetRandomGender() const",
asMETHOD(PkmnLib::Library::PokemonSpecies, GetRandomGender), asCALL_THISCALL);
assert(r >= 0);
}

View File

@ -1,5 +1,5 @@
#include "CreatePokemon.hpp"
#include "../../Library/Statistic.hpp"
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(CreatureLib::Core::Random rand) {
_ivHp = rand.Get(0, 32);
_ivAttack = rand.Get(0, 32);

View File

@ -30,10 +30,10 @@ namespace PkmnLib::Battling {
_individualValues(individualValues), _effortValues(effortValues), _nature(nature) {}
const Library::Nature& GetNature() const;
const uint8_t GetIndividualValue(CreatureLib::Core::Statistic stat) const {
uint8_t GetIndividualValue(CreatureLib::Core::Statistic stat) const {
return _individualValues.GetStat(stat);
}
const uint8_t GetEffortValue(CreatureLib::Core::Statistic stat) const { return _effortValues.GetStat(stat); }
uint8_t GetEffortValue(CreatureLib::Core::Statistic stat) const { return _effortValues.GetStat(stat); }
};
}

View File

@ -126,5 +126,4 @@ TEST_CASE("Test whether species object was properly registered.") {
}
#endif