Skip to content

Commit b6e3fb1

Browse files
authored
Boost optional is no longer automatic (#279)
* Boost optional is no longer automatic * Tighten up optional a bit * Check times
1 parent 10e4b07 commit b6e3fb1

File tree

5 files changed

+33
-25
lines changed

5 files changed

+33
-25
lines changed

.ci/azure-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ steps:
55
cmakeArgs: .. -DCLI11_SINGLE_FILE=$(cli11.single) -DCLI11_CXX_STD=$(cli11.std) -DCLI11_SINGLE_FILE_TESTS=$(cli11.single) -DCMAKE_BUILD_TYPE=$(cli11.build_type) $(cli11.options)
66
displayName: 'Configure'
77

8-
- script: cmake --build . $(cli11.threadopt)
8+
- script: cmake --build .
99
displayName: 'Build'
1010
workingDirectory: build
1111

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ else()
1111
cmake_policy(VERSION 3.14)
1212
endif()
1313

14+
# TESTING: remove this later
15+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
16+
1417
set(VERSION_REGEX "#define CLI11_VERSION[ \t]+\"(.+)\"")
1518

1619
# Read in the line containing the version

azure-pipelines.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ variables:
1111
cli11.std: 14
1212
cli11.build_type: Debug
1313
cli11.options:
14-
cli11.threadopt: -j
14+
CMAKE_BUILD_PARALLEL_LEVEL: 4
1515

1616
jobs:
1717

@@ -21,7 +21,7 @@ jobs:
2121
cli11.options: -DCLANG_TIDY_FIX=ON
2222
cli11.std: 11
2323
cli11.single: OFF
24-
cli11.threadopt:
24+
CMAKE_BUILD_PARALLEL_LEVEL: 1
2525
pool:
2626
vmImage: 'ubuntu-16.04'
2727
container: silkeh/clang:5
@@ -37,9 +37,9 @@ jobs:
3737
strategy:
3838
matrix:
3939
Linux:
40-
vmImage: 'ubuntu-16.04'
40+
vmImage: 'ubuntu-latest'
4141
macOS:
42-
vmImage: 'macOS-10.14'
42+
vmImage: 'macOS-latest'
4343
Windows:
4444
vmImage: 'vs2017-win2016'
4545
pool:
@@ -52,7 +52,7 @@ jobs:
5252
variables:
5353
cli11.single: OFF
5454
pool:
55-
vmImage: 'ubuntu-16.04'
55+
vmImage: 'ubuntu-latest'
5656
strategy:
5757
matrix:
5858
gcc9:

include/CLI/Optional.hpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,35 @@
88
#include "CLI/Macros.hpp"
99

1010
// [CLI11:verbatim]
11-
#ifdef __has_include
1211

1312
// You can explicitly enable or disable support
14-
// by defining these to 1 or 0.
15-
#if defined(CLI11_CPP17) && __has_include(<optional>) && \
16-
!defined(CLI11_STD_OPTIONAL)
13+
// by defining to 1 or 0. Extra check here to ensure it's in the stdlib too.
14+
// We nest the check for __has_include and it's usage
15+
#ifndef CLI11_STD_OPTIONAL
16+
#ifdef __has_include
17+
#if defined(CLI11_CPP17) && __has_include(<optional>)
1718
#define CLI11_STD_OPTIONAL 1
18-
#elif !defined(CLI11_STD_OPTIONAL)
19+
#else
1920
#define CLI11_STD_OPTIONAL 0
2021
#endif
22+
#else
23+
#define CLI11_STD_OPTIONAL 0
24+
#endif
25+
#endif
2126

22-
#if !defined(CLI11_EXPERIMENTAL_OPTIONAL)
27+
#ifndef CLI11_EXPERIMENTAL_OPTIONAL
2328
#define CLI11_EXPERIMENTAL_OPTIONAL 0
2429
#endif
2530

26-
#if __has_include(<boost/optional.hpp>) && !defined(CLI11_BOOST_OPTIONAL)
27-
#include <boost/version.hpp>
28-
#if BOOST_VERSION >= 106100
29-
#define CLI11_BOOST_OPTIONAL 1
30-
#endif
31-
#elif !defined(CLI11_BOOST_OPTIONAL)
31+
#ifndef CLI11_BOOST_OPTIONAL
3232
#define CLI11_BOOST_OPTIONAL 0
3333
#endif
3434

35+
#if CLI11_BOOST_OPTIONAL
36+
#include <boost/version.hpp>
37+
#if BOOST_VERSION < 106100
38+
#error "This boost::optional version is not supported, use 1.61 or better"
39+
#endif
3540
#endif
3641

3742
#if CLI11_STD_OPTIONAL

tests/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ file(WRITE "${PROJECT_BINARY_DIR}/CTestCustom.cmake"
115115
find_package(Boost 1.61)
116116
if(Boost_FOUND)
117117
if(TARGET Boost::boost)
118-
target_link_libraries(informational PUBLIC Boost::boost)
119-
target_link_libraries(OptionalTest PUBLIC Boost::boost)
118+
target_link_libraries(informational PRIVATE Boost::boost)
119+
target_link_libraries(OptionalTest PRIVATE Boost::boost)
120120
else()
121-
target_include_directories(informational PUBLIC ${Boost_INCLUDE_DIRS})
122-
target_include_directories(OptionalTest PUBLIC ${Boost_INCLUDE_DIRS})
121+
target_include_directories(informational PRIVATE ${Boost_INCLUDE_DIRS})
122+
target_include_directories(OptionalTest PRIVATE ${Boost_INCLUDE_DIRS})
123123
endif()
124-
# Enforce Boost::Optional even if __has_include is missing on your compiler
125-
target_compile_definitions(informational PUBLIC CLI11_BOOST_OPTIONAL)
126-
target_compile_definitions(OptionalTest PUBLIC CLI11_BOOST_OPTIONAL)
124+
125+
target_compile_definitions(informational PRIVATE CLI11_BOOST_OPTIONAL)
126+
target_compile_definitions(OptionalTest PRIVATE CLI11_BOOST_OPTIONAL)
127127
endif()
128128

129129
if(CMAKE_BUILD_TYPE STREQUAL Coverage)

0 commit comments

Comments
 (0)