Skip to content

Commit

Permalink
Modify the repo to work with Travis CI (#1)
Browse files Browse the repository at this point in the history
* Modified tree to use C++17 to fight STL allocator errors

* Fixed syntax

* Removed semicolon warning because old habits die hard

* Removed pie and modules

* Forgot that cotire requires it to be set at the target level

* Forced to add rebind it seems like

* Gotta learn to build locally

* Debug attempt: checking the std version

* Wow I can't see the glaring 14 right in front of me

* Fine, I'll fix the bloody allocator for C++14 since 17 isn't ready yet.

* Fixed doxygen comments

* Implement the rest of the dumb STLAllocator

* Forced to disable the gold plugin. Sad day indeed.

* Removed the intentional failure on calls to unimplemented functions
  • Loading branch information
Cyberboss committed Oct 29, 2016
1 parent 23b916f commit e362e35
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 32 deletions.
4 changes: 2 additions & 2 deletions BuildScripts/Travis/Travis.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then
cmake . -DCMAKE_BUILD_TYPE=Release -DCOTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES=1
cmake . -DCMAKE_BUILD_TYPE=Release -DCOTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES=1 -DGOLD_PLUGIN=OFF
else
cmake . -DCMAKE_BUILD_TYPE=Debug -DCOTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES=1
cmake . -DCMAKE_BUILD_TYPE=Debug -DCOTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES=1 -DGOLD_PLUGIN=OFF
fi
make
ctest
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ include(${CYB_BASE_DIR}/BuildScripts/CMake/add_catch_tests.cmake)

enable_testing()

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CYB_BASE_DIR}/Output/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CYB_BASE_DIR}/Output/bin")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "\$ORIGIN")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -Wall -Werror -Wdocumentation -fpie -fmodules -fvisibility=hidden -D__USE_XOPEN2K8 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_DARWIN_FEATURE_64_BIT_INODE")
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -Wall -Werror -Wdocumentation -Wno-c++11-extra-semi -fvisibility=hidden -D__USE_XOPEN2K8 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_DARWIN_FEATURE_64_BIT_INODE")

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
option(GOLD_PLUGIN "Use the llvm gold plugin for link time code generation. RECOMMENDED" ON)
if(GOLD_PLUGIN)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
endif()

#support libs here

