From 6ce85550f32d4f0ed13ff9312314c556b8bd6db5 Mon Sep 17 00:00:00 2001 From: Simon Brand Date: Wed, 1 May 2019 13:23:30 +0100 Subject: [PATCH 1/5] Do CMake properly --- .appveyor.yml | 1 + .gitmodules | 3 +++ CMakeLists.txt | 12 +++++++----- cmake/tl-cmake | 1 + cmake/tl-optional-config.cmake.in | 3 +++ {tl => include/tl}/optional.hpp | 5 +++-- tests/assignment.cpp | 2 +- tests/bases.cpp | 2 +- tests/constexpr.cpp | 2 +- tests/constructors.cpp | 2 +- tests/emplace.cpp | 2 +- tests/extensions.cpp | 2 +- tests/hash.cpp | 2 +- tests/in_place.cpp | 2 +- tests/issues.cpp | 2 +- tests/make_optional.cpp | 2 +- tests/noexcept.cpp | 2 +- tests/nullopt.cpp | 2 +- tests/observers.cpp | 2 +- tests/relops.cpp | 2 +- 20 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 .gitmodules create mode 160000 cmake/tl-cmake create mode 100644 cmake/tl-optional-config.cmake.in rename {tl => include/tl}/optional.hpp (99%) diff --git a/.appveyor.yml b/.appveyor.yml index 2bc97fd..ccfb904 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -3,6 +3,7 @@ os: - Visual Studio 2017 build_script: + - git submodule update --init --recursive - mkdir build - cd build - cmake .. diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e6488b5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cmake/tl-cmake"] + path = cmake/tl-cmake + url = https://github.com/TartanLlama/tl-cmake.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 5352502..18246ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,14 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.8) -project(optional) +project(tl-optional VERSION 1.0.0 LANGUAGES CXX) option(OPTIONAL_ENABLE_TESTS "Enable tests." ON) -add_library(optional INTERFACE) -target_sources(optional INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/tl/optional.hpp) -target_include_directories(optional INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/tl) +set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/tl-cmake" ${CMAKE_MODULE_PATH}) +include(add-tl) + +tl_add_library(optional SOURCES + include/tl/optional.hpp) if(OPTIONAL_ENABLE_TESTS) # Prepare "Catch" library for other executables diff --git a/cmake/tl-cmake b/cmake/tl-cmake new file mode 160000 index 0000000..576e25f --- /dev/null +++ b/cmake/tl-cmake @@ -0,0 +1 @@ +Subproject commit 576e25feabec4c79ebe2cf7174398c61de05d384 diff --git a/cmake/tl-optional-config.cmake.in b/cmake/tl-optional-config.cmake.in new file mode 100644 index 0000000..cc57bdf --- /dev/null +++ b/cmake/tl-optional-config.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/tl-optional-targets.cmake") \ No newline at end of file diff --git a/tl/optional.hpp b/include/tl/optional.hpp similarity index 99% rename from tl/optional.hpp rename to include/tl/optional.hpp index e33682c..4b9cee8 100644 --- a/tl/optional.hpp +++ b/include/tl/optional.hpp @@ -15,8 +15,9 @@ #ifndef TL_OPTIONAL_HPP #define TL_OPTIONAL_HPP -#define TL_OPTIONAL_VERSION_MAJOR 0 -#define TL_OPTIONAL_VERSION_MINOR 5 +#define TL_OPTIONAL_VERSION_MAJOR 1 +#define TL_OPTIONAL_VERSION_MINOR 0 +#define TL_OPTIONAL_VERSION_PATCH 0 #include #include diff --git a/tests/assignment.cpp b/tests/assignment.cpp index 205ed7b..781be33 100644 --- a/tests/assignment.cpp +++ b/tests/assignment.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "optional.hpp" +#include TEST_CASE("Assignment value", "[assignment.value]") { tl::optional o1 = 42; diff --git a/tests/bases.cpp b/tests/bases.cpp index cff7819..7973b8c 100644 --- a/tests/bases.cpp +++ b/tests/bases.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "optional.hpp" +#include // 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 && \ diff --git a/tests/constexpr.cpp b/tests/constexpr.cpp index dc4db43..efd916c 100644 --- a/tests/constexpr.cpp +++ b/tests/constexpr.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "optional.hpp" +#include #define TOKENPASTE(x, y) x##y #define TOKENPASTE2(x, y) TOKENPASTE(x, y) diff --git a/tests/constructors.cpp b/tests/constructors.cpp index fc87a97..1c7a806 100644 --- a/tests/constructors.cpp +++ b/tests/constructors.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "optional.hpp" +#include #include struct foo { diff --git a/tests/emplace.cpp b/tests/emplace.cpp index 0a87983..feccd41 100644 --- a/tests/emplace.cpp +++ b/tests/emplace.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "optional.hpp" +#include #include #include diff --git a/tests/extensions.cpp b/tests/extensions.cpp index d97687e..a5d6352 100644 --- a/tests/extensions.cpp +++ b/tests/extensions.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "optional.hpp" +#include #include #define TOKENPASTE(x, y) x##y diff --git a/tests/hash.cpp b/tests/hash.cpp index 16437da..af0dff3 100644 --- a/tests/hash.cpp +++ b/tests/hash.cpp @@ -1,4 +1,4 @@ #include "catch.hpp" -#include "optional.hpp" +#include TEST_CASE("Hashing", "[hash]") {} diff --git a/tests/in_place.cpp b/tests/in_place.cpp index 07254e4..4fa87be 100644 --- a/tests/in_place.cpp +++ b/tests/in_place.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "optional.hpp" +#include #include #include diff --git a/tests/issues.cpp b/tests/issues.cpp index 387b083..d5672a3 100644 --- a/tests/issues.cpp +++ b/tests/issues.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "optional.hpp" +#include #include struct foo{ diff --git a/tests/make_optional.cpp b/tests/make_optional.cpp index ba44fd9..779ad52 100644 --- a/tests/make_optional.cpp +++ b/tests/make_optional.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "optional.hpp" +#include #include #include diff --git a/tests/noexcept.cpp b/tests/noexcept.cpp index b12fdea..0f5e368 100644 --- a/tests/noexcept.cpp +++ b/tests/noexcept.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "optional.hpp" +#include TEST_CASE("Noexcept", "[noexcept]") { tl::optional o1{4}; diff --git a/tests/nullopt.cpp b/tests/nullopt.cpp index 6340724..0ddd17b 100644 --- a/tests/nullopt.cpp +++ b/tests/nullopt.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "optional.hpp" +#include TEST_CASE("Nullopt", "[nullopt]") { tl::optional o1 = tl::nullopt; diff --git a/tests/observers.cpp b/tests/observers.cpp index 642b9f6..96db38f 100644 --- a/tests/observers.cpp +++ b/tests/observers.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "optional.hpp" +#include struct move_detector { move_detector() = default; diff --git a/tests/relops.cpp b/tests/relops.cpp index 2f388e7..4c06833 100644 --- a/tests/relops.cpp +++ b/tests/relops.cpp @@ -1,5 +1,5 @@ #include "catch.hpp" -#include "optional.hpp" +#include TEST_CASE("Relational ops", "[relops]") { tl::optional o1{4}; From d7356bb01cb6abf4c1b2fe2e110b829662d27745 Mon Sep 17 00:00:00 2001 From: Simon Brand Date: Tue, 25 Jun 2019 09:47:19 +0100 Subject: [PATCH 2/5] Use FetchContent --- CMakeLists.txt | 13 +++++++++++-- cmake/tl-cmake | 1 - 2 files changed, 11 insertions(+), 3 deletions(-) delete mode 160000 cmake/tl-cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 18246ad..b285424 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,19 @@ -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.11) project(tl-optional VERSION 1.0.0 LANGUAGES CXX) option(OPTIONAL_ENABLE_TESTS "Enable tests." ON) -set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/tl-cmake" ${CMAKE_MODULE_PATH}) +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(optional SOURCES diff --git a/cmake/tl-cmake b/cmake/tl-cmake deleted file mode 160000 index 576e25f..0000000 --- a/cmake/tl-cmake +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 576e25feabec4c79ebe2cf7174398c61de05d384 From 3cfcb3ff2db38ae899cb66372dc846f46e0b4cd0 Mon Sep 17 00:00:00 2001 From: Simon Brand Date: Tue, 25 Jun 2019 10:07:25 +0100 Subject: [PATCH 3/5] Use Xenial on Travis instead of Trusty --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 46eccb1..6f079a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: cpp -dist: trusty +dist: xenial sudo: false matrix: From 9839b761e03f40bf83cc630475d0341aec065a8b Mon Sep 17 00:00:00 2001 From: Simon Brand Date: Tue, 25 Jun 2019 10:47:46 +0100 Subject: [PATCH 4/5] Tidy traits --- include/tl/optional.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/tl/optional.hpp b/include/tl/optional.hpp index 4b9cee8..200825e 100644 --- a/include/tl/optional.hpp +++ b/include/tl/optional.hpp @@ -138,13 +138,13 @@ struct conjunction : std::conditional, B>::type {}; #if defined(_LIBCPP_VERSION) && __cplusplus == 201103L -#define TL_OPTIONAL_LIBCXX_MEM_FN_WORKAROUND +#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_OPTIONAL_LIBCXX_MEM_FN_WORKAROUND +#ifdef TL_TRAITS_LIBCXX_MEM_FN_WORKAROUND template struct is_pointer_to_non_const_member_func : std::false_type{}; template struct is_pointer_to_non_const_member_func : std::true_type{}; @@ -167,7 +167,7 @@ template struct is_const_or_const_ref : std::true_type{}; // std::invoke from C++17 // https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround template ::value && is_const_or_const_ref::value)>, #endif From 359499d904d653660fd32cb2f988625e0ef3a64e Mon Sep 17 00:00:00 2001 From: Simon Brand Date: Tue, 25 Jun 2019 10:52:08 +0100 Subject: [PATCH 5/5] Use Xenial repos --- .travis.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6f079a8..03842f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -98,7 +98,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: @@ -109,7 +109,7 @@ matrix: addons: apt: sources: - - llvm-toolchain-trusty-4.0 + - llvm-toolchain-xenial-4.0 - ubuntu-toolchain-r-test packages: - clang++-4.0 @@ -119,7 +119,7 @@ matrix: addons: apt: sources: - - llvm-toolchain-trusty-5.0 + - llvm-toolchain-xenial-5.0 - ubuntu-toolchain-r-test packages: - clang++-5.0 @@ -129,7 +129,7 @@ matrix: addons: apt: sources: - - llvm-toolchain-trusty-6.0 + - llvm-toolchain-xenial-6.0 - ubuntu-toolchain-r-test packages: - clang++-6.0 @@ -212,7 +212,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: @@ -223,7 +223,7 @@ matrix: addons: apt: sources: - - llvm-toolchain-trusty-4.0 + - llvm-toolchain-xenial-4.0 - ubuntu-toolchain-r-test packages: - clang++-4.0 @@ -233,7 +233,7 @@ matrix: addons: apt: sources: - - llvm-toolchain-trusty-5.0 + - llvm-toolchain-xenial-5.0 - ubuntu-toolchain-r-test packages: - clang++-5.0 @@ -243,7 +243,7 @@ matrix: addons: apt: sources: - - llvm-toolchain-trusty-6.0 + - llvm-toolchain-xenial-6.0 - ubuntu-toolchain-r-test packages: - clang++-6.0