Skip to content

Commit

Permalink
Squashed 'externals/coda-oss/' changes from a8c5a3b2b..422c334c8
Browse files Browse the repository at this point in the history
422c334c8 Merge branch 'cpp17' into cpp20
97f1dbf6d Merge branch 'cpp17' into cpp20
e12fbce2e Merge branch 'cpp17' into cpp20
729d61fb4 use GCC 10 on build server
69e5f8d52 restore C++20

git-subtree-dir: externals/coda-oss
git-subtree-split: 422c334c8448c21bf2f703dcb0c87ff1354ba2c6
  • Loading branch information
Dan Smith committed Aug 29, 2023
1 parent d12bcf8 commit 1df497c
Show file tree
Hide file tree
Showing 25 changed files with 104 additions and 1,013 deletions.
14 changes: 6 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
cmake_minimum_required(VERSION 3.14)
project(coda-oss)

set(CMAKE_CXX_STANDARD 17)
project(coda-oss)

set(CMAKE_CXX_STANDARD 20)
set(CXX_STANDARD_REQUIRED true)

if (EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
Expand All @@ -22,13 +24,9 @@ if (${CMAKE_PROJECT_NAME} STREQUAL coda-oss)
# Always turn on "warnings as errors" to avoid lots of (meaningless?) build output;
# we'll dial-back warnings as necessary.
if (MSVC)
add_compile_options(/WX) # warnings as errors
add_compile_options(/MP) # multi-processor compile

if (ENABLE_ASAN)
# https://docs.microsoft.com/en-us/cpp/sanitizers/asan?view=msvc-160
add_compile_options(/fsanitize=address)
endif()
# set warning level to /W3
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE "/W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
elseif (UNIX)
add_compile_options(-Werror) # warnings as errors

Expand Down
8 changes: 4 additions & 4 deletions UnitTest/UnitTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
<ConformanceMode>true</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
Expand All @@ -99,8 +99,8 @@
<ConformanceMode>true</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
52 changes: 28 additions & 24 deletions build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ def options(opt):
'results. NOOP if junit_xml cannot be imported')


def ensureCpp17Support(self):
def ensureCpp20Support(self):
# DEPRECATED.
# Keeping for now in case downstream code is still looking for it
self.env['cpp11support'] = True
Expand All @@ -830,6 +830,14 @@ def configureCompilerOptions(self):

if ccCompiler == 'msvc':
cxxCompiler = ccCompiler
else:
if ccCompiler == 'gcc':
ccCompiler = 'gcc-10'
self.env['COMPILER_CC'] =ccCompiler

if cxxCompiler == 'g++':
cxxCompiler = 'g++-10'
self.env['COMPILER_CXX'] = cxxCompiler

if not cxxCompiler or not ccCompiler:
self.fatal('Unable to find C/C++ compiler')
Expand Down Expand Up @@ -873,7 +881,7 @@ def configureCompilerOptions(self):
self.env.append_value('CFLAGS', '-fPIC -dynamiclib'.split())

# GCC / ICC (for Linux or Solaris)
elif ccCompiler == 'gcc' or ccCompiler == 'icc':
elif ccCompiler == 'gcc' or ccCompiler == 'gcc-10' or ccCompiler == 'icc':
if not re.match(winRegex, sys_platform):
self.env.append_value('LIB_DL', 'dl')
if not re.match(osxRegex, sys_platform):
Expand All @@ -883,7 +891,7 @@ def configureCompilerOptions(self):
self.check_cc(lib='pthread', mandatory=True)

warningFlags = '-Wall'
if ccCompiler == 'gcc':
if ccCompiler == 'gcc' or ccCompiler == 'gcc-10':
#warningFlags += ' -Wno-deprecated-declarations -Wold-style-cast'
warningFlags += ' -Wno-deprecated-declarations'
else:
Expand All @@ -897,7 +905,13 @@ def configureCompilerOptions(self):
# If you want the plugins to not depend on Intel libraries,
# configure with:
# --with-cflags=-static-intel --with-cxxflags=-static-intel --with-linkflags=-static-intel
if cxxCompiler == 'g++' or cxxCompiler == 'icpc':
if cxxCompiler == 'gcc' or cxxCompiler == 'gcc-10':
config['cxx']['debug'] = '-ggdb3'
config['cxx']['optz_debug'] = '-Og'
elif cxxCompiler == 'icpc':
config['cxx']['debug'] = '-g'
config['cxx']['optz_debug'] = ''
if cxxCompiler == 'g++' or cxxCompiler == 'g++-10' or cxxCompiler == 'icpc':
config['cxx']['warn'] = warningFlags.split()
config['cxx']['verbose'] = '-v'
config['cxx']['64'] = '-m64'
Expand All @@ -913,8 +927,7 @@ def configureCompilerOptions(self):
# The "fastest-possible" option is new; see comments above.
config['cxx']['optz_fastest-possible'] = [ config['cxx']['optz_faster'], '-march=native' ] # -march=native instead of haswell

