Skip to content

Commit

Permalink
Squashed 'externals/coda-oss/' changes from 710754a00..a357c55b9
Browse files Browse the repository at this point in the history
a357c55b9 Merge branch 'cpp17' into cpp20
17696426f Merge branch 'cpp17' into cpp20
5f3f99143 build with C++20
10756ea88 Merge branch 'cpp17' into cpp20
b028a625f Merge branch 'cpp17' into cpp20
78e40ace3 Merge branch 'cpp17' into cpp20
0fafe39ea suppress C++20-only warning
d89913d55 -std=c++20 only for modules/c++
b3a55d3ed restore C++20
c17aab612 restore C++20
894afe57b Merge branch 'cpp17' into cpp20
9840e6906 Merge branch 'cpp17' into cpp20
9babe53d4 restore C++20
15337cebc Merge branch 'cpp17' into cpp20
11e472854 Merge branch 'cpp17' into cpp20
e71539d27 C++20 has <numbers>
8d99186db Merge branch 'cpp17' into cpp20
61ba2a2a8 Merge branch 'cpp17' into cpp20
b0be9762c Merge branch 'cpp17' into cpp20
679725800 Merge branch 'cpp17' into cpp20
b672c0ab8 Merge branch 'cpp17' into cpp20
18d4c9c5c start over again from 'cpp17'

git-subtree-dir: externals/coda-oss
git-subtree-split: a357c55b98ca718cc541473f5b6b6a329044e031
  • Loading branch information
J. Daniel Smith committed Jul 24, 2023
1 parent 629dc82 commit df247a7
Show file tree
Hide file tree
Showing 29 changed files with 110 additions and 862 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):
'_LARGEFILE_SOURCE WIN32 _USE_MATH_DEFINES NOMINMAX 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
4 changes: 2 additions & 2 deletions modules/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(TARGET_LANGUAGE c++)

if (MSVC)
add_compile_options(/std:c++17)
add_compile_options(/std:c++20)

# turn on maximum warnings
# By default, there is a /W3 on the command-line from somewhere (?); adding
Expand All @@ -10,7 +10,7 @@ if (MSVC)
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # /Wall

elseif (UNIX)
add_compile_options(-std=c++17)
add_compile_options(-std=c++20)

# https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
add_compile_options(-Werror) # Make all warnings into errors
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 @@ -23,7 +23,6 @@
<ClInclude Include="coda_oss\include\coda_oss\numbers.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 @@ -593,8 +592,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 @@ -623,8 +622,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 @@ -70,8 +70,8 @@
#define CODA_OSS_cpp20 (CODA_OSS_cplusplus >= 202002L)
#define CODA_OSS_cpp23 (CODA_OSS_cplusplus >= 202302L)

#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

#endif // CODA_OSS_coda_oss_CPlusPlus_h_INCLUDED_
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
50 changes: 2 additions & 48 deletions modules/c++/coda_oss/include/coda_oss/numbers.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,62 +22,16 @@
#ifndef CODA_OSS_coda_oss_numbers_h_INCLUDED_
#define CODA_OSS_coda_oss_numbers_h_INCLUDED_

#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES // get M_PI, etc.
#endif
#include <math.h>
/*
#define M_E 2.71828182845904523536 // e
#define M_LOG2E 1.44269504088896340736 // log2(e)
#define M_LOG10E 0.434294481903251827651 // log10(e)
#define M_LN2 0.693147180559945309417 // ln(2)
#define M_LN10 2.30258509299404568402 // ln(10)
#define M_PI 3.14159265358979323846 // pi
#define M_PI_2 1.57079632679489661923 // pi/2
#define M_PI_4 0.785398163397448309616 // pi/4
#define M_1_PI 0.318309886183790671538 // 1/pi
#define M_2_PI 0.636619772367581343076 // 2/pi
#define M_2_SQRTPI 1.12837916709551257390 // 2/sqrt(pi)
#define M_SQRT2 1.41421356237309504880 // sqrt(2)
#define M_SQRT1_2 0.707106781186547524401 // 1/sqrt(2)
*/
#include <numbers>

namespace coda_oss
{

namespace numbers
{
// https://en.cppreference.com/w/cpp/header/numbers

template <typename T> constexpr T e_v = static_cast<T>(M_E);
template <typename T> constexpr T log2e_v = static_cast<T>(M_LOG2E);
template <typename T> constexpr T log10e_v = static_cast<T>(M_LOG10E);
template <typename T> constexpr T pi_v = static_cast<T>(M_PI);
template <typename T> constexpr T inv_pi_v = static_cast<T>(M_1_PI);
//template <typename T> constexpr T inv_sqrtpi_v = static_cast<T>();
template <typename T> constexpr T ln2_v = static_cast<T>(M_LN2);
template <typename T> constexpr T ln10_v = static_cast<T>(M_LN10);
template <typename T> constexpr T sqrt2_v = static_cast<T>(M_SQRT2);
//template <typename T> constexpr T sqrt3_v = static_cast<T>();
//template <typename T> constexpr T inv_sqrt3_v = static_cast<T>();
//template <typename T> constexpr T egamma_v = static_cast<T>();
//template <typename T> constexpr T phi_v = static_cast<T>();
using namespace std::numbers;

constexpr double e = e_v<double>;
constexpr double log2e = log2e_v<double>;
constexpr double log10e = log10e_v<double>;
constexpr double pi = pi_v<double>;
constexpr double inv_pi = inv_pi_v<double>;
//constexpr double inv_sqrtpi = inv_sqrtpi_v<double>;
constexpr double ln2 = ln2_v<double>;
constexpr double ln10 = ln10_v<double>;
constexpr double sqrt2 = sqrt2_v<double>;
//constexpr double sqrt3 = sqrt3_v<double>;
//constexpr double inv_sqrt3 = inv_sqrt3_v<double>;
//constexpr double egamma = egamma_v<double>;
//constexpr double phi = phi_v<double>;
}

}

#endif // CODA_OSS_coda_oss_numbers_h_INCLUDED_
Loading

0 comments on commit df247a7

Please sign in to comment.