🎨 Revamp CMake to be correct and easy to understand (#69)

🎨 Cleanup include path for catch2

 Add basic .deb generation support
  WiX and RPM support is still needed (if even desired?)

⬆️ Upgrade minimum CMake version to 3.14
⬆️ Upgrade Catch to Catch v2.9.2
📌 Pin Catch to v2.9.2
This commit is contained in:
Isabella Muerte
2019-10-25 06:44:01 -07:00
committed by Sy Brand
parent fd96e4545c
commit 0ca73ee30e
17 changed files with 146 additions and 12078 deletions

View File

@ -3,9 +3,6 @@ os:
- Visual Studio 2017
build_script:
- git submodule update --init --recursive
- mkdir build
- cd build
- cmake ..
- cmake --build .
- C:\projects\expected\build\Debug\tests.exe
- cmake -Bbuild -S.
- cmake --build build
- cmake --build build --target RUN_TESTS

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
\#*
.\#*
/build/

View File

@ -1,7 +1,6 @@
language: cpp
dist: xenial
sudo: false
matrix:
include:
@ -87,8 +86,9 @@ matrix:
addons:
apt:
sources:
- llvm-toolchain-precise-3.8
- ubuntu-toolchain-r-test
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.8 main"
key_url: "http://apt.llvm.org/llvm-snapshot.gpg.key"
- ubuntu-toolchain-r-test
packages:
- clang++-3.8
- libc++-dev
@ -201,8 +201,9 @@ matrix:
addons:
apt:
sources:
- llvm-toolchain-precise-3.8
- ubuntu-toolchain-r-test
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.8 main"
key_url: "http://apt.llvm.org/llvm-snapshot.gpg.key"
- ubuntu-toolchain-r-test
packages:
- clang++-3.8
- libc++-dev
@ -249,9 +250,19 @@ matrix:
- libc++-dev
env: COMPILER=clang++-6.0 CXXSTD=14
before_install:
- sudo apt update
- sudo apt install -y apt-transport-https ca-certificates gnupg software-properties-common
- curl -L https://apt.kitware.com/keys/kitware-archive-latest.asc | sudo apt-key add -
- sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ xenial main'
- sudo apt update
install:
- if [ "$CXX" = "clang++" ]; then export CXX="$COMPILER -stdlib=libc++"; fi
- if [ "$CXX" = "g++" ]; then export CXX="$COMPILER"; fi
- if [ "$CXX" = "clang++" ]; then export CXX="$COMPILER -stdlib=libc++"; fi
- if [ "$CXX" = "g++" ]; then export CXX="$COMPILER"; fi
- sudo apt install -y cmake
script: mkdir build && cd build && cmake -DCXXSTD=$CXXSTD .. && make && ./tests
script:
- /usr/bin/cmake -B build -S . "-DCMAKE_CXX_STANDARD=$CXXSTD"
- /usr/bin/cmake --build build
- /usr/bin/cmake --build build --target test

View File

@ -1,46 +1,117 @@
cmake_minimum_required(VERSION 3.11)
project(tl-expected VERSION 1.0.0 LANGUAGES CXX)
option(EXPECTED_ENABLE_TESTS "Enable tests." ON)
cmake_minimum_required(VERSION 3.14)
project(tl-expected
HOMEPAGE_URL https://tl.tartanllama.xyz
DESCRIPTION "C++11/14/17 std::expected with functional-style extensions"
VERSION 1.0.0
LANGUAGES CXX)
include(CMakePackageConfigHelpers)
include(CMakeDependentOption)
include(GNUInstallDirs)
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})
include(CTest)
if (NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
include(add-tl)
tl_add_library(expected SOURCES
include/tl/expected.hpp)
option(EXPECTED_BUILD_PACKAGE "Build package files as well" ON)
# Prepare "Catch" library for other executables
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
add_library(Catch INTERFACE)
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
cmake_dependent_option(EXPECTED_BUILD_TESTS
"Enable tl::expected tests" ON
"BUILD_TESTING" OFF)
if(EXPECTED_ENABLE_TESTS)
# Make test executable
set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/extensions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/assignment.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/emplace.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/issues.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/bases.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/observers.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/swap.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/constructors.cpp)
cmake_dependent_option(EXPECTED_BUILD_PACKAGE_DEB
"Create a DEB" ON
"EXPECTED_BUILD_PACKAGE" OFF)
add_executable(tests ${TEST_SOURCES})
add_library(expected INTERFACE)
target_include_directories(expected
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_link_libraries(tests Catch expected)
set(CXXSTD 14 CACHE STRING "C++ standard to use, default C++14")
set_property(TARGET tests PROPERTY CXX_STANDARD ${CXXSTD})
set_property(TARGET tests PROPERTY CXX_FLAGS "-Wall -Wextra")
if (NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
add_executable(tl::expected ALIAS expected)
endif()
# Installation help
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION "share/cmake/${PROJECT_NAME}")
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT)
install(TARGETS expected
EXPORT ${PROJECT_NAME}-targets
INCLUDES DESTINATION "${CMAKE_INSTALL_DATADIR}")
install(EXPORT ${PROJECT_NAME}-targets
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}"
NAMESPACE tl::
FILE "${PROJECT_NAME}-targets.cmake")
install(FILES
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}")
install(DIRECTORY "include/" TYPE INCLUDE)
if(EXPECTED_BUILD_TESTS)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(CATCH_INSTALL_HELPERS OFF)
set(CATCH_BUILD_TESTING OFF)
set(CATCH_INSTALL_DOCS OFF)
FetchContent_Declare(Catch2 URL
https://github.com/catchorg/Catch2/archive/v2.9.2.zip)
FetchContent_MakeAvailable(Catch2)
file(GLOB test-sources CONFIGURE_DEPENDS tests/*.cpp)
list(FILTER test-sources EXCLUDE REGEX "tests/test.cpp")
add_executable(${PROJECT_NAME}-tests "${test-sources}")
target_compile_options(${PROJECT_NAME}-tests PRIVATE
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra>)
target_link_libraries(${PROJECT_NAME}-tests
PRIVATE
Catch2::Catch2
expected)
add_test(NAME tl::expected::tests COMMAND ${PROJECT_NAME}-tests)
endif()
if (NOT EXPECTED_BUILD_PACKAGE)
return()
endif()
list(APPEND source-generators TBZ2 TGZ TXZ ZIP)
if (CMAKE_HOST_WIN32)
list(APPEND binary-generators "WIX")
endif()
if (EXPECTED_BUILD_PACKAGE_DEB)
list(APPEND binary-generators "DEB")
endif()
if (EXPECTED_BUILD_RPM)
list(APPEND binary-generators "RPM")
endif()
set(CPACK_SOURCE_GENERATOR ${source-generators})
set(CPACK_GENERATOR ${binary-generators})
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Sy Brand")
list(APPEND CPACK_SOURCE_IGNORE_FILES /.git/ /build/ .gitignore .DS_Store)
include(CPack)

View File

@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>
#include <tl/expected.hpp>
TEST_CASE("Simple assignment", "[assignment.simple]") {

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,8 +1,8 @@
#include "catch.hpp"
#include <catch2/catch.hpp>
#include <tl/expected.hpp>
#include <vector>
#include <type_traits>
#include <vector>
#include <string>
struct takes_init_and_variadic {

View File

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

View File

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

View File

@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>
#include <tl/expected.hpp>
#include <string>
@ -135,4 +135,4 @@ tl::expected<int, std::unique_ptr<std::string>> func()
TEST_CASE("Issue 61", "[issues.61]") {
REQUIRE(func().value() == 1);
}
}

View File

@ -1,2 +1,2 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <catch2/catch.hpp>

View File

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

View File

@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>
#include <tl/expected.hpp>
struct move_detector {

View File

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

View File

@ -1,4 +1,4 @@
#include "catch.hpp"
#include <catch2/catch.hpp>
#include <tl/expected.hpp>
struct no_throw {
@ -98,4 +98,4 @@ TEST_CASE("swap") {
REQUIRE(a->i == s1);
REQUIRE(b.error().i == s2);
}
}