Merge pull request #27 from TartanLlama/cmake_love

Do CMake properly
This commit is contained in:
Simon Brand
2019-06-25 11:18:19 +01:00
committed by GitHub
20 changed files with 52 additions and 33 deletions

View File

@ -3,6 +3,7 @@ os:
- Visual Studio 2017 - Visual Studio 2017
build_script: build_script:
- git submodule update --init --recursive
- mkdir build - mkdir build
- cd build - cd build
- cmake .. - 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,7 +1,7 @@
language: cpp language: cpp
dist: trusty dist: xenial
sudo: false sudo: false
matrix: matrix:
@ -98,7 +98,7 @@ matrix:
addons: addons:
apt: apt:
sources: 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" key_url: "http://apt.llvm.org/llvm-snapshot.gpg.key"
- ubuntu-toolchain-r-test - ubuntu-toolchain-r-test
packages: packages:
@ -109,7 +109,7 @@ matrix:
addons: addons:
apt: apt:
sources: sources:
- llvm-toolchain-trusty-4.0 - llvm-toolchain-xenial-4.0
- ubuntu-toolchain-r-test - ubuntu-toolchain-r-test
packages: packages:
- clang++-4.0 - clang++-4.0
@ -119,7 +119,7 @@ matrix:
addons: addons:
apt: apt:
sources: sources:
- llvm-toolchain-trusty-5.0 - llvm-toolchain-xenial-5.0
- ubuntu-toolchain-r-test - ubuntu-toolchain-r-test
packages: packages:
- clang++-5.0 - clang++-5.0
@ -129,7 +129,7 @@ matrix:
addons: addons:
apt: apt:
sources: sources:
- llvm-toolchain-trusty-6.0 - llvm-toolchain-xenial-6.0
- ubuntu-toolchain-r-test - ubuntu-toolchain-r-test
packages: packages:
- clang++-6.0 - clang++-6.0
@ -212,7 +212,7 @@ matrix:
addons: addons:
apt: apt:
sources: 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" key_url: "http://apt.llvm.org/llvm-snapshot.gpg.key"
- ubuntu-toolchain-r-test - ubuntu-toolchain-r-test
packages: packages:
@ -223,7 +223,7 @@ matrix:
addons: addons:
apt: apt:
sources: sources:
- llvm-toolchain-trusty-4.0 - llvm-toolchain-xenial-4.0
- ubuntu-toolchain-r-test - ubuntu-toolchain-r-test
packages: packages:
- clang++-4.0 - clang++-4.0
@ -233,7 +233,7 @@ matrix:
addons: addons:
apt: apt:
sources: sources:
- llvm-toolchain-trusty-5.0 - llvm-toolchain-xenial-5.0
- ubuntu-toolchain-r-test - ubuntu-toolchain-r-test
packages: packages:
- clang++-5.0 - clang++-5.0
@ -243,7 +243,7 @@ matrix:
addons: addons:
apt: apt:
sources: sources:
- llvm-toolchain-trusty-6.0 - llvm-toolchain-xenial-6.0
- ubuntu-toolchain-r-test - ubuntu-toolchain-r-test
packages: packages:
- clang++-6.0 - clang++-6.0

View File

@ -1,12 +1,23 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.11)
project(optional) project(tl-optional VERSION 1.0.0 LANGUAGES CXX)
option(OPTIONAL_ENABLE_TESTS "Enable tests." ON) option(OPTIONAL_ENABLE_TESTS "Enable tests." ON)
add_library(optional INTERFACE) include(FetchContent)
target_sources(optional INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/tl/optional.hpp) FetchContent_Declare(
target_include_directories(optional INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/tl) 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(optional SOURCES
include/tl/optional.hpp)
if(OPTIONAL_ENABLE_TESTS) if(OPTIONAL_ENABLE_TESTS)
# Prepare "Catch" library for other executables # Prepare "Catch" library for other executables

View File

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

View File

@ -15,8 +15,9 @@
#ifndef TL_OPTIONAL_HPP #ifndef TL_OPTIONAL_HPP
#define TL_OPTIONAL_HPP #define TL_OPTIONAL_HPP
#define TL_OPTIONAL_VERSION_MAJOR 0 #define TL_OPTIONAL_VERSION_MAJOR 1
#define TL_OPTIONAL_VERSION_MINOR 5 #define TL_OPTIONAL_VERSION_MINOR 0
#define TL_OPTIONAL_VERSION_PATCH 0
#include <exception> #include <exception>
#include <functional> #include <functional>
@ -137,13 +138,13 @@ struct conjunction<B, Bs...>
: std::conditional<bool(B::value), conjunction<Bs...>, B>::type {}; : std::conditional<bool(B::value), conjunction<Bs...>, B>::type {};
#if defined(_LIBCPP_VERSION) && __cplusplus == 201103L #if defined(_LIBCPP_VERSION) && __cplusplus == 201103L
#define TL_OPTIONAL_LIBCXX_MEM_FN_WORKAROUND #define TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
#endif #endif
// In C++11 mode, there's an issue in libc++'s std::mem_fn // 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 // 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. // in some cases. This is a check to workaround the common failing case.
#ifdef TL_OPTIONAL_LIBCXX_MEM_FN_WORKAROUND #ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
template <class T> struct is_pointer_to_non_const_member_func : std::false_type{}; template <class T> struct is_pointer_to_non_const_member_func : std::false_type{};
template <class T, class Ret, class... Args> template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret (T::*) (Args...)> : std::true_type{}; struct is_pointer_to_non_const_member_func<Ret (T::*) (Args...)> : std::true_type{};
@ -166,7 +167,7 @@ template <class T> struct is_const_or_const_ref<T const> : std::true_type{};
// std::invoke from C++17 // std::invoke from C++17
// https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround // https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround
template <typename Fn, typename... Args, template <typename Fn, typename... Args,
#ifdef TL_OPTIONAL_LIBCXX_MEM_FN_WORKAROUND #ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
typename = enable_if_t<!(is_pointer_to_non_const_member_func<Fn>::value typename = enable_if_t<!(is_pointer_to_non_const_member_func<Fn>::value
&& is_const_or_const_ref<Args...>::value)>, && is_const_or_const_ref<Args...>::value)>,
#endif #endif

View File

@ -1,5 +1,5 @@
#include "catch.hpp" #include "catch.hpp"
#include "optional.hpp" #include <tl/optional.hpp>
TEST_CASE("Assignment value", "[assignment.value]") { TEST_CASE("Assignment value", "[assignment.value]") {
tl::optional<int> o1 = 42; tl::optional<int> o1 = 42;

View File

@ -1,5 +1,5 @@
#include "catch.hpp" #include "catch.hpp"
#include "optional.hpp" #include <tl/optional.hpp>
// Old versions of GCC don't have the correct trait names. Could fix them up if needs be. // Old versions of GCC don't have the correct trait names. Could fix them up if needs be.
#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && \ #if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && \

View File

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

View File

@ -1,5 +1,5 @@
#include "catch.hpp" #include "catch.hpp"
#include "optional.hpp" #include <tl/optional.hpp>
#include <vector> #include <vector>
struct foo { struct foo {

View File

@ -1,5 +1,5 @@
#include "catch.hpp" #include "catch.hpp"
#include "optional.hpp" #include <tl/optional.hpp>
#include <utility> #include <utility>
#include <tuple> #include <tuple>

View File

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

View File

@ -1,4 +1,4 @@
#include "catch.hpp" #include "catch.hpp"
#include "optional.hpp" #include <tl/optional.hpp>
TEST_CASE("Hashing", "[hash]") {} TEST_CASE("Hashing", "[hash]") {}

View File

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

View File

@ -1,5 +1,5 @@
#include "catch.hpp" #include "catch.hpp"
#include "optional.hpp" #include <tl/optional.hpp>
#include <type_traits> #include <type_traits>
struct foo{ struct foo{

View File

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

View File

@ -1,5 +1,5 @@
#include "catch.hpp" #include "catch.hpp"
#include "optional.hpp" #include <tl/optional.hpp>
TEST_CASE("Noexcept", "[noexcept]") { TEST_CASE("Noexcept", "[noexcept]") {
tl::optional<int> o1{4}; tl::optional<int> o1{4};

View File

@ -1,5 +1,5 @@
#include "catch.hpp" #include "catch.hpp"
#include "optional.hpp" #include <tl/optional.hpp>
TEST_CASE("Nullopt", "[nullopt]") { TEST_CASE("Nullopt", "[nullopt]") {
tl::optional<int> o1 = tl::nullopt; tl::optional<int> o1 = tl::nullopt;

View File

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

View File

@ -1,5 +1,5 @@
#include "catch.hpp" #include "catch.hpp"
#include "optional.hpp" #include <tl/optional.hpp>
TEST_CASE("Relational ops", "[relops]") { TEST_CASE("Relational ops", "[relops]") {
tl::optional<int> o1{4}; tl::optional<int> o1{4};