self.env.append_value('CXXFLAGS', '-fPIC'.split())
gxxCompileFlags='-std=c++17'
gxxCompileFlags='-fPIC -std=c++2a'
self.env.append_value('CXXFLAGS', gxxCompileFlags.split())

# DEFINES and LINKFLAGS will apply to both gcc and g++
Expand All @@ -929,22 +942,13 @@ def configureCompilerOptions(self):

self.env.append_value('LINKFLAGS', linkFlags.split())

if Options.options.debugging:
if cxxCompiler == 'g++':
config['cxx']['debug'] = '-ggdb3'
config['cxx']['optz_debug'] = '-Og'
elif cxxCompiler == 'icpc':
config['cxx']['debug'] = '-g'
config['cxx']['optz_debug'] = ''

if ccCompiler == 'gcc':
config['cc']['debug'] = '-ggdb3'
config['cc']['optz_debug'] = '-Og'
elif ccCompiler == 'icc':
config['cc']['debug'] = '-g'
config['cc']['optz_debug'] = ''

if ccCompiler == 'gcc' or ccCompiler == 'icc':
if ccCompiler == 'gcc' or ccCompiler == 'gcc-10':
config['cc']['debug'] = '-ggdb3'
config['cc']['optz_debug'] = '-Og'
elif ccCompiler == 'icc':
config['cc']['debug'] = '-g'
config['cc']['optz_debug'] = ''
if ccCompiler == 'gcc' or ccCompiler == 'gcc-10' or ccCompiler == 'icc':
config['cc']['warn'] = warningFlags.split()
config['cc']['verbose'] = '-v'
config['cc']['64'] = '-m64'
Expand Down Expand Up @@ -1024,7 +1028,7 @@ def configureCompilerOptions(self):
'WIN32 _USE_MATH_DEFINES NOMINMAX _CRT_SECURE_NO_WARNINGS WIN32_LEAN_AND_MEAN'.split()
flags = '/UUNICODE /U_UNICODE /EHs /GR'.split()

flags.append('/std:c++17')
flags.append('/std:c++20')

self.env.append_value('DEFINES', defines)
self.env.append_value('CXXFLAGS', flags)
Expand Down Expand Up @@ -1245,7 +1249,7 @@ def configure(self):
if Options.options._defs:
env.append_unique('DEFINES', Options.options._defs.split(','))
configureCompilerOptions(self)
ensureCpp17Support(self)
ensureCpp20Support(self)

env['PLATFORM'] = sys_platform

