Cleanup cmake file.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2020-07-18 12:42:54 +02:00
parent 41b15dc693
commit dc3630b171
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
31 changed files with 141 additions and 69 deletions

View File

@ -1,3 +1,4 @@
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
#include "../Core.hpp"

View File

@ -1,23 +1,21 @@
cmake_minimum_required(VERSION 3.13)
# Make warnings trigger errors.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
project(pkmnLib)
# Enable all warnings, and make them error when occurring.
add_compile_options(-Wall -Wextra -Werror)
# We like new stuff, so set the c++ standard to c++20.
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (NOT SCRIPT_PROVIDER)
message(WARNING "Script provider was not set, using angelscript as default.")
set(SCRIPT_PROVIDER "angelscript")
ADD_DEFINITIONS(-D ANGELSCRIPT=1)
endif()
option(WINDOWS "Whether the build target is Windows or not." OFF)
option(SHARED "Whether we should build a shared library, instead of a static one." OFF)
option(TESTS "Whether the test executable should be build as well." OFF)
option(STATICC "Whether gcc and stdc++ should be linked statically to the library." OFF)
set(SCRIPT_PROVIDER "angelscript" CACHE STRING "Which script provider to use.")
if (WINDOWS)
SET(CMAKE_SYSTEM_NAME Windows)
ADD_DEFINITIONS(-D WINDOWS=1)
endif(WINDOWS)
endif (WINDOWS)
message(STATUS "Using:
\t C ${CMAKE_C_COMPILER}
@ -25,37 +23,20 @@ message(STATUS "Using:
\t CXX ABI ${CMAKE_CXX_COMPILER_ABI}
\t C++ Version ${CMAKE_CXX_STANDARD}")
if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
message(WARNING "The file conanbuildinfo.cmake doesn't exist, running conan install.")
string(REPLACE "." ";" VERSION_LIST "${CMAKE_C_COMPILER_VERSION}")
list(GET VERSION_LIST 0 VERSION)
list(GET VERSION_LIST 1 MINOR)
if (NOT MINOR MATCHES 0)
SET(VERSION ${VERSION}.${MINOR})
endif ()
set(CONAN_STATIC_C False)
if (STATICC)
set(CONAN_STATIC_C True)
endif (STATICC)
if (NOT WINDOWS)
execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build outdated
-s compiler=clang -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION} -o *:staticC=${CONAN_STATIC_C} -o AngelScript:link_std_statically=True)
else ()
execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build outdated
-s compiler=gcc -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION} -s os=Windows -o *:staticC=${CONAN_STATIC_C} -o AngelScript:link_std_statically=True)
endif ()
endif ()
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
include(CmakeConanSetup.cmake)
SetupConan()
message(STATUS "Using Conan Libs:")
foreach (_conanLib ${CONAN_LIBS})
message(STATUS "\t ${_conanLib}")
endforeach()
endforeach ()
# Set whether we want a static or shared library.
set(LIBTYPE STATIC)
if (SHARED)
set(LIBTYPE SHARED)
endif (SHARED)
# Create Core library with files in src/Core
SET(FILE_SOURCE
"src/Battling/*.cpp"
"src/Battling/*.hpp"
@ -78,22 +59,19 @@ if (SCRIPT_PROVIDER STREQUAL "angelscript")
)
ADD_DEFINITIONS(-D AS_USE_ACCESSORS=1)
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()
add_library(pkmnLib ${LIBTYPE} ${CORE_SRC_FILES})
SET(_LINKS CreatureLibLibrary CreatureLibBattling Arbutils)
SET(_TESTLINKS pkmnLib CreatureLibLibrary CreatureLibBattling Arbutils)
if (SCRIPT_PROVIDER STREQUAL "angelscript")
SET(_LINKS angelscript ${_LINKS} )
SET(_TESTLINKS angelscript ${_TESTLINKS} )
endif()
message(STATUS "Using Angelscript as script provider.")
ADD_DEFINITIONS(-D ANGELSCRIPT=1)
SET(_LINKS angelscript ${_LINKS})
SET(_TESTLINKS angelscript ${_TESTLINKS})
endif ()
if (WINDOWS)
message(STATUS "Using Windows build.")
@ -104,17 +82,14 @@ endif (WINDOWS)
if (STATICC)
message(STATUS "Linking C library statically")
SET(_LINKS ${_LINKS} -static-libgcc -static-libstdc++)
if (NOT DEFINED CONAN_EXPORTED)
SET(_TESTLINKS ${_TESTLINKS} -static-libgcc -static-libstdc++)
endif()
endif()
target_link_libraries(pkmnLib PUBLIC ${_LINKS})
if (NOT DEFINED CONAN_EXPORTED)
if (TESTS)
# Create Test executable
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
add_executable(pkmnLibTests ${TEST_FILES} extern/catch.hpp)
add_executable(pkmnLibTests ${TEST_FILES} extern/catch.hpp)
message(STATUS "${_TESTLINKS}")
target_link_libraries(pkmnLibTests PUBLIC ${_TESTLINKS})

