-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 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
- Loading branch information
1 parent
fd96e45
commit 0ca73ee
Showing
17 changed files
with
150 additions
and
12,082 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
\#* | ||
.\#* | ||
/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,117 @@ | ||
cmake_minimum_required(VERSION 3.11) | ||
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) | ||
|
||
project(tl-expected VERSION 1.0.0 LANGUAGES CXX) | ||
include(CMakePackageConfigHelpers) | ||
include(CMakeDependentOption) | ||
include(GNUInstallDirs) | ||
include(FetchContent) | ||
include(CTest) | ||
|
||
if (NOT DEFINED CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 14) | ||
endif() | ||
|
||
option(EXPECTED_ENABLE_TESTS "Enable tests." ON) | ||
option(EXPECTED_BUILD_PACKAGE "Build package files as well" ON) | ||
|
||
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}) | ||
cmake_dependent_option(EXPECTED_BUILD_TESTS | ||
"Enable tl::expected tests" ON | ||
"BUILD_TESTING" OFF) | ||
|
||
cmake_dependent_option(EXPECTED_BUILD_PACKAGE_DEB | ||
"Create a DEB" ON | ||
"EXPECTED_BUILD_PACKAGE" OFF) | ||
|
||
add_library(expected INTERFACE) | ||
target_include_directories(expected | ||
INTERFACE | ||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:include>) | ||
|
||
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() | ||
include(add-tl) | ||
|
||
tl_add_library(expected SOURCES | ||
include/tl/expected.hpp) | ||
|
||
# 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}) | ||
|
||
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) | ||
|
||
add_executable(tests ${TEST_SOURCES}) | ||
|
||
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 (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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "catch.hpp" | ||
#include <catch2/catch.hpp> | ||
#include <tl/expected.hpp> | ||
|
||
#include <string> | ||
|
Oops, something went wrong.