Cmake love (#55)

* Do CMake properly

* Remove uneeded file

* Add patch to version

* Init submodule in appveyor

* Use FetchContent

* Up CMake version requirement

* Use Xenial on Travis instead of Trusty

* Tidy traits

* Use Xenial repos
This commit is contained in:
Simon Brand
2019-06-25 11:20:05 +01:00
committed by GitHub
parent 1fb40294e6
commit 4f541d7221
20 changed files with 392 additions and 342 deletions

View File

@@ -3,6 +3,7 @@ os:
- Visual Studio 2017
build_script:
- git submodule update --init --recursive
- mkdir build
- cd build
- cmake ..

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "cmake/tl-cmake"]
path = cmake/tl-cmake
url = https://github.com/TartanLlama/tl-cmake.git

View File

@@ -1,6 +1,6 @@
language: cpp
dist: trusty
dist: xenial
sudo: false
matrix:
@@ -97,7 +97,7 @@ matrix:
addons:
apt:
sources:
- sourceline: "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main"
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.9 main"
key_url: "http://apt.llvm.org/llvm-snapshot.gpg.key"
- ubuntu-toolchain-r-test
packages:
@@ -108,7 +108,7 @@ matrix:
addons:
apt:
sources:
- llvm-toolchain-trusty-4.0
- llvm-toolchain-xenial-4.0
- ubuntu-toolchain-r-test
packages:
- clang++-4.0
@@ -118,7 +118,7 @@ matrix:
addons:
apt:
sources:
- llvm-toolchain-trusty-5.0
- llvm-toolchain-xenial-5.0
- ubuntu-toolchain-r-test
packages:
- clang++-5.0
@@ -128,7 +128,7 @@ matrix:
addons:
apt:
sources:
- llvm-toolchain-trusty-6.0
- llvm-toolchain-xenial-6.0
- ubuntu-toolchain-r-test
packages:
- clang++-6.0
@@ -211,7 +211,7 @@ matrix:
addons:
apt:
sources:
- sourceline: "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main"
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.9 main"
key_url: "http://apt.llvm.org/llvm-snapshot.gpg.key"
- ubuntu-toolchain-r-test
packages:
@@ -222,7 +222,7 @@ matrix:
addons:
apt:
sources:
- llvm-toolchain-trusty-4.0
- llvm-toolchain-xenial-4.0
- ubuntu-toolchain-r-test
packages:
- clang++-4.0
@@ -232,7 +232,7 @@ matrix:
addons:
apt:
sources:
- llvm-toolchain-trusty-5.0
- llvm-toolchain-xenial-5.0
- ubuntu-toolchain-r-test
packages:
- clang++-5.0
@@ -242,7 +242,7 @@ matrix:
addons:
apt:
sources:
- llvm-toolchain-trusty-6.0
- llvm-toolchain-xenial-6.0
- ubuntu-toolchain-r-test
packages:
- clang++-6.0

View File

@@ -1,12 +1,23 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.11)
project(expected)
project(tl-expected VERSION 1.0.0 LANGUAGES CXX)
option(EXPECTED_ENABLE_TESTS "Enable tests." ON)
add_library(expected INTERFACE)
target_sources(expected INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/tl/expected.hpp)
target_include_directories(expected INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/tl)
include(FetchContent)
FetchContent_Declare(
tl_cmake
GIT_REPOSITORY https://github.com/TartanLlama/tl-cmake.git
)
FetchContent_GetProperties(tl_cmake)
if(NOT tl_cmake_POPULATED)
FetchContent_Populate(tl_cmake)
set(CMAKE_MODULE_PATH ${tl_cmake_SOURCE_DIR} ${CMAKE_MODULE_PATH})
endif()
include(add-tl)
tl_add_library(expected SOURCES
include/tl/expected.hpp)
# Prepare "Catch" library for other executables
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)

1
cmake/tl-cmake Submodule

Submodule cmake/tl-cmake added at 284c6a3f0f

View File

@@ -0,0 +1,3 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/tl-expected-targets.cmake")

View File