22
CmakeConanSetup.cmake Normal file
View File

@ -0,0 +1,22 @@
function(SetupConan)
# If conan isn't set up yet, we need to install the dependencies.
if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
message(WARNING "The file conanbuildinfo.cmake doesn't exist, running conan install.")
# If we're linking C statically, we also want to do so for our dependencies.
set(CONAN_STATIC_C False)
if (STATICC)
set(CONAN_STATIC_C True)
endif (STATICC)
if (NOT WINDOWS)
execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build outdated
-s compiler=clang -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION} -o *:staticC=${CONAN_STATIC_C} -o AngelScript:link_std_statically=True)
else ()
execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build outdated
-s compiler=gcc -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION} -s os=Windows -o *:staticC=${CONAN_STATIC_C} -o AngelScript:link_std_statically=True)
endif ()
endif ()
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
endfunction()

View File

@ -3,7 +3,10 @@
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
#endif
// Sometimes it may be desired to use the same method names as used by C++ STL.

View File

@ -14,21 +14,21 @@
// TODO: Implement flags for turning on/off include directives and conditional programming
//---------------------------
// Declaration
//
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
#endif
#if defined(_MSC_VER) && _MSC_VER <= 1200
// disable the annoying warnings on MSVC 6
#pragma warning (disable:4786)
#pragma warning(disable : 4786)
#endif
#include <string>

View File