Expand Down
2 changes: 1 addition & 1 deletion build/config.guess
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ dummy=$tmp/dummy ;
tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
case $CC_FOR_BUILD,$HOST_CC,$CC in
,,) echo "int x;" > $dummy.c ;
for c in cc gcc c89 c99 ; do
for c in gcc-10 gcc c99 c89 cc; do
if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
CC_FOR_BUILD="$c"; break ;
fi ;
Expand Down
9 changes: 4 additions & 5 deletions modules/c++/coda-oss.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<ClInclude Include="coda_oss\include\coda_oss\optional.h" />
<ClInclude Include="coda_oss\include\coda_oss\optional_.h" />
<ClInclude Include="coda_oss\include\coda_oss\span.h" />
<ClInclude Include="coda_oss\include\coda_oss\span_.h" />
<ClInclude Include="coda_oss\include\coda_oss\string.h" />
<ClInclude Include="coda_oss\include\coda_oss\type_traits.h" />
<ClInclude Include="config\include\config\compiler_extensions.h" />
Expand Down Expand Up @@ -582,8 +581,8 @@
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<TreatWarningAsError>true</TreatWarningAsError>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<UseStandardPreprocessor>true</UseStandardPreprocessor>
</ClCompile>
<Link>
Expand Down Expand Up @@ -612,8 +611,8 @@
<ConformanceMode>true</ConformanceMode>
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<UseStandardPreprocessor>true</UseStandardPreprocessor>
</ClCompile>
<Link>
Expand Down
3 changes: 0 additions & 3 deletions modules/c++/coda-oss.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
<ClInclude Include="coda_oss\include\coda_oss\span.h">
<Filter>coda_oss</Filter>
</ClInclude>
<ClInclude Include="coda_oss\include\coda_oss\span_.h">
<Filter>coda_oss</Filter>
</ClInclude>
<ClInclude Include="coda_oss\include\coda_oss\string.h">
<Filter>coda_oss</Filter>
</ClInclude>
Expand Down
4 changes: 2 additions & 2 deletions modules/c++/coda_oss/include/coda_oss/CPlusPlus.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
#define CODA_OSS_cpp20 (CODA_OSS_cplusplus >= CODA_OSS_cplusplus20)
#define CODA_OSS_cpp23 (CODA_OSS_cplusplus >= CODA_OSS_cplusplus23)

#if !CODA_OSS_cpp17
#error "Must compile with C++17 or greater."
#if !CODA_OSS_cpp20
#error "Must compile with C++20 or greater."
#endif

// Get feature-testing macros: https://en.cppreference.com/w/cpp/feature_test
Expand Down
16 changes: 3 additions & 13 deletions modules/c++/coda_oss/include/coda_oss/bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,14 @@
#include <byteswap.h> // "These functions are GNU extensions."
#endif

#include<bit>
#include <type_traits>

#include "coda_oss/namespace_.h"
namespace coda_oss
{
// https://en.cppreference.com/w/cpp/types/endian
enum class endian
{
#ifdef _WIN32
little = 0,
big = 1,
native = little
#else
little = __ORDER_LITTLE_ENDIAN__,
big = __ORDER_BIG_ENDIAN__,
native = __BYTE_ORDER__
#endif
};
using std::endian;


// https://en.cppreference.com/w/cpp/numeric/byteswap
namespace details
Expand Down
2 changes: 1 addition & 1 deletion modules/c++/coda_oss/include/coda_oss/cstddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace coda_oss
{
using byte = std::byte;
using std::byte;
}

#endif // CODA_OSS_coda_oss_cstddef_h_INCLUDED_
2 changes: 1 addition & 1 deletion modules/c++/coda_oss/include/coda_oss/namespace_.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
* License along with this program; If not, http://www.gnu.org/licenses/.
*
*/
#pragma once
#ifndef CODA_OSS_coda_oss_namespace__h_INCLUDED_
#define CODA_OSS_coda_oss_namespace__h_INCLUDED_
#pragma once

namespace coda_oss
{
Expand Down
28 changes: 3 additions & 25 deletions modules/c++/coda_oss/include/coda_oss/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,12 @@
#ifndef CODA_OSS_coda_oss_optional_h_INCLUDED_
#define CODA_OSS_coda_oss_optional_h_INCLUDED_

#include "coda_oss/CPlusPlus.h"

// This logic needs to be here rather than <std/optional> so that `coda_oss::optional` will
// be the same as `std::optional`.
#ifndef CODA_OSS_HAVE_std_optional_
#define CODA_OSS_HAVE_std_optional_ 0 // assume no <optional>
#endif
#if CODA_OSS_cpp17 // C++17 for `__has_include()`
#if __has_include(<optional>) // __cpp_lib_optional not until C++20
#include <optional>
#undef CODA_OSS_HAVE_std_optional_
#define CODA_OSS_HAVE_std_optional_ 1 // provided by the implementation, probably C++17
#endif
#endif // CODA_OSS_cpp17

#if !CODA_OSS_HAVE_std_optional_
#include "coda_oss/optional_.h"
#endif
#include <optional>

namespace coda_oss
{
#if CODA_OSS_HAVE_std_optional_
using std::optional;
using std::make_optional;
#else
using details::optional;
using details::make_optional;
#endif
using std::optional;
using std::make_optional;
}

#endif // CODA_OSS_coda_oss_optional_h_INCLUDED_
Loading

0 comments on commit 1df497c

Please sign in to comment.