Skip to content

Commit a265082

Browse files
authored
Merge pull request #27 from TartanLlama/cmake_love
Do CMake properly
2 parents d613d34 + aef62df commit a265082

20 files changed

+52
-33
lines changed

.appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ os:
33
- Visual Studio 2017
44

55
build_script:
6+
- git submodule update --init --recursive
67
- mkdir build
78
- cd build
89
- cmake ..

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "cmake/tl-cmake"]
2+
path = cmake/tl-cmake
3+
url = https://github.com/TartanLlama/tl-cmake.git

.travis.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: cpp
22

33

4-
dist: trusty
4+
dist: xenial
55
sudo: false
66

77
matrix:
@@ -98,7 +98,7 @@ matrix:
9898
addons:
9999
apt:
100100
sources:
101-
- sourceline: "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main"
101+
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.9 main"
102102
key_url: "http://apt.llvm.org/llvm-snapshot.gpg.key"
103103
- ubuntu-toolchain-r-test
104104
packages:
@@ -109,7 +109,7 @@ matrix:
109109
addons:
110110
apt:
111111
sources:
112-
- llvm-toolchain-trusty-4.0
112+
- llvm-toolchain-xenial-4.0
113113
- ubuntu-toolchain-r-test
114114
packages:
115115
- clang++-4.0
@@ -119,7 +119,7 @@ matrix:
119119
addons:
120120
apt:
121121
sources:
122-
- llvm-toolchain-trusty-5.0
122+
- llvm-toolchain-xenial-5.0
123123
- ubuntu-toolchain-r-test
124124
packages:
125125
- clang++-5.0
@@ -129,7 +129,7 @@ matrix:
129129
addons:
130130
apt:
131131
sources:
132-
- llvm-toolchain-trusty-6.0
132+
- llvm-toolchain-xenial-6.0
133133
- ubuntu-toolchain-r-test
134134
packages:
135135
- clang++-6.0
@@ -212,7 +212,7 @@ matrix:
212212
addons:
213213
apt:
214214
sources:
215-
- sourceline: "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main"
215+
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.9 main"
216216
key_url: "http://apt.llvm.org/llvm-snapshot.gpg.key"
217217
- ubuntu-toolchain-r-test
218218
packages:
@@ -223,7 +223,7 @@ matrix:
223223
addons:
224224
apt:
225225
sources:
226-
- llvm-toolchain-trusty-4.0
226+
- llvm-toolchain-xenial-4.0
227227
- ubuntu-toolchain-r-test
228228
packages:
229229
- clang++-4.0
@@ -233,7 +233,7 @@ matrix:
233233
addons:
234234
apt:
235235
sources:
236-
- llvm-toolchain-trusty-5.0
236+
- llvm-toolchain-xenial-5.0
237237
- ubuntu-toolchain-r-test
238238
packages:
239239
- clang++-5.0
@@ -243,7 +243,7 @@ matrix:
243243
addons:
244244
apt:
245245
sources:
246-
- llvm-toolchain-trusty-6.0
246+
- llvm-toolchain-xenial-6.0
247247
- ubuntu-toolchain-r-test
248248
packages:
249249
- clang++-6.0

CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1-
cmake_minimum_required(VERSION 3.0)
1+
cmake_minimum_required(VERSION 3.11)
22

3-
project(optional)
3+
project(tl-optional VERSION 1.0.0 LANGUAGES CXX)
44

55
option(OPTIONAL_ENABLE_TESTS "Enable tests." ON)
66

7-
add_library(optional INTERFACE)
8-
target_sources(optional INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/tl/optional.hpp)
9-
target_include_directories(optional INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/tl)
7+
include(FetchContent)
8+
FetchContent_Declare(
9+
tl_cmake
10+
GIT_REPOSITORY https://github.com/TartanLlama/tl-cmake.git
11+
)
12+
FetchContent_GetProperties(tl_cmake)
13+
if(NOT tl_cmake_POPULATED)
14+
FetchContent_Populate(tl_cmake)
15+
set(CMAKE_MODULE_PATH ${tl_cmake_SOURCE_DIR} ${CMAKE_MODULE_PATH})
16+
endif()
17+
include(add-tl)
18+
19+
tl_add_library(optional SOURCES
20+
include/tl/optional.hpp)
1021

1122
if(OPTIONAL_ENABLE_TESTS)
1223
# Prepare "Catch" library for other executables

cmake/tl-optional-config.cmake.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@PACKAGE_INIT@
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/tl-optional-targets.cmake")

tl/optional.hpp renamed to include/tl/optional.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
#ifndef TL_OPTIONAL_HPP
1616
#define TL_OPTIONAL_HPP
1717

18-
#define TL_OPTIONAL_VERSION_MAJOR 0
19-
#define TL_OPTIONAL_VERSION_MINOR 5
18+
#define TL_OPTIONAL_VERSION_MAJOR 1
19+
#define TL_OPTIONAL_VERSION_MINOR 0
20+
#define TL_OPTIONAL_VERSION_PATCH 0
2021

2122
#include <exception>
2223
#include <functional>
@@ -137,13 +138,13 @@ struct conjunction<B, Bs...>
137138
: std::conditional<bool(B::value), conjunction<Bs...>, B>::type {};
138139

139140
#if defined(_LIBCPP_VERSION) && __cplusplus == 201103L
140-
#define TL_OPTIONAL_LIBCXX_MEM_FN_WORKAROUND
141+
#define TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
141142
#endif
142143

143144
// In C++11 mode, there's an issue in libc++'s std::mem_fn
144145
// which results in a hard-error when using it in a noexcept expression
145146
// in some cases. This is a check to workaround the common failing case.
146-
#ifdef TL_OPTIONAL_LIBCXX_MEM_FN_WORKAROUND
147+
#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
147148
template <class T> struct is_pointer_to_non_const_member_func : std::false_type{};
148149
template <class T, class Ret, class... Args>
149150
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{};
166167
// std::invoke from C++17
167168
// https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround
168169
template <typename Fn, typename... Args,
169-
#ifdef TL_OPTIONAL_LIBCXX_MEM_FN_WORKAROUND
170+
#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND
170171
typename = enable_if_t<!(is_pointer_to_non_const_member_func<Fn>::value
171172
&& is_const_or_const_ref<Args...>::value)>,
172173
#endif

tests/assignment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "catch.hpp"
2-
#include "optional.hpp"
2+
#include <tl/optional.hpp>
33

44
TEST_CASE("Assignment value", "[assignment.value]") {
55
tl::optional<int> o1 = 42;

tests/bases.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "catch.hpp"
2-
#include "optional.hpp"
2+
#include <tl/optional.hpp>
33

44
// Old versions of GCC don't have the correct trait names. Could fix them up if needs be.
55
#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && \

tests/constexpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "catch.hpp"
2-
#include "optional.hpp"
2+
#include <tl/optional.hpp>
33

44
#define TOKENPASTE(x, y) x##y
55
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)

tests/constructors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "catch.hpp"
2-
#include "optional.hpp"
2+
#include <tl/optional.hpp>
33
#include <vector>
44

55
struct foo {

0 commit comments

Comments
 (0)