@ -191,7 +191,7 @@ void CScriptHandle::EnumReferences(asIScriptEngine* inEngine) {
inEngine->GCEnumCallback(m_type);
}
void CScriptHandle::ReleaseReferences(asIScriptEngine* inEngine) {
void CScriptHandle::ReleaseReferences(asIScriptEngine*) {
// Simply clear the content to release the references
Set(0, 0);
}

View File

@ -3,7 +3,10 @@
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
#endif

View File

@ -6,7 +6,10 @@
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
#endif

View File

@ -13,7 +13,10 @@
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
#endif
#include <string>

View File

@ -18,14 +18,15 @@ uint32_t PkmnLib::Battling::DamageLibrary::GetDamage(CreatureLib::Battling::Exec
return damage;
}
uint8_t PkmnLib::Battling::DamageLibrary::GetBasePower(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
const HitData& hitData) const {
[[maybe_unused]] CreatureLib::Battling::Creature* target,
[[maybe_unused]] uint8_t hitIndex,
[[maybe_unused]] const HitData& hitData) const {
auto bp = attack->GetAttack()->GetAttack()->GetBasePower();
// HOOK: modify base power.
return bp;
}
float PkmnLib::Battling::DamageLibrary::GetStatModifier(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
CreatureLib::Battling::Creature* target, uint8_t,
const HitData& hitData) const {
auto user = attack->GetUser();
// HOOK: allow overriding for which users stat we use.

View File

@ -2,6 +2,9 @@
#define PKMNLIB_PKMNSCRIPT_HPP
#include <CreatureLib/Battling/ScriptHandling/Script.hpp>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
namespace PkmnLib::Battling {
class PkmnScript : public CreatureLib::Battling::Script {
public:
@ -19,5 +22,6 @@ namespace PkmnLib::Battling {
CreatureLib::Battling::Creature* winningMon, bool* shareExperience){};
};
}
#pragma clang diagnostic pop
#endif // PKMNLIB_PKMNSCRIPT_HPP

View File

@ -115,7 +115,7 @@ void AngelScriptResolver::RegisterTypes() {
BasicScriptClass::Register(_engine);
}
void AngelScriptResolver::MessageCallback(const asSMessageInfo* msg, void* param) {
void AngelScriptResolver::MessageCallback(const asSMessageInfo* msg, void*) {
const char* type = "ERR ";
if (msg->type == asMSGTYPE_WARNING)
type = "WARN";
@ -265,7 +265,7 @@ void AngelScriptResolver::LoadByteCodeFromFile(const char* file) {
// Begin loading the type database
auto types = stream->ReadTypes();
InitializeByteCode(stream, types);
InitializeByteCode(types);
Assert(fclose(rFile) == 0);
delete stream;
}
@ -297,11 +297,10 @@ void AngelScriptResolver::LoadByteCodeFromMemory(uint8_t* byte, size_t size) {
// Begin loading the type database
auto types = stream->ReadTypes();
InitializeByteCode(stream, types);
InitializeByteCode(types);
delete stream;
}
void AngelScriptResolver::InitializeByteCode(
asIBinaryStream* stream,
const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, uint32_t>>& types) {
auto typeCount = _mainModule->GetObjectTypeCount();

View File

@ -25,8 +25,7 @@ private:
void RegisterTypes();
void
InitializeByteCode(asIBinaryStream* stream,
const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, uint32_t>>& types);
InitializeByteCode(const ArbUt::Dictionary<ScriptCategory, ArbUt::Dictionary<ArbUt::StringView, uint32_t>>& types);
public:
~AngelScriptResolver() override {
@ -64,7 +63,7 @@ public:
int r = _engine->RegisterObjectMethod(type, decl, asFunctionPtr(func), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
}
void RegisterGlobalMethod(const char* decl, void*(func)(void*)) {
void RegisterGlobalMethod(const char*, void*(func)(void*)) {
auto r = _engine->RegisterGlobalFunction("decl", asFunctionPtr(func), asCALL_CDECL);
Assert(r >= 0);
}

View File

@ -3,7 +3,12 @@
#include <CreatureLib/Battling/ScriptHandling/Script.hpp>
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
#include <CreatureLib/Library/Exceptions/NotImplementedException.hpp>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
#include <cstdint>
#include "../../../extern/angelscript_addons/scriptarray/scriptarray.h"
#include "../../Battling/PkmnScript.hpp"

View File

@ -5,7 +5,10 @@
#include <Arbutils/Collections/Dictionary.hpp>
#include <Arbutils/StringView.hpp>
#include <CreatureLib/Library/Exceptions/CreatureException.hpp>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
#include <cstring>
#include <unordered_map>
#include <utility>

View File

@ -1,7 +1,10 @@
#ifndef PKMNLIB_CONTEXTPOOL_HPP
#define PKMNLIB_CONTEXTPOOL_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
#include <vector>
class ContextPool {

View File

@ -1,7 +1,11 @@
#ifndef PKMNLIB_BASICSCRIPTCLASS_HPP
#define PKMNLIB_BASICSCRIPTCLASS_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class BasicScriptClass {
public:
static void Register(asIScriptEngine* engine);

View File

@ -1,7 +1,10 @@
#ifndef PKMNLIB_REGISTERBATTLECLASS_HPP
#define PKMNLIB_REGISTERBATTLECLASS_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class RegisterBattleClass {
static void RegisterChoiceQueue(asIScriptEngine* engine);
static void RegisterBattle(asIScriptEngine* engine);

View File

@ -1,7 +1,11 @@
#ifndef PKMNLIB_REGISTERBATTLELIBRARY_HPP
#define PKMNLIB_REGISTERBATTLELIBRARY_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class RegisterBattleLibrary {
static void RegisterDamageLibrary(asIScriptEngine* engine);
static void RegisterLibrary(asIScriptEngine* engine);

View File

@ -1,7 +1,9 @@
#ifndef PKMNLIB_REGISTEREXECUTINGATTACK_HPP
#define PKMNLIB_REGISTEREXECUTINGATTACK_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class RegisterExecutingAttack {
static void RegisterHitData(asIScriptEngine* engine);

View File

@ -1,7 +1,11 @@
#ifndef PKMNLIB_REGISTERPOKEMONCLASS_HPP
#define PKMNLIB_REGISTERPOKEMONCLASS_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class RegisterPokemonClass {
static void RegisterDamageSource(asIScriptEngine* engine);
static void RegisterMoveLearnMethod(asIScriptEngine* engine);

View File

@ -1,7 +1,11 @@
#ifndef PKMNLIB_REGISTERTURNCHOICES_HPP
#define PKMNLIB_REGISTERTURNCHOICES_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class RegisterTurnChoices {
static void RegisterTurnChoiceKindEnum(asIScriptEngine* engine);
static void RegisterBaseTurnChoice(asIScriptEngine* engine);

View File

@ -1,7 +1,11 @@
#ifndef PKMNLIB_CONSTSTRING_HPP
#define PKMNLIB_CONSTSTRING_HPP
#include <Arbutils/Assert.hpp>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class ConstStringRegister {
public:
static void Register(asIScriptEngine* engine);

View File

@ -1,4 +1,4 @@
#define BORROWED_PTR_GETTER_FUNC(o, returns, funcName) \
static returns* funcName##Wrapper(o* obj) { return obj->funcName().GetRaw(); }
#define UNIQUE_PTR_GETTER_FUNC(o, returns, funcName) \
static returns* funcName##Wrapper(o* obj) { return obj->funcName().get(); }
static returns* funcName##Wrapper(o* obj) { return obj->funcName().get(); }

View File

@ -1,7 +1,11 @@
#ifndef PKMNLIB_REGISTEREFFECTPARAMETER_HPP
#define PKMNLIB_REGISTEREFFECTPARAMETER_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class RegisterEffectParameter {
public:
static void Register(asIScriptEngine* engine);

View File

@ -1,6 +1,9 @@
#ifndef PKMNLIB_REGISTERGROWTHRATETYPES_HPP
#define PKMNLIB_REGISTERGROWTHRATETYPES_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class RegisterGrowthRateTypes {
static void RegisterGrowthRateType(asIScriptEngine* engine);

View File

@ -1,6 +1,9 @@
#ifndef PKMNLIB_REGISTERITEMTYPES_HPP
#define PKMNLIB_REGISTERITEMTYPES_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class RegisterItemTypes {
static void RegisterItemCategoryEnum(asIScriptEngine* engine);

View File

@ -1,6 +1,9 @@
#ifndef PKMNLIB_REGISTERMOVETYPES_HPP
#define PKMNLIB_REGISTERMOVETYPES_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class RegisterMoveTypes {
static void RegisterMoveCategory(asIScriptEngine* engine);

View File

@ -1,6 +1,9 @@
#ifndef PKMNLIB_REGISTERSPECIESTYPES_HPP
#define PKMNLIB_REGISTERSPECIESTYPES_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class RegisterSpeciesTypes {
public:

View File

@ -1,7 +1,11 @@
#ifndef PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP
#define PKMNLIB_REGISTERSTATICLIBRARYTYPES_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class RegisterStaticLibraryTypes {
static void RegisterLibrarySettingsType(asIScriptEngine* engine);
static void RegisterLibraryType(asIScriptEngine* engine);

View File

@ -1,6 +1,9 @@
#ifndef PKMNLIB_REGISTERTYPELIBRARY_HPP
#define PKMNLIB_REGISTERTYPELIBRARY_HPP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <angelscript.h>
#pragma clang diagnostic pop
class RegisterTypeLibrary {
static void RegisterTypeLibraryType(asIScriptEngine* engine);