Skip to content

Commit

Permalink
Finish Release-0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
foonathan committed Jun 13, 2015
2 parents ea0203d + fc91f58 commit 291602b
Show file tree
Hide file tree
Showing 67 changed files with 4,212 additions and 1,532 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.3
---
* added debugging options such as memory filling and deallocation and leak check
* improved performance of pool allocators
* changed complete project structure and CMake
* many internal changes and bugfixes and automated testing

0.2
---
* added temporary_allocator as portable alloca
Expand Down
159 changes: 65 additions & 94 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,106 +1,77 @@
# Copyright (C) 2015 Jonathan Müller <[email protected]>
# This file is subject to the license terms in the LICENSE file
# found in the top-level directory of this distribution.

# root CMakeLists.txt, specifies option and interface library

cmake_minimum_required(VERSION 3.1)

if (BIICODE)
include(${CMAKE_HOME_DIRECTORY}/biicode.cmake)
include(biicode/cmake/tools)
ADD_BII_TARGETS()
else()
cmake_minimum_required(VERSION 3.0)
project(foonathan_memory)
project(FOONATHAN_MEMORY)
endif()

include(CheckCXXSourceCompiles)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-std=c++11 cpp11_flag)
if (cpp11_flag)
set(CMAKE_REQUIRED_FLAGS "-std=c++11")
else()
CHECK_CXX_COMPILER_FLAG(-std=c++0x cpp0x_flag)
if (cpp0x_flag)
set(CMAKE_REQUIRED_FLAGS "-std=c++0x")
endif(cpp0x_flag)
endif(cpp11_flag)

CHECK_CXX_SOURCE_COMPILES("int main() {int i = alignof(int);}" comp_alignof)
CHECK_CXX_SOURCE_COMPILES("#include <cstddef>
using namespace std;
int main() {max_align_t val;}" comp_max_align)
CHECK_CXX_SOURCE_COMPILES("#include <new>
int main() {auto handler = std::get_new_handler();}" comp_new_handler)
CHECK_CXX_SOURCE_COMPILES("thread_local int i; int main() {}" comp_thread_local)
CHECK_CXX_SOURCE_COMPILES("constexpr auto foo = 1; int main(){}" comp_constexpr)
CHECK_CXX_SOURCE_COMPILES("void foo() noexcept {} int main(){}" comp_noexcept)
# compatibility options
include(cmake/compatibility.cmake)

option(FOONATHAN_IMPL_HAS_ALIGNOF "whether or not alignof is available" ${comp_alignof})
option(FOONATHAN_IMPL_HAS_MAX_ALIGN "whether or not std::max_align_t is available" ${comp_max_align})
option(FOONATHAN_IMPL_HAS_GET_NEW_HANDLER "whether or not std::get_new_handler() is available" ${comp_new_handler})
option(FOONATHAN_IMPL_HAS_THREAD_LOCAL "whether or not thread_local is available" ${comp_thread_local})
option(FOONATHAN_IMPL_HAS_CONSTEXPR "whether or not constexpr is available" ${comp_constexpr})
option(FOONATHAN_IMPL_HAS_NOEXCEPT "whether or not noexcept is available" ${comp_noexcept})
# debug options
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
set(debug_checks ON)
set(debug_fence 8)
elseif(${CMAKE_BUILD_TYPE} MATCHES "RelWithDebInfo")
set(debug_checks ON)
set(debug_fence 0)
else()
set(debug_checks OFF)
set(debug_fence 0)
endif()

set(version_major 0 CACHE INTERNAL "")
set(version_minor 2 CACHE INTERNAL "")
option(FOONATHAN_MEMORY_DEBUG_FILL
"whether or not the (de-)allocated memory will be pre-filled" ${debug_checks})
set(FOONATHAN_MEMORY_DEBUG_FENCE ${debug_fence} CACHE STRING
"the amount of memory used as fence to help catching overflow errors" )
option(FOONATHAN_MEMORY_DEBUG_LEAK_CHECK
"whether or not leak checking is active" ${debug_checks})
option(FOONATHAN_MEMORY_DEBUG_POINTER_CHECK
"whether or not pointer checking on deallocation is active" ${debug_checks})

# other options
set(FOONATHAN_MEMORY_DEFAULT_ALLOCATOR heap_allocator CACHE STRING
"the default implementation allocator for higher-level ones")
option(FOONATHAN_MEMORY_THREAD_SAFE_ADAPTER "whether or not raw_allocator_adapter is thread safe by default" ON)
option(FOONATHAN_MEMORY_THREAD_SAFE_REFERENCE
"whether or not allocator_reference is thread safe by default" ON)

# whether or not this is project is build directly or as subdirectory
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(is_toplevel 1)
else()
set(is_toplevel 0)
endif()

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.hpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/config_impl.hpp")
# build options
option(FOONATHAN_MEMORY_BUILD_EXAMPLES "whether or not to build the examples" ${is_toplevel})
option(FOONATHAN_MEMORY_BUILD_TESTS "whether or not to build the tests" ${is_toplevel})
option(FOONATHAN_MEMORY_INCLUDE_PREFIX "whether or not you have to use <foonathan/memory/xxx.hpp>" OFF)
option(FOONATHAN_MEMORY_NAMESPACE_PREFIX "whether or not everything is in namespace foonathan::memory" OFF)

if (BIICODE)
ADD_BIICODE_TARGETS()
ACTIVATE_CPP11()
target_include_directories(${BII_BLOCK_TARGET} INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
else()
set(src
detail/align.hpp
detail/block_list.cpp
detail/block_list.hpp
detail/free_list.cpp
detail/free_list.hpp
detail/memory_stack.hpp
detail/small_free_list.cpp
detail/small_free_list.hpp
aligned_allocator.hpp
allocator_adapter.hpp
allocator_traits.hpp
config.hpp
default_allocator.hpp
heap_allocator.cpp
heap_allocator.hpp
new_allocator.cpp
new_allocator.hpp
pool_allocator.hpp
pool_collection.cpp
pool_collection.hpp
pool_type.hpp
pool_type.cpp
raw_allocator_base.hpp
smart_ptr.hpp
stack_allocator.hpp
std_allocator_base.hpp
temporary_allocator.cpp
temporary_allocator.hpp
threading.hpp
tracking.hpp
CACHE INTERNAL "")

add_library(foonathan_memory ${src})
add_executable(foonathan_memory_example_allocator example/allocator.cpp)
add_executable(foonathan_memory_example_smart_ptr example/smart_ptr.cpp)
add_executable(foonathan_memory_example_temporary example/temporary.cpp)

target_link_libraries(foonathan_memory_example_allocator PUBLIC foonathan_memory)
target_link_libraries(foonathan_memory_example_smart_ptr PUBLIC foonathan_memory)
target_link_libraries(foonathan_memory_example_temporary PUBLIC foonathan_memory)

set(targets foonathan_memory
foonathan_memory_example_allocator
foonathan_memory_example_smart_ptr
foonathan_memory_example_temporary
CACHE INTERNAL "")

set_target_properties(${targets} PROPERTIES CXX_STANDARD 11)

foreach(target ${targets})
target_include_directories(${target} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
endforeach()
# variables to use library in other projects
if(FOONATHAN_MEMORY_INCLUDE_PREFIX)
set(FOONATHAN_MEMORY_INCLUDE_DIR ${FOONATHAN_MEMORY_SOURCE_DIR}/include/ CACHE PATH
"include directory for library")
else()
set(FOONATHAN_MEMORY_INCLUDE_DIR ${FOONATHAN_MEMORY_SOURCE_DIR}/include/foonathan CACHE PATH
"include directory for library")
endif()

set(FOONATHAN_MEMORY_VERSION_MAJOR 0 CACHE STRING "major version of memory" FORCE)
set(FOONATHAN_MEMORY_VERSION_MINOR 3 CACHE STRING "minor version of memory" FORCE)

# subdirectories
add_subdirectory(src)
if(FOONATHAN_MEMORY_BUILD_EXAMPLES)
add_subdirectory(example)
endif()
if(FOONATHAN_MEMORY_BUILD_TESTS)
add_subdirectory(test)
endif()
Loading

0 comments on commit 291602b

Please sign in to comment.