Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Jun 24, 2024
1 parent fc4ca1a commit 6f6fee8
Show file tree
Hide file tree
Showing 43 changed files with 540 additions and 662 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
fail-fast: false
matrix:
toolset: [""]
build_type: [Release]
build_type: [Release, Debug]
build_shared_libs: [OFF] # TODO(JS): Add ON once shared lib build is resolved

steps:
Expand Down Expand Up @@ -93,8 +93,12 @@ jobs:
|| exit /b
build_on_pixi:
name: win-pixi
name: win-pixi${{ matrix.build_type }}
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
build_type: ["", "-dev"]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -109,4 +113,4 @@ jobs:

- name: Test DART and dartpy
run: |
pixi run test # TODO: Change to test-all
pixi run test${{ matrix.build_type }} # TODO: Change to test-all
64 changes: 34 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,11 @@ endif()
#===============================================================================
# Build type settings
#===============================================================================
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug | Release | RelWithDebInfo | MinSizeRel" FORCE)
endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE)

set(DART_BUILD_MODE_DEBUG FALSE)
set(DART_BUILD_MODE_RELEASE FALSE)

if("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "DEBUG")
set(DART_BUILD_MODE_DEBUG TRUE)
elseif("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "RELEASE")
set(DART_BUILD_MODE_RELEASE TRUE)
elseif("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "RELWITHDEBINFO")
set(DART_BUILD_MODE_RELEASE TRUE)
elseif("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "MINSIZEREL")
set(DART_BUILD_MODE_RELEASE TRUE)
else()
message(WARNING "CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} unknown. Valid options are: Debug | Release | RelWithDebInfo | MinSizeRel")
if(NOT CMAKE_CONFIGURATION_TYPES)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
endif()

# Active log level:
Expand All @@ -191,14 +178,33 @@ endif()
# - ERROR: To enable log with DART_ERROR() and below
# - FATAL: To enable log with DART_FATAL()
# - OFF: To turn off all the logs
if(DART_BUILD_MODE_DEBUG)
set(DART_ACTIVE_LOG_LEVEL "DEBUG" CACHE STRING "Compile time active log level to enable")
if(NOT DART_ACTIVE_LOG_LEVEL)
if(NOT CMAKE_CONFIGURATION_TYPES AND CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DART_ACTIVE_LOG_LEVEL "DEBUG" CACHE STRING "Compile time active log level to enable")
else()
set(DART_ACTIVE_LOG_LEVEL "INFO" CACHE STRING "Compile time active log level to enable")
endif()
set_property(CACHE DART_ACTIVE_LOG_LEVEL PROPERTY STRINGS TRACE DEBUG INFO WARN ERROR FATAL OFF)
endif()
if(DART_ACTIVE_LOG_LEVEL STREQUAL "TRACE")
set(DART_ACTIVE_LOG_LEVEL_VALUE 0)
elseif(DART_ACTIVE_LOG_LEVEL STREQUAL "DEBUG")
set(DART_ACTIVE_LOG_LEVEL_VALUE 1)
elseif(DART_ACTIVE_LOG_LEVEL STREQUAL "INFO")
set(DART_ACTIVE_LOG_LEVEL_VALUE 2)
elseif(DART_ACTIVE_LOG_LEVEL STREQUAL "WARN")
set(DART_ACTIVE_LOG_LEVEL_VALUE 3)
elseif(DART_ACTIVE_LOG_LEVEL STREQUAL "ERROR")
set(DART_ACTIVE_LOG_LEVEL_VALUE 4)
elseif(DART_ACTIVE_LOG_LEVEL STREQUAL "FATAL")
set(DART_ACTIVE_LOG_LEVEL_VALUE 5)
elseif(DART_ACTIVE_LOG_LEVEL STREQUAL "OFF")
set(DART_ACTIVE_LOG_LEVEL_VALUE 6)
else()
set(DART_ACTIVE_LOG_LEVEL "INFO" CACHE STRING "Compile time active log level to enable")
message(FATAL_ERROR "Unknown DART_ACTIVE_LOG_LEVEL: ${DART_ACTIVE_LOG_LEVEL}")
endif()
set_property(CACHE DART_ACTIVE_LOG_LEVEL PROPERTY STRINGS TRACE DEBUG INFO WARN ERROR FATAL OFF)

if(DART_BUILD_MODE_DEBUG)
if(NOT CMAKE_CONFIGURATION_TYPES AND CMAKE_BUILD_TYPE STREQUAL "Debug")
option(DART_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
else()
option(DART_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" ON)
Expand Down Expand Up @@ -355,14 +361,12 @@ if(DART_VERBOSE)
message(STATUS "Build gui::osg : ${DART_BUILD_GUI_OSG}")
message(STATUS "Install path : ${CMAKE_INSTALL_PREFIX}")
message(STATUS "CXX_FLAGS : ${CMAKE_CXX_FLAGS}")
if(${CMAKE_BUILD_TYPE_UPPERCASE} STREQUAL "RELEASE")
message(STATUS "CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
elseif(${CMAKE_BUILD_TYPE_UPPERCASE} STREQUAL "DEBUG")
message(STATUS "CXX_FLAGS_DEBUG : ${CMAKE_CXX_FLAGS_DEBUG}")
elseif(${CMAKE_BUILD_TYPE_UPPERCASE} STREQUAL "RELWITHDEBINFO")
if(NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "CXX_FLAGS_RELEASE : ${CMAKE_CXX_FLAGS_RELEASE}")
message(STATUS "CXX_FLAGS_DEBUG : ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "CXX_FLAGS_MINSIZEREL : ${CXX_FLAGS_MINSIZEREL}")
message(STATUS "CXX_FLAGS_RELWITHDEBINFO: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
elseif(${CMAKE_BUILD_TYPE_UPPERCASE} STREQUAL "PROFILE")
message(STATUS "CXX_FLAGS_PROFILE: ${CMAKE_CXX_FLAGS_PROFILE}")
message(STATUS "CXX_FLAGS_PROFILE : ${CMAKE_CXX_FLAGS_PROFILE}")
endif()
message(STATUS "DART_SOURCE_DIR : ${DART_SOURCE_DIR}")
message(STATUS "DART_BINARY_DIR : ${DART_BINARY_DIR}")
Expand Down
2 changes: 0 additions & 2 deletions dart/common/FreeListAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ void FreeListAllocator::MemoryBlockHeader::merge(MemoryBlockHeader* other)
}

//==============================================================================
#if DART_BUILD_MODE_DEBUG
bool FreeListAllocator::MemoryBlockHeader::isValid() const
{
if (mPrev != nullptr && mPrev->mNext != this) {
Expand All @@ -385,6 +384,5 @@ bool FreeListAllocator::MemoryBlockHeader::isValid() const

return true;
}
#endif

} // namespace dart::common
2 changes: 0 additions & 2 deletions dart/common/FreeListAllocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ class FreeListAllocator : public MemoryAllocator
/// Merges this memory block with the given memory block
void merge(MemoryBlockHeader* other);

#if DART_BUILD_MODE_DEBUG
/// [Debug only] Returns whether this memory block is valid
bool isValid() const;
#endif
};

/// Allocates a new memory block for \c sizeToAllocate bytes
Expand Down
7 changes: 2 additions & 5 deletions dart/common/Logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#ifndef DART_COMMON_LOGGING_HPP_
#define DART_COMMON_LOGGING_HPP_

#include <dart/config.hpp>

// clang-format off
#define DART_LOG_LEVEL_TRACE 0
#define DART_LOG_LEVEL_DEBUG 1
Expand All @@ -43,11 +45,6 @@
#define DART_LOG_LEVEL_OFF 6
// clang-format on

// Default active log level
#if !defined(DART_ACTIVE_LOG_LEVEL)
#define DART_ACTIVE_LOG_LEVEL DART_LOG_LEVEL_INFO
#endif

#if DART_ACTIVE_LOG_LEVEL <= DART_LOG_LEVEL_TRACE
#define DART_TRACE(...) ::dart::common::trace(__VA_ARGS__)
#else
Expand Down
28 changes: 1 addition & 27 deletions dart/common/MemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include "dart/common/MemoryManager.hpp"

#if DART_BUILD_MODE_DEBUG
#ifndef NDEBUG
#include "dart/common/Logging.hpp"
#endif

Expand All @@ -49,11 +49,7 @@ MemoryManager& MemoryManager::GetDefault()
MemoryManager::MemoryManager(MemoryAllocator& baseAllocator)
: mBaseAllocator(baseAllocator),
mFreeListAllocator(mBaseAllocator),
#if DART_BUILD_MODE_RELEASE
mPoolAllocator(mFreeListAllocator)
#else
mPoolAllocator(mFreeListAllocator.getInternalAllocator())
#endif
{
// Do nothing
}
Expand All @@ -73,21 +69,13 @@ MemoryAllocator& MemoryManager::getBaseAllocator()
//==============================================================================
FreeListAllocator& MemoryManager::getFreeListAllocator()
{
#if DART_BUILD_MODE_RELEASE
return mFreeListAllocator;
#else
return mFreeListAllocator.getInternalAllocator();
#endif
}

//==============================================================================
PoolAllocator& MemoryManager::getPoolAllocator()
{
#if DART_BUILD_MODE_RELEASE
return mPoolAllocator;
#else
return mPoolAllocator.getInternalAllocator();
#endif
}

//==============================================================================
Expand Down Expand Up @@ -144,20 +132,6 @@ void MemoryManager::deallocateUsingPool(void* pointer, size_t bytes)
deallocate(Type::Pool, pointer, bytes);
}

#if DART_BUILD_MODE_DEBUG
//==============================================================================
bool MemoryManager::hasAllocated(void* pointer, size_t size) const noexcept
{
if (mFreeListAllocator.hasAllocated(pointer, size))
return true;

if (mPoolAllocator.hasAllocated(pointer, size))
return true;

return false;
}
#endif

//==============================================================================
void MemoryManager::print(std::ostream& os, int indent) const
{
Expand Down
16 changes: 0 additions & 16 deletions dart/common/MemoryManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
#ifndef DART_COMMON_MEMORYMANAGER_HPP_
#define DART_COMMON_MEMORYMANAGER_HPP_

#if DART_BUILD_MODE_DEBUG
#include <mutex>
#endif
#include <dart/common/FreeListAllocator.hpp>
#include <dart/common/PoolAllocator.hpp>

Expand Down Expand Up @@ -151,11 +148,6 @@ class MemoryManager final
template <typename T>
void destroyUsingPool(T* pointer) noexcept;

#if DART_BUILD_MODE_DEBUG
/// Returns true if a pointer is allocated by the internal allocator.
[[nodiscard]] bool hasAllocated(void* pointer, size_t size) const noexcept;
#endif

/// Prints state of the memory manager.
void print(std::ostream& os = std::cout, int indent = 0) const;

Expand All @@ -167,19 +159,11 @@ class MemoryManager final
/// The base allocator to allocate memory chunk.
MemoryAllocator& mBaseAllocator;

#if DART_BUILD_MODE_RELEASE
/// The free list allocator.
FreeListAllocator mFreeListAllocator;

/// The pool allocator.
PoolAllocator mPoolAllocator;
#else
/// The free list allocator.
FreeListAllocator::Debug mFreeListAllocator;

/// The pool allocator.
PoolAllocator::Debug mPoolAllocator;
#endif
};

} // namespace dart::common
Expand Down
12 changes: 4 additions & 8 deletions dart/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
|| (DART_MINOR_VERSION <= y && DART_PATCH_VERSION <= z)))

// Deprecated in 6.14
#define DART_VERSION_AT_LEAST(x, y, z) \
DART_VERSION_GE(x, y, z)
#define DART_VERSION_AT_LEAST(x, y, z) DART_VERSION_GE(x, y, z)

// Deprecated in 6.14
#define DART_MAJOR_MINOR_VERSION_AT_LEAST(x, y) \
Expand All @@ -44,8 +43,7 @@
&& (DART_MINOR_VERSION > y || (DART_MINOR_VERSION >= y))))

// Deprecated in 6.14
#define DART_VERSION_AT_MOST(x, y, z) \
DART_VERSION_LE(x, y, z)
#define DART_VERSION_AT_MOST(x, y, z) DART_VERSION_LE(x, y, z)

// Deprecated in 6.14
#define DART_MAJOR_MINOR_VERSION_AT_MOST(x, y) \
Expand All @@ -62,10 +60,6 @@
#define DART_COMPILER_MSVC
#endif

// Indicates the build mode used for compiling
#cmakedefine01 DART_BUILD_MODE_DEBUG
#cmakedefine01 DART_BUILD_MODE_RELEASE

#cmakedefine01 HAVE_NLOPT
#cmakedefine01 HAVE_IPOPT
#cmakedefine01 HAVE_PAGMO
Expand Down Expand Up @@ -98,3 +92,5 @@
#cmakedefine01 DART_USE_SYSTEM_IMGUI

#cmakedefine01 DART_BUILD_PROFILE

#define DART_ACTIVE_LOG_LEVEL @DART_ACTIVE_LOG_LEVEL_VALUE@
Loading

0 comments on commit 6f6fee8

Please sign in to comment.