Skip to content

Commit a6caaf1

Browse files
authored
Enable C++11 compatibility (#16)
* first working version for C++11 * files forgotten * fixed bug in ZipWithStdVectorUnequalSizesThrowsTest * using C++11 by default * pretty formatting to custom gcc script * Update README.md * enabling actions for C++11 and C++17 * fixed yml syntax * replaced matrix.config.os with name * forgotten continuation for C++17 in terminal * windows compiler: 'init-statements in if/switch' requires compiler flag '/std:c++17' * fixed another init-statement in if * removed build option to C++17 * generic replacement for optional based on PR feedback * Added date to credit
1 parent b2a87b9 commit a6caaf1

File tree

10 files changed

+531
-168
lines changed

10 files changed

+531
-168
lines changed

.github/workflows/cmake.yml

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
matrix:
2222
config:
2323
- {
24-
name: "Windows Latest MSVC",
24+
name: "Windows Latest MSVC (C++11)",
2525
os: windows-latest,
2626
build_type: "Debug",
2727
cc: "cl",
@@ -30,15 +30,40 @@ jobs:
3030
generators: "Visual Studio 16 2019"
3131
}
3232
- {
33-
name: "Ubuntu Latest GCC",
33+
name: "Windows Latest MSVC (C++17)",
34+
os: windows-latest,
35+
build_type: "Debug",
36+
cc: "cl",
37+
cxx: "cl",
38+
environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat",
39+
generators: "Visual Studio 16 2019"
40+
}
41+
- {
42+
name: "Ubuntu Latest GCC (C++11)",
3443
os: ubuntu-latest,
3544
build_type: "Debug",
3645
cc: "gcc",
3746
cxx: "g++",
3847
generators: "Ninja"
3948
}
4049
- {
41-
name: "macOS Latest Clang",
50+
name: "Ubuntu Latest GCC (C++17)",
51+
os: ubuntu-latest,
52+
build_type: "Debug",
53+
cc: "gcc",
54+
cxx: "g++",
55+
generators: "Ninja"
56+
}
57+
- {
58+
name: "macOS Latest Clang (C++11)",
59+
os: macos-latest,
60+
build_type: "Debug",
61+
cc: "clang",
62+
cxx: "clang++",
63+
generators: "Xcode"
64+
}
65+
- {
66+
name: "macOS Latest Clang (C++17)",
4267
os: macos-latest,
4368
build_type: "Debug",
4469
cc: "clang",
@@ -54,6 +79,7 @@ jobs:
5479
run: |
5580
echo github.event.action: ${{ github.event.action }}
5681
echo github.event_name: ${{ github.event_name }}
82+
5783
- name: Install dependencies on windows
5884
if: startsWith(matrix.config.os, 'windows')
5985
run: |
@@ -69,21 +95,35 @@ jobs:
6995
ninja --version
7096
cmake --version
7197
gcc --version
98+
7299
- name: Install dependencies on macos
73100
if: startsWith(matrix.config.os, 'macos')
74101
run: |
75102
brew install cmake ninja
76103
ninja --version
77104
cmake --version
78105
79-
- name: Configure
106+
- name: Configure C++11
107+
shell: bash
108+
if: contains(matrix.config.name, 'C++11')
109+
run: |
110+
mkdir build
111+
cmake \
112+
-S . \
113+
-B build \
114+
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
115+
-G "${{ matrix.config.generators }}"
116+
117+
- name: Configure C++17
80118
shell: bash
119+
if: contains(matrix.config.name, 'C++17')
81120
run: |
82121
mkdir build
83122
cmake \
84123
-S . \
85124
-B build \
86125
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
126+
-DCMAKE_CXX_STANDARD=17 \
87127
-G "${{ matrix.config.generators }}"
88128
89129
- name: Build

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ compile_commands.json
1010
CTestTestfile.cmake
1111
_deps
1212
build/
13+
build_cpp11/
14+
build_cpp17/
15+
build_gcc/
1316
/.vs

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ cmake_minimum_required(VERSION 3.14)
22
project(functional_vector VERSION 0.9)
33

44
# GoogleTest requires at least C++11
5-
set(CMAKE_CXX_STANDARD 17)
5+
if(NOT "${CMAKE_CXX_STANDARD}")
6+
set(CMAKE_CXX_STANDARD 11)
7+
endif()
8+
message("-- C++ standard version: ${CMAKE_CXX_STANDARD}")
69

710
# For Windows: Prevent overriding the parent project's compiler/linker settings
811
if(CMAKE_HOST_WIN32)
@@ -36,4 +39,4 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
3639

3740
# Include the testing subdirectory
3841
add_subdirectory(src)
39-
add_subdirectory(tests)
42+
add_subdirectory(tests)

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,38 @@ This is heavily influenced and inspired by C# and Swift.
1010
* CMake >= 3.14
1111

1212
### Minimum C++ version
13-
* C++17
13+
* C++11
1414

15-
An out-of-source build strategy is used. All following examples assume an output build folder named ```build```.
15+
An out-of-source build strategy is used. All following examples assume an output build folder named ```build```. If no additional argument is passed to CMake, C++11 is used. Otherwise, you can pass ```-DCMAKE_CXX_STANDARD=17``` and it will use C++17 for example.
1616
### macOS (Xcode)
1717
```console
1818
cd functional_vector
1919
cmake -S . -B build -G Xcode
2020
```
2121
Then open the generated ```functional_vector.xcodeproj``` in the ```build``` folder.
2222

23-
### macOS and Linux (Makefiles)
23+
### macOS (Makefiles/clang)
24+
```console
25+
cd functional_vector
26+
cmake -S . -B build
27+
cmake --build build
28+
build/tests/unit_tests
29+
```
30+
31+
### macOS (Makefiles/g++)
32+
Assuming you have installed Homebrew, then you can use the gcc and g++ compilers by doing the following (this example uses version gcc 11)
33+
```console
34+
cd functional_vector
35+
cmake \
36+
-S . \
37+
-B build \
38+
-DCMAKE_C_COMPILER=/opt/homebrew/Cellar/gcc/11.2.0/bin/gcc-11 \
39+
-DCMAKE_CXX_COMPILER=/opt/homebrew/Cellar/gcc/11.2.0/bin/g++-11
40+
cmake --build build
41+
build/tests/unit_tests
42+
```
43+
44+
### Linux (Makefiles)
2445
```console
2546
cd functional_vector
2647
cmake -S . -B build

include/compatibility.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2021 Ioannis Kaliakatsos
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
#pragma once
24+
25+
#if __cplusplus >= 201703L
26+
#define CPP17_AVAILABLE
27+
#endif

include/export_def.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030
#endif
3131
#else
3232
#define FunctionalVectorExport __attribute__ ((__visibility__("default")))
33-
#endif
33+
#endif
34+
35+
#include "compatibility.h"

0 commit comments

Comments
 (0)