Expand Down
21 changes: 20 additions & 1 deletion Engine/API/Interop/STLAllocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,36 @@ namespace CYB {
namespace API {
namespace Interop {
//! @brief Remaps STL style allocations to the CyberEngine Allocator. Based on std::allocator, usable on STL containers
template <class AType> class STLAllocator {
template <typename AType> class STLAllocator {
public:
using pointer = AType*; //!< @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator">std::allocator::pointer</a>
using const_pointer = const AType*; //!< @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator">std::allocator::const_pointer</a>
using reference = AType&; //!< @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator">std::allocator::reference</a>
using const_reference = const AType&; //!< @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator">std::allocator::const_reference</a>
using size_type = unsigned long long; //!< @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator">std::allocator::size_type</a>
using difference_type = std::ptrdiff_t; //!< @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator">std::allocator::difference_type</a>

template<typename AOther> class rebind { public: typedef STLAllocator<AOther> other; }; //!< @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator">std::allocator::rebind</a>

using value_type = AType; //!< @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator">std::allocator</a>
using propagate_on_container_move_assignment = std::false_type; //!< @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator">std::allocator</a>
using is_always_equal = std::true_type; //!< @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator">std::allocator</a>
public:
//! @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator">std::allocator::address</a>
static pointer address(reference AObject) noexcept;
//! @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator">std::allocator::address</a>
static const_pointer address(const_reference AObject) noexcept;

//! @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator/allocate">std::allocator::allocate</a>
static AType* allocate(const std::size_t ACount);
//! @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator/deallocate">std::allocator::deallocate</a>
static void deallocate(AType* const AObject, const std::size_t ACount) noexcept;

//! @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator/construct">std::allocator::construct</a>
template <typename AOther, typename... AArgs> static void construct(AOther* const APointer, AArgs&&... AArguments);
//! @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator/destroy">std::allocator::destroy</a>
template <typename AOther> static void destroy(AOther* const APointer) noexcept;

//! @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator/allocator">std::allocator::allocator</a>
STLAllocator() noexcept = default;
//! @brief See <a href="http://en.cppreference.com/w/cpp/memory/allocator/allocator">std::allocator::allocator</a>
Expand Down
27 changes: 22 additions & 5 deletions Engine/API/Interop/STLAllocator.inl
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
#pragma once

template <class AType> AType* CYB::API::Interop::STLAllocator<AType>::allocate(const std::size_t ACount) {
template <typename AType> auto CYB::API::Interop::STLAllocator<AType>::address(reference AObject) noexcept -> pointer {
return std::addressof<AType>(AObject);
}

template <typename AType> auto CYB::API::Interop::STLAllocator<AType>::address(const_reference AObject) noexcept -> const_pointer {
return std::addressof<AType>(AObject);
}

template <typename AType> AType* CYB::API::Interop::STLAllocator<AType>::allocate(const std::size_t ACount) {
const auto Size(sizeof(AType) * ACount);
Assert::LessThanOrEqual<unsigned long long>(Size, static_cast<unsigned long long>(std::numeric_limits<int>::max()));
return static_cast<AType*>(Context::GetContext().FAllocator.FHeap.Alloc(static_cast<int>(Size)));
}

template <class AType> void CYB::API::Interop::STLAllocator<AType>::deallocate(AType* const AObject, const std::size_t ACount) noexcept {
template <typename AType> void CYB::API::Interop::STLAllocator<AType>::deallocate(AType* const AObject, const std::size_t ACount) noexcept {
const auto Size(sizeof(AType) * ACount);
Assert::LessThanOrEqual<unsigned long long>(Size, static_cast<unsigned long long>(std::numeric_limits<int>::max()));
Context::GetContext().FAllocator.FHeap.Free(AObject);
}

template <class AType> template <class AOtherType> CYB::API::Interop::STLAllocator<AType>::STLAllocator(const AOtherType& AOther) noexcept {
template <typename AType> template <typename AOther, typename... AArgs> void CYB::API::Interop::STLAllocator<AType>::construct(AOther* const APointer, AArgs&&... AArguments) {
::new (static_cast<void*>(APointer)) AOther(std::forward<AArgs>(AArguments)...);
}

template <typename AType> template <typename AOther> void CYB::API::Interop::STLAllocator<AType>::destroy(AOther* const APointer) noexcept {
static_cast<void>(APointer); //MSVC thinks calling the destructor counts as having the pointer being unreferenced
APointer->~AOther();
}

template <typename AType> template <typename AOtherType> CYB::API::Interop::STLAllocator<AType>::STLAllocator(const AOtherType& AOther) noexcept {
static_cast<void>(AOther);
}

template <class AType> template<class ARType> constexpr bool CYB::API::Interop::STLAllocator<AType>::operator==(const STLAllocator<ARType>& ARHS) const noexcept {
template <typename AType> template<typename ARType> constexpr bool CYB::API::Interop::STLAllocator<AType>::operator==(const STLAllocator<ARType>& ARHS) const noexcept {
static_cast<void>(ARHS);
return true;
}

template <class AType> template<class ARType> constexpr bool CYB::API::Interop::STLAllocator<AType>::operator!=(const STLAllocator<ARType>& ARHS) const noexcept {
template <typename AType> template<typename ARType> constexpr bool CYB::API::Interop::STLAllocator<AType>::operator!=(const STLAllocator<ARType>& ARHS) const noexcept {
static_cast<void>(ARHS);
return false;
}
16 changes: 2 additions & 14 deletions Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,8 @@ Engine/Core/CYBInterop.cpp
Engine/Core/CYBCore.cpp
)

set_property(TARGET EngineBase PROPERTY CXX_STANDARD 14)
set_property(TARGET EngineBase PROPERTY CXX_STANDARD_REQUIRED ON)

IF(CMAKE_BUILD_TYPE MATCHES Debug)
set_property(TARGET EngineBase PROPERTY COMPILE_FLAGS "-fprofile-arcs -ftest-coverage -pedantic")
IF(APPLE)
target_link_libraries(EngineBase dl -fprofile-arcs -ftest-coverage)
ELSE()
target_link_libraries(EngineBase dl -fprofile-arcs -ftest-coverage --coverage -fPIE -pie)
ENDIF()
ELSE()
set_property(TARGET EngineBase PROPERTY COMPILE_FLAGS "-pedantic")
target_link_libraries(EngineBase dl)
ENDIF()
set_property(TARGET EngineBase PROPERTY COMPILE_FLAGS "-pedantic")
target_link_libraries(EngineBase dl)

set_property (SOURCE "CYB.cpp" PROPERTY COTIRE_DEPENDENCY "TRUE")
set_target_properties(EngineBase PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "CYB.hpp")
Expand Down
3 changes: 0 additions & 3 deletions Executable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ ENDIF()
add_executable(${CYB_EXE_NAME}
CYBEntry.cpp)

set_property(TARGET ${CYB_EXE_NAME} PROPERTY CXX_STANDARD 14)
set_property(TARGET ${CYB_EXE_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)

target_link_libraries(${CYB_EXE_NAME} EngineBase)
3 changes: 0 additions & 3 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ API/Interop/STLAllocator.cpp

)

set_property(TARGET CyberEngineMkIIITester PROPERTY CXX_STANDARD 14)
set_property(TARGET CyberEngineMkIIITester PROPERTY CXX_STANDARD_REQUIRED ON)

target_link_libraries(CyberEngineMkIIITester EngineBase)

set_property (SOURCE "TestHeader.cpp" PROPERTY COTIRE_DEPENDENCY "TRUE")
Expand Down
1 change: 0 additions & 1 deletion Tests/Utils/HCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ void CYB::API::Assert::HCF[[noreturn]](void) noexcept {

void CYB::API::Assert::Unimplemented(const char* const AFunction, const char* const AFile, const unsigned int ALine) noexcept {
WARN(std::string("Call to unimplemented function \"") + AFunction + "\" in file \"" + AFile + "\" at line: " + std::to_string(ALine));
CHECK(false);
}

0 comments on commit e362e35

Please sign in to comment.