Skip to content

Commit

Permalink
Merge pull request #35 from ilelann/cmake
Browse files Browse the repository at this point in the history
CMake build
  • Loading branch information
Sean Parent committed Jul 12, 2015
2 parents 1b3c22f + b8c98f3 commit 4ed5647
Show file tree
Hide file tree
Showing 52 changed files with 253 additions and 367 deletions.
32 changes: 32 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 3.0)
include(ExternalProject)
include(CMakeParseArguments)
enable_testing()

project(adobe_source_libraries CXX)

set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 11)

link_directories(${CMAKE_INSTALL_PREFIX}/lib)

ExternalProject_Add(double-conversion_prj
PREFIX ${CMAKE_BINARY_DIR}/thirdparty/double-conversion
GIT_REPOSITORY https://github.com/google/double-conversion.git
#GIT_REPOSITORY https://github.com/stlab/double-conversion.git
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})

function(target_link_doubleconversion target)

#tweak on include double-conversion path
target_compile_definitions(${target} PUBLIC -DADOBE_BUILT_WITH_CMAKE)

add_dependencies(${target} double-conversion_prj)
target_include_directories(${target} PUBLIC ${CMAKE_INSTALL_PREFIX}/include)
target_link_libraries(${target} PUBLIC double-conversion)
endfunction(target_link_doubleconversion)

find_package(Boost COMPONENTS system thread unit_test_framework program_options REQUIRED)

add_subdirectory(source)
add_subdirectory(test)
3 changes: 3 additions & 0 deletions adobe/cmath.hpp
Expand Up @@ -48,6 +48,9 @@ back to include math.h. This also needs to add any other C99 math.h extensions.

#define ADOBE_HAS_C99_STD_MATH_H
#endif
#elif __GNUC__ == 5
#define ADOBE_HAS_C99_STD_MATH_H
#include <cmath>
#endif

#elif defined(_MSC_VER)
Expand Down
4 changes: 4 additions & 0 deletions adobe/json.hpp
Expand Up @@ -18,7 +18,11 @@
#include <unordered_map>
#include <vector>

#ifdef ADOBE_BUILT_WITH_CMAKE
#include <double-conversion/double-conversion.h>
#else
#include <double-conversion/src/double-conversion.h>
#endif

#include <adobe/cassert.hpp>
#include <adobe/string/to_string.hpp>
Expand Down
278 changes: 0 additions & 278 deletions adobe/memory.hpp
Expand Up @@ -180,83 +180,6 @@ struct ptr_traits<T*> {
static bool empty_ptr(const_pointer_type x) throw() { return adobe::empty_ptr<T*>()(x); }
};

//!\ingroup memory
template <typename T>
struct ptr_traits<std::auto_ptr<T>> {
typedef typename std::auto_ptr<T>::element_type element_type;
typedef std::auto_ptr<T> pointer_type;
typedef std::auto_ptr<const T> const_pointer_type;

template <class U>
struct rebind {
typedef adobe::ptr_traits<U> other;
};
enum {
is_array = false
};
};

//!\ingroup memory
template <typename R, typename T>
struct runtime_cast_t<R, std::auto_ptr<T>> {
R operator()(std::auto_ptr<T>& x) const {
typedef typename R::element_type* dest_type;
dest_type result = dynamic_cast<dest_type>(x.get());
if (result)
x.release();
return R(result);
}
};

//!\ingroup memory
template <typename T, class Traits>
struct ptr_traits<auto_ptr<T, Traits>> {
typedef typename auto_ptr<T, Traits>::element_type element_type;
typedef auto_ptr<T, Traits> pointer_type;
typedef auto_ptr<const T, Traits> const_pointer_type;

enum {
is_array = Traits::is_array
};
};

//!\ingroup memory
template <typename R, typename T, typename Traits>
struct runtime_cast_t<R, auto_ptr<T, Traits>> {
R operator()(auto_ptr<T, Traits>& x) const {
typedef typename R::element_type* dest_type;
dest_type result = dynamic_cast<dest_type>(x.get());
if (result)
x.release();
return R(result);
}
};

//!\ingroup memory
template <typename T, class Traits>
struct ptr_traits<auto_resource<T, Traits>> {
typedef typename Traits::element_type element_type;
typedef auto_resource<T, Traits> pointer_type;
typedef auto_resource<const T, Traits> const_pointer_type;

enum {
is_array = Traits::is_array
};
};

//!\ingroup memory
template <typename R, typename T, typename Traits>
struct runtime_cast_t<R, auto_resource<T, Traits>> {
R operator()(auto_resource<T, Traits>& x) const {
typedef typename R::element_type* dest_type;
dest_type result = dynamic_cast<dest_type>(x.get());
if (result)
x.release();
return R(result);
}
};


/*************************************************************************************************/

#ifndef NO_DOCUMENTATION
Expand Down Expand Up @@ -357,121 +280,6 @@ class auto_resource {

/*************************************************************************************************/

/*! \brief The <code>adobe::auto_ptr\<\></code> template adds a number of extensions to
<code>std::auto_ptr\<\></code>.
Although <code>std::auto_ptr\<\></code> is a non-regular type, it has proven to be valueable
especially when converting C or non-exception aware C++ to exception aware C++ code. It is
also useful when dealing with C libraries (such as OS libraries) that by necisity return
pointers.
However, <code>std::auto_ptr\<\></code> has a number of limitations that make use error prone,
limit when it can be used, and make it's use more combursome than necessary.
The <code>auto_ptr\<\></code> includes the following not present in
<code>std::auto_ptr\<\></code>:
- The inclusion of ptr_traits to support alternative delete functions.
- Proper support for array types.
- Support for assignment from function results.
- Safe bool casts.
- Assignment and construction from NULL.
Also, <code>auto_resource\<\></code> is provided for non-pointer and opaque pointer
references.
<b>Rationals:</b>
Rational for not going with boost: scoped_ptr interface: The interface to boost:scoped_ptr is a
constrained subset of auto_ptr with out any improvements. I'm not a fan of providing a whole new
interface to prevent the user from performing some operations.
Rational for traits instead of policies:
- Advantages of policies
- allows for per-instance state.
- would allow for use with boost::function.
- Disadvanteages
- no real world examples to demonstrate the advantages.
- complicates implementation to properly handle exceptions from
throwing when assigning policies.
- prohibits use of no-throw in declarations (may not be an actual disadvantage).
- would require more complex interface for constructors.
- would require swap be added to the interface to achieve a non-throwing swap and
it is unclear how swap could be generally implemented.
In total I thought the advantages didn't warrant the effort. If someone come demonstrate a
concrete instance where there would be a strong advantage I'd reconsider.
Differences between photoshop linear types and adobe:: types:
- traits_type replaces deallocator and provides custom null checks
- Safe bool casts.
- Assignment and construction from NULL.
- template based constructor, assignment, and conversion
- linear_resource -> adobe::auto_resource
- linear_base_ptr -> adobe::auto_ptr
- linear_array<T> -> adobe::auto_ptr<T[]>
- linear_ptr -> adobe::auto_ptr
*/

template <typename X, class Traits = ptr_traits<X*>>
class auto_ptr : public auto_resource<X*, Traits> {
typedef auto_resource<X*, Traits> inherited;
struct clear_type {};

public:
typedef Traits traits_type;
typedef typename traits_type::element_type element_type;
typedef typename traits_type::pointer_type pointer_type;
// 20.4.5.1 construct/copy/destroy:
explicit auto_ptr(pointer_type p = 0) throw();

auto_ptr(auto_ptr&) throw();
template <typename Y>
auto_ptr(const auto_ptr<Y, typename traits_type::template rebind<Y*>::other>&) throw();

auto_ptr& operator=(auto_ptr&) throw();
template <typename Y>
auto_ptr& operator=(auto_ptr<Y, typename traits_type::template rebind<Y*>::other>) throw();

// assignment from NULL
auto_ptr& operator=(const clear_type*) throw();

// additions for interop with std::auto_ptr
auto_ptr(std::auto_ptr<X> r) throw();
template <typename Y>
auto_ptr(std::auto_ptr<Y> r) throw();

auto_ptr& operator=(std::auto_ptr<X>) throw();
template <typename Y>
auto_ptr& operator=(std::auto_ptr<Y>) throw();

operator std::auto_ptr<X>() throw() { return std::auto_ptr<X>(inherited::release()); }

// 20.4.5.2 members:
element_type& operator*() const throw();
pointer_type operator->() const throw();
element_type& operator[](std::size_t index) const throw(); // addition

private:
/*
REVISIT (sparent) : This enable_if trick is failing with LLVM using XCode 4.2
*/
#if 0
template <typename Y> struct error_on_const_auto_type;
template <typename Y> struct error_on_const_auto_type<auto_ptr<Y, typename traits_type::template rebind<Y*>::other> const>
{ typedef typename auto_ptr<Y, typename traits_type::template rebind<Y*>::other>::const_auto_type_is_not_allowed type; };

template <class U>
auto_ptr(U& rhs, typename error_on_const_auto_type<U>::type = 0);
#endif
};

//! @}

/*************************************************************************************************/

template <typename X, class Traits>
inline auto_resource<X, Traits>::auto_resource(pointer_type p) throw()
: pointer_m(p) {}
Expand Down Expand Up @@ -546,92 +354,6 @@ inline bool auto_resource<X, Traits>::operator!() const throw() {

/*************************************************************************************************/


template <typename X, class Traits>
inline auto_ptr<X, Traits>::auto_ptr(pointer_type p) throw()
: inherited(p) {}

template <typename X, class Traits>
inline auto_ptr<X, Traits>::auto_ptr(auto_ptr& r) throw()
: inherited(r) {}

template <typename X, class Traits>
template <typename Y>
inline auto_ptr<X, Traits>::auto_ptr(
const auto_ptr<Y, typename traits_type::template rebind<Y*>::other>& r) throw()
: inherited(const_cast<auto_ptr<Y, typename traits_type::template rebind<Y*>::other>&>(r)) {}

template <typename X, class Traits>
inline auto_ptr<X, Traits>& auto_ptr<X, Traits>::operator=(auto_ptr& r) throw() {
inherited::operator=(r);
return *this;
}

template <typename X, class Traits>
template <typename Y>
inline auto_ptr<X, Traits>& auto_ptr<X, Traits>::
operator=(auto_ptr<Y, typename traits_type::template rebind<Y*>::other> r) throw() {
inherited::operator=(r);
return *this;
}

/*************************************************************************************************/

template <typename X, class Traits>
inline auto_ptr<X, Traits>& auto_ptr<X, Traits>::operator=(const clear_type*) throw() {
inherited::reset();
return *this;
}

/*************************************************************************************************/

template <typename X, class Traits>
inline auto_ptr<X, Traits>::auto_ptr(std::auto_ptr<X> r) throw()
: inherited(r.release()) {}

template <typename X, class Traits>
template <typename Y>
inline auto_ptr<X, Traits>::auto_ptr(std::auto_ptr<Y> r) throw()
: inherited(r.release()) {}

template <typename X, class Traits>
inline auto_ptr<X, Traits>& auto_ptr<X, Traits>::operator=(std::auto_ptr<X> r) throw() {
inherited::reset(r.release());
return *this;
}

template <typename X, class Traits>
template <typename Y>
inline auto_ptr<X, Traits>& auto_ptr<X, Traits>::operator=(std::auto_ptr<Y> r) throw() {
inherited::reset(r.release());
return *this;
}

/*************************************************************************************************/

template <typename X, class Traits>
inline typename auto_ptr<X, Traits>::element_type& auto_ptr<X, Traits>::operator*() const throw() {
assert(!traits_type::empty_ptr(this->get()));
return *this->get();
}

template <typename X, class Traits>
inline typename auto_ptr<X, Traits>::pointer_type auto_ptr<X, Traits>::operator->() const throw() {
assert(!traits_type::empty_ptr(this->get()));
return this->get();
}

template <typename X, class Traits>
inline typename auto_ptr<X, Traits>::element_type& auto_ptr<X, Traits>::
operator[](std::size_t index) const throw() {
implementation::adobe_static_assert<traits_type::is_array>();

assert(!traits_type::empty_ptr(this->get()));
return *(this->get() + index);
}

/*************************************************************************************************/

template <typename T> // T models Regular
inline void destroy(T* p) {
p->~T();
Expand Down
15 changes: 15 additions & 0 deletions cmake_build.sh
@@ -0,0 +1,15 @@
#!/bin/bash

BUILDDIR=${BUILDDIR:-build}
TOOLSET=${TOOLSET:-clang}
BUILDMODE=${BUILDMODE:-RELEASE}

mkdir -p ../${BUILDDIR}/${TOOLSET}/${BUILDMODE}
pushd ../${BUILDDIR}/${TOOLSET}/${BUILDMODE}

cmake -DCMAKE_CXX_COMPILER=${TOOLSET} -DCMAKE_BUILD_TYPE=${BUILDMODE} -DCMAKE_INSTALL_PREFIX=stage -G "Unix Makefiles" ../../../adobe_source_libraries
make -j4
make test

popd

8 changes: 8 additions & 0 deletions cmake_build_all.sh
@@ -0,0 +1,8 @@
#!/bin/bash

BUILDDIR=${1:-build}

BUILDDIR=${BUILDDIR} TOOLSET=clang++ BUILDMODE=RELEASE sh cmake_build.sh
BUILDDIR=${BUILDDIR} TOOLSET=clang++ BUILDMODE=DEBUG sh cmake_build.sh
BUILDDIR=${BUILDDIR} TOOLSET=g++ BUILDMODE=RELEASE sh cmake_build.sh
BUILDDIR=${BUILDDIR} TOOLSET=g++ BUILDMODE=DEBUG sh cmake_build.sh
20 changes: 20 additions & 0 deletions source/CMakeLists.txt
@@ -0,0 +1,20 @@
aux_source_directory(. SRC_LIST)
file(GLOB_RECURSE INC_LIST ../adobe/*.hpp)
add_library(asl ${SRC_LIST} ${INC_LIST})

target_include_directories(asl PUBLIC ..)
target_compile_definitions(asl PUBLIC ADOBE_STD_SERIALIZATION)

#otherwise boost concept checking fails on adobe::selection_t because it lacks non const begin/end
target_compile_definitions(asl PUBLIC -DBOOST_RANGE_ENABLE_CONCEPT_ASSERT=0)

#otherwise boost::move and std::move are ambiguous
target_compile_definitions(asl PUBLIC -DBOOST_MOVE_USE_STANDARD_LIBRARY_MOVE)

target_compile_options(asl PUBLIC $<$<CXX_COMPILER_ID:Clang>:-fconstexpr-depth=1024>)
target_compile_options(asl PUBLIC $<$<CXX_COMPILER_ID:Clang>:-ftemplate-depth=1024>)

target_link_doubleconversion(asl)

target_link_libraries(asl PUBLIC ${Boost_SYSTEM_LIBRARY})

0 comments on commit 4ed5647

Please sign in to comment.