Skip to content

Commit

Permalink
[core] update to c++20 (organicmaps#7299)
Browse files Browse the repository at this point in the history
* Update to C++20

Signed-off-by: Harry Bond <[email protected]>

* Update CMakeLists.txt

Signed-off-by: Alexander Borsuk <[email protected]>

---------

Signed-off-by: Harry Bond <[email protected]>
Signed-off-by: Alexander Borsuk <[email protected]>
Co-authored-by: Alexander Borsuk <[email protected]>
  • Loading branch information
RedAuburn and biodranik authored Jun 3, 2024
1 parent 3ca578e commit 22fb1fe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ IndentCaseLabels: false
NamespaceIndentation: None
PointerAlignment: Middle
SortIncludes: true
Standard: c++17
Standard: c++20
IncludeBlocks: Regroup
IncludeCategories:
# Tests --------------------------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.18)
project(omim C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 11)
# Our code does not rely on gnu extensions.
set(CMAKE_CXX_EXTENSIONS OFF)
Expand All @@ -26,7 +26,7 @@ if (APPLE AND NOT ("${CMAKE_SYSTEM_NAME}" STREQUAL Android))
set(CMAKE_OBJC_VISIBILITY_PRESET hidden)
enable_language(OBJCXX)
set(CMAKE_OBJCXX_EXTENSIONS OFF)
set(CMAKE_OBJCXX_STANDARD 17)
set(CMAKE_OBJCXX_STANDARD 20)
set(CMAKE_OBJCXX_FLAGS -fobjc-arc)
set(CMAKE_OBJCXX_VISIBILITY_PRESET hidden)
endif()
Expand Down Expand Up @@ -166,9 +166,9 @@ if (NJOBS)
set(CMAKE_JOB_POOL_PRECOMPILE_HEADER custom)
endif()

# GCC 8.1 is required to support <charconv> header inclusion in base/string_utils.hpp, otherwise 7.0 is sufficient
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.1)
message(FATAL_ERROR "Minimum supported g++ version is 8.1 yours is ${CMAKE_CXX_COMPILER_VERSION}")
# GCC 10.0 is required to support <charconv> header inclusion in base/string_utils.hpp
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
message(FATAL_ERROR "Minimum supported g++ version is 10.0, yours is ${CMAKE_CXX_COMPILER_VERSION}")
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand Down
4 changes: 2 additions & 2 deletions cmake/OmimHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ function(add_precompiled_headers header pch_target_name)
export_directory_flags("${pch_flags_file}")
set(compiler_flags "@${pch_flags_file}")

# CMAKE_CXX_STANDARD 17 flags:
set(c_standard_flags "-std=c++17")
# CMAKE_CXX_STANDARD 20 flags:
set(c_standard_flags "-std=c++20")
get_filename_component(pch_file_name ${header} NAME)

add_pic_pch_target(${header} ${pch_target_name} ${pch_file_name} lib "-fPIC")
Expand Down
8 changes: 4 additions & 4 deletions docs/CPP_STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ In general, [Google's coding standard](https://google.github.io/styleguide/cppgu

Below are our specific (but not all!) exceptions to the Google's coding standard:

- All C++ code should conform to the C++17 standard.
- All C++ code should conform to the C++20 standard.
- We use `.cpp` and `.hpp` files, not `.cc` and `.h` (`.c` and `.h` are used for C code), in UTF-8 encoding.
- File names are lowercase with underscores, like `file_reader.cpp`.
- We use `#pragma once` instead of the `#define` Guard in header files.
- Includes are sorted and grouped by directory, there should be newlines between different directories.
- Order of directories in includes: "current_dir/current_file.hpp", includes from other dirs sorted by dependencies (e.g. indexer, then coding, then base), "defines.hpp", C++ standard library headers, boost headers, 3party.
- We ARE using C++ exceptions.
- We are using all features of C++17 except the filesystem which is not fully supported on all platforms.
- We try to limit the usage of boost libraries which require linking (and prefer C++17 types over their boost counterparts).
- We are using all features of C++17 and C++20 except std::filesystem, std::to_chars & std::from_chars which are not fully supported on all platforms.
- We try to limit the usage of boost libraries which require linking (and prefer C++20 types over their boost counterparts).

Naming and formatting

Expand Down Expand Up @@ -195,7 +195,7 @@ v = w * (x + z);
- If you see outdated code which can be improved, DO IT NOW (but in a separate pull request or commit)!
- Your code should work at least on [mac|linux|android][x86|x86_64], [ios|android][x86|armv7|arm64] architectures
- Your code should compile with C++17 compiler
- Your code should compile with C++20 compiler
- Avoid using any new 3party library if it is not fully tested and supported on all our platforms
- Cover your code with unit tests. See examples for existing libraries
- Check Base and Coding libraries for most of the basic functions
Expand Down

0 comments on commit 22fb1fe

Please sign in to comment.