Skip to content

Commit 556c2c3

Browse files
authored
Merge pull request #7 from TartanLlama/cmake_love
Do CMake properly
2 parents b87a35a + 1d4e6f4 commit 556c2c3

File tree

11 files changed

+75
-52
lines changed

11 files changed

+75
-52
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: cpp
22

3-
dist: trusty
3+
dist: xenial
44
sudo: false
55

66
matrix:
@@ -33,7 +33,7 @@ matrix:
3333
addons:
3434
apt:
3535
sources:
36-
- llvm-toolchain-precise-3.5
36+
- llvm-toolchain-xenial-3.5
3737
- ubuntu-toolchain-r-test
3838
packages:
3939
- clang++-3.5
@@ -43,7 +43,7 @@ matrix:
4343
addons:
4444
apt:
4545
sources:
46-
- llvm-toolchain-precise-3.6
46+
- llvm-toolchain-xenial-3.6
4747
- ubuntu-toolchain-r-test
4848
packages:
4949
- clang++-3.6
@@ -53,7 +53,7 @@ matrix:
5353
addons:
5454
apt:
5555
sources:
56-
- llvm-toolchain-precise-3.7
56+
- llvm-toolchain-xenial-3.7
5757
- ubuntu-toolchain-r-test
5858
packages:
5959
- clang++-3.7
@@ -63,7 +63,7 @@ matrix:
6363
addons:
6464
apt:
6565
sources:
66-
- llvm-toolchain-precise-3.8
66+
- llvm-toolchain-xenial-3.8
6767
- ubuntu-toolchain-r-test
6868
packages:
6969
- clang++-3.8
@@ -73,7 +73,7 @@ matrix:
7373
addons:
7474
apt:
7575
sources:
76-
- sourceline: "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main"
76+
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.9 main"
7777
key_url: "http://apt.llvm.org/llvm-snapshot.gpg.key"
7878
- ubuntu-toolchain-r-test
7979
packages:

CMakeLists.txt

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
1-
cmake_minimum_required(VERSION 3.0)
1+
cmake_minimum_required(VERSION 3.11)
22

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

5-
# Prepare "Catch" library for other executables
6-
set(CATCH_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/test)
7-
add_library(Catch INTERFACE)
8-
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
9-
10-
# Make test executable
11-
set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp
12-
${CMAKE_CURRENT_SOURCE_DIR}/tests/constructors.cpp
13-
${CMAKE_CURRENT_SOURCE_DIR}/tests/call.cpp
14-
${CMAKE_CURRENT_SOURCE_DIR}/tests/issues.cpp
15-
${CMAKE_CURRENT_SOURCE_DIR}/tests/assignment.cpp)
16-
17-
add_executable(tests ${TEST_SOURCES})
5+
option(FUNCTION_REF_ENABLE_TESTS "Enable tests." ON)
186

19-
add_library(function_ref INTERFACE)
20-
target_sources(function_ref INTERFACE ${CMAKE_SOURCE_DIR}/function_ref.hpp)
21-
target_include_directories(function_ref INTERFACE ${CMAKE_SOURCE_DIR})
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)
2218

23-
target_link_libraries(tests Catch function_ref)
24-
set_property(TARGET tests PROPERTY CXX_STANDARD 14)
19+
tl_add_library(function-ref SOURCES
20+
include/tl/function_ref.hpp)
2521

22+
# Prepare "Catch" library for other executables
23+
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
24+
add_library(Catch INTERFACE)
25+
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
2626

27-
find_package(standardese) # find standardese after installation
28-
29-
# generates a custom target that will run standardese to generate the documentation
30-
if (standardese_FOUND)
31-
standardese_generate(function_ref
32-
INCLUDE_DIRECTORY .
33-
CONFIG ${CMAKE_SOURCE_DIR}/standardese.config
34-
INPUT function_ref.hpp)
35-
endif ()
27+
if(FUNCTION_REF_ENABLE_TESTS)
28+
# Make test executable
29+
set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp
30+
${CMAKE_CURRENT_SOURCE_DIR}/tests/constructors.cpp
31+
${CMAKE_CURRENT_SOURCE_DIR}/tests/call.cpp
32+
${CMAKE_CURRENT_SOURCE_DIR}/tests/issues.cpp
33+
${CMAKE_CURRENT_SOURCE_DIR}/tests/assignment.cpp)
34+
35+
add_executable(tests ${TEST_SOURCES})
36+
37+
target_link_libraries(tests Catch function-ref)
38+
39+
set_property(TARGET tests PROPERTY CXX_STANDARD 14)
40+
endif()

cmake/tl-cmake

Submodule tl-cmake added at 284c6a3

cmake/tl-function-ref-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-function-ref-targets.cmake")

function_ref.hpp renamed to include/tl/function_ref.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
#ifndef TL_FUNCTION_REF_HPP
1515
#define TL_FUNCTION_REF_HPP
1616

17-
#define TL_FUNCTION_REF_VERSION_MAJOR 0
18-
#define TL_FUNCTION_REF_VERSION_MINOR 3
17+
#define TL_FUNCTION_REF_VERSION_MAJOR 1
18+
#define TL_FUNCTION_REF_VERSION_MINOR 0
19+
#define TL_FUNCTION_REF_VERSION_PATCH 0
1920

2021
#if (defined(_MSC_VER) && _MSC_VER == 1900)
2122
/// \exclude
@@ -62,8 +63,7 @@
6263

6364
namespace tl {
6465
namespace detail {
65-
#ifndef TL_TRAITS_MUTEX
66-
#define TL_TRAITS_MUTEX
66+
namespace fnref {
6767
// C++14-style aliases for brevity
6868
template <class T> using remove_const_t = typename std::remove_const<T>::type;
6969
template <class T>
@@ -98,17 +98,16 @@ template <class F, class, class... Us> struct invoke_result_impl;
9898

9999
template <class F, class... Us>
100100
struct invoke_result_impl<
101-
F, decltype(invoke(std::declval<F>(), std::declval<Us>()...), void()),
101+
F, decltype(tl::detail::fnref::invoke(std::declval<F>(), std::declval<Us>()...), void()),
102102
Us...> {
103-
using type = decltype(invoke(std::declval<F>(), std::declval<Us>()...));
103+
using type = decltype(tl::detail::fnref::invoke(std::declval<F>(), std::declval<Us>()...));
104104
};
105105

106106
template <class F, class... Us>
107107
using invoke_result = invoke_result_impl<F, void, Us...>;
108108

109109
template <class F, class... Us>
110110
using invoke_result_t = typename invoke_result<F, Us...>::type;
111-
#endif
112111

113112
template <class, class R, class F, class... Args>
114113
struct is_invocable_r_impl : std::false_type {};
@@ -122,6 +121,7 @@ template <class R, class F, class... Args>
122121
using is_invocable_r = is_invocable_r_impl<std::true_type, R, F, Args...>;
123122

124123
} // namespace detail
124+
} // namespace fnref
125125

126126
/// A lightweight non-owning reference to a callable.
127127
///
@@ -147,13 +147,13 @@ template <class R, class... Args> class function_ref<R(Args...)> {
147147
///
148148
/// \synopsis template <typename F> constexpr function_ref(F &&f) noexcept
149149
template <typename F,
150-
detail::enable_if_t<
151-
!std::is_same<detail::decay_t<F>, function_ref>::value &&
152-
detail::is_invocable_r<R, F &&, Args...>::value> * = nullptr>
150+
detail::fnref::enable_if_t<
151+
!std::is_same<detail::fnref::decay_t<F>, function_ref>::value &&
152+
detail::fnref::is_invocable_r<R, F &&, Args...>::value> * = nullptr>
153153
TL_FUNCTION_REF_11_CONSTEXPR function_ref(F &&f) noexcept
154154
: obj_(const_cast<void*>(reinterpret_cast<const void *>(std::addressof(f)))) {
155155
callback_ = [](void *obj, Args... args) -> R {
156-
return detail::invoke(
156+
return detail::fnref::invoke(
157157
*reinterpret_cast<typename std::add_pointer<F>::type>(obj),
158158
std::forward<Args>(args)...);
159159
};
@@ -167,12 +167,12 @@ template <class R, class... Args> class function_ref<R(Args...)> {
167167
///
168168
/// \synopsis template <typename F> constexpr function_ref &operator=(F &&f) noexcept;
169169
template <typename F,
170-
detail::enable_if_t<detail::is_invocable_r<R, F &&, Args...>::value>
170+
detail::fnref::enable_if_t<detail::fnref::is_invocable_r<R, F &&, Args...>::value>
171171
* = nullptr>
172172
TL_FUNCTION_REF_11_CONSTEXPR function_ref<R(Args...)> &operator=(F &&f) noexcept {
173173
obj_ = reinterpret_cast<void *>(std::addressof(f));
174174
callback_ = [](void *obj, Args... args) {
175-
return detail::invoke(
175+
return detail::fnref::invoke(
176176
*reinterpret_cast<typename std::add_pointer<F>::type>(obj),
177177
std::forward<Args>(args)...);
178178
};

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 "function_ref.hpp"
2+
#include <tl/function_ref.hpp>
33

44
void f(){}
55
struct b {

tests/call.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 "function_ref.hpp"
2+
#include <tl/function_ref.hpp>
33

44
namespace {
55
bool f_called = false;

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 "function_ref.hpp"
2+
#include <tl/function_ref.hpp>
33

44
void foo(){}
55
struct bar {

0 commit comments

Comments
 (0)