@@ -12,8 +12,8 @@ class ExpectedConan(ConanFile):
exports_sources = "*"
def source(self):
tools.replace_in_file('CMakeLists.txt', 'project(expected)',
'''project(expected)
tools.replace_in_file('CMakeLists.txt', 'project(tl-expected)',
'''project(tl-expected)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
''')
@@ -31,4 +31,4 @@ conan_basic_setup()
self.run('%s/bin/tests' % self.build_folder)
def package(self):
self.copy('*.hpp', dst='include/tl', src='tl')
self.copy('*.hpp', dst='include/tl', src='include/tl')

View File

@@ -14,8 +14,9 @@
#ifndef TL_EXPECTED_HPP
#define TL_EXPECTED_HPP
#define TL_EXPECTED_VERSION_MAJOR 0
#define TL_EXPECTED_VERSION_MINOR 2
#define TL_EXPECTED_VERSION_MAJOR 1
#define TL_EXPECTED_VERSION_MINOR 0
#define TL_EXPECTED_VERSION_PATCH 0
#include <exception>
#include <functional>
@@ -236,10 +237,41 @@ template <class B, class... Bs>
struct conjunction<B, Bs...>
: std::conditional<bool(B::value), conjunction<Bs...>, B>::type {};
#if defined(_LIBCPP_VERSION) && __cplusplus == 201103L
#define TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
#endif
// In C++11 mode, there's an issue in libc++'s std::mem_fn
// which results in a hard-error when using it in a noexcept expression
// in some cases. This is a check to workaround the common failing case.
#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
template <class T> struct is_pointer_to_non_const_member_func : std::false_type {};
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...)> : std::true_type {};
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...)&> : std::true_type {};
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) &&> : std::true_type {};
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) volatile> : std::true_type {};
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) volatile &> : std::true_type {};
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret(T::*) (Args...) volatile &&> : std::true_type {};
template <class T> struct is_const_or_const_ref : std::false_type {};
template <class T> struct is_const_or_const_ref<T const&> : std::true_type {};
template <class T> struct is_const_or_const_ref<T const> : std::true_type {};
#endif
// std::invoke from C++17
// https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround
template <typename Fn, typename... Args,
typename = enable_if_t<std::is_member_pointer<decay_t<Fn>>{}>,
#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
typename = enable_if_t<!(is_pointer_to_non_const_member_func<Fn>::value
&& is_const_or_const_ref<Args...>::value)>,
#endif
typename = enable_if_t<std::is_member_pointer<decay_t<Fn>>::value>,
int = 0>
constexpr auto invoke(Fn && f, Args && ... args) noexcept(
noexcept(std::mem_fn(f)(std::forward<Args>(args)...)))
@@ -248,7 +280,7 @@ constexpr auto invoke(Fn &&f, Args &&... args) noexcept(
}
template <typename Fn, typename... Args,
typename = enable_if_t<!std::is_member_pointer<decay_t<Fn>>{}>>
typename = enable_if_t<!std::is_member_pointer<decay_t<Fn>>::value>>
constexpr auto invoke(Fn && f, Args && ... args) noexcept(
noexcept(std::forward<Fn>(f)(std::forward<Args>(args)...)))
-> decltype(std::forward<Fn>(f)(std::forward<Args>(args)...)) {
@@ -2442,5 +2474,4 @@ void swap(expected<T, E> &lhs,
}
} // namespace tl
#define TL_OPTIONAL_EXPECTED_MUTEX
#endif

View File

@@ -1,5 +1,5 @@
#include "catch.hpp"
#include "expected.hpp"
#include <tl/expected.hpp>
TEST_CASE("Simple assignment", "[assignment.simple]") {
tl::expected<int, int> e1 = 42;

View File

@@ -1,5 +1,5 @@
#include "catch.hpp"
#include "expected.hpp"
#include <tl/expected.hpp>
#include <string>

View File

@@ -1,5 +1,5 @@
#include "catch.hpp"
#include "expected.hpp"
#include <tl/expected.hpp>
TEST_CASE("Constexpr", "[constexpr]") {
//TODO

View File

@@ -1,5 +1,5 @@
#include "catch.hpp"
#include "expected.hpp"
#include <tl/expected.hpp>
#include <vector>
#include <type_traits>

View File

@@ -1,5 +1,5 @@
#include "catch.hpp"
#include "expected.hpp"
#include <tl/expected.hpp>
#include <memory>
#include <vector>
#include <tuple>

View File

@@ -1,5 +1,5 @@
#include "catch.hpp"
#include "expected.hpp"
#include <tl/expected.hpp>
#define TOKENPASTE(x, y) x##y
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)

View File

@@ -1,5 +1,5 @@
#include "catch.hpp"
#include "expected.hpp"
#include <tl/expected.hpp>
#include <string>

View File

@@ -1,5 +1,5 @@
#include "catch.hpp"
#include "expected.hpp"
#include <tl/expected.hpp>
TEST_CASE("Noexcept", "[noexcept]") {
//TODO

View File

@@ -1,5 +1,5 @@
#include "catch.hpp"
#include "expected.hpp"
#include <tl/expected.hpp>
struct move_detector {
move_detector() = default;

View File

@@ -1,5 +1,5 @@
#include "catch.hpp"
#include "expected.hpp"
#include <tl/expected.hpp>
TEST_CASE("Relational operators", "[relops]") {
//TODO

View File

@@ -1,5 +1,5 @@
#include "catch.hpp"
#include "expected.hpp"
#include <tl/expected.hpp>
struct no_throw {
no_throw(std::string i) : i(i) {}