Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow usage of system provided status-code #258

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# (See accompanying file Licence.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

set(OUTCOME_DEPENDENCY_QUICKCPPLIB_GIT_TAG "master" CACHE STRING "Which git tag to use for the QuickCppLib dependency")
if(NOT OUTCOME_DEPENDENCY_QUICKCPPLIB_GIT_TAG STREQUAL "master")
Expand All @@ -32,13 +32,24 @@ if(NOT OUTCOME_DEPENDENCY_QUICKCPPLIB_GIT_TAG STREQUAL "master")
set(CTEST_QUICKCPPLIB_CLONE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/quickcpplib-bootstrap")
endif()
endif()
set(OUTCOME_DEPENDENCY_STATUS_CODE_GIT_TAG "master" CACHE STRING "Which git tag to use for the status-code dependency")
option(OUTCOME_BUNDLE_EMBEDDED_STATUS_CODE "Whether to bundle an embedded copy of SG14 status-code with Outcome. Used by various package managers such as vcpkg." ON)

include(cmake/QuickCppLibBootstrap.cmake)
include(QuickCppLibRequireOutOfSourceBuild)
include(QuickCppLibUtils)
include(QuickCppLibPolicies)

ensure_git_subrepo("${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/experimental/status-code/include" "https://github.com/ned14/status-code.git")
if(OUTCOME_BUNDLE_EMBEDDED_STATUS_CODE)
ensure_git_subrepo("${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/experimental/status-code/include" "https://github.com/ned14/status-code.git")
else()
find_quickcpplib_library(status-code
GIT_REPOSITORY "https://github.com/ned14/status-code.git"
GIT_TAG "${OUTCOME_DEPENDENCY_STATUS_CODE_GIT_TAG}"
REQUIRED
IS_HEADER_ONLY
)
endif()

# Parse the version we tell cmake directly from the version header file
ParseProjectVersionFromHpp("${CMAKE_CURRENT_SOURCE_DIR}/include/outcome/detail/version.hpp" VERSIONSTRING)
Expand Down Expand Up @@ -88,6 +99,9 @@ else()
IS_HEADER_ONLY
)
endif()
if (NOT OUTCOME_BUNDLE_EMBEDDED_STATUS_CODE)
list_filter(${PROJECT_NAME}_HEADERS EXCLUDE REGEX /status-code/include/)
endif()

# Make an interface only library so dependent CMakeLists can bring in this header-only library
include(QuickCppLibMakeHeaderOnlyLibrary)
Expand Down Expand Up @@ -155,6 +169,10 @@ endif()
if(TARGET quickcpplib::hl)
target_link_libraries(outcome_hl INTERFACE quickcpplib::hl)
endif()
if(TARGET status-code::hl)
target_link_libraries(outcome_hl INTERFACE status-code::hl)
all_compile_definitions(PUBLIC OUTCOME_USE_SYSTEM_STATUS_CODE=1)
ned14 marked this conversation as resolved.
Show resolved Hide resolved
endif()

if(OUTCOME_ENABLE_CXX_MODULES)
# Right now this is very hacky, as cmake doesn't support building C++ Modules yet
Expand Down Expand Up @@ -363,11 +381,12 @@ endif()
include(QuickCppLibCacheLibrarySources)

# Dependencies needed to consume our cmake package
set(PROJECT_PACKAGE_DEPENDENCIES "include(CMakeFindDependencyMacro)")
if(TARGET quickcpplib::hl)
set(PROJECT_PACKAGE_DEPENDENCIES [=[
include(CMakeFindDependencyMacro)
find_dependency(quickcpplib)
]=])
string(APPEND PROJECT_PACKAGE_DEPENDENCIES "\nfind_dependency(quickcpplib)")
endif()
if(TARGET status-code::hl)
string(APPEND PROJECT_PACKAGE_DEPENDENCIES "\nfind_dependency(status-code)")
endif()

# Make available this library for install and export
Expand Down
4 changes: 4 additions & 0 deletions include/outcome/experimental/status_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ Distributed under the Boost Software License, Version 1.0.
#include "../basic_result.hpp"
#include "../policy/fail_to_compile_observers.hpp"

#if !OUTCOME_USE_SYSTEM_STATUS_CODE && __has_include("status-code/include/system_error2.hpp")
ned14 marked this conversation as resolved.
Show resolved Hide resolved
#include "status-code/include/system_error2.hpp"
#else
#include <status-code/system_error2.hpp>
#endif

OUTCOME_V2_NAMESPACE_EXPORT_BEGIN

Expand Down