Skip to content

Commit

Permalink
s2: add to build
Browse files Browse the repository at this point in the history
  • Loading branch information
kiburtse committed Feb 1, 2023
1 parent 41edb32 commit ca39b9f
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 52 deletions.
23 changes: 18 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,33 @@ elseif(APPLE)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
endif()

function(add_cxx_flag_if_supported flag)
function(check_if_cxx_compiler_flag_supported flag out_var)
if(flag MATCHES "^-Wno-")
# Compilers ignore unknown -Wno-foo flags, so look for -Wfoo instead.
string(REPLACE "-Wno-" "-W" check_flag ${flag})
else()
set(check_flag ${flag})
endif()

check_cxx_compiler_flag(${check_flag} HAVE${check_flag})
if(HAVE${check_flag})
check_cxx_compiler_flag(${check_flag} ${out_var})
endfunction()

function(add_cxx_flag_if_supported flag)
check_if_cxx_compiler_flag_supported(${flag} HAVE_${flag})
if(HAVE_${flag})
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${flag}>)
endif()
endfunction()

function(add_target_option_if_supported target option_scope)
foreach(option ${ARGN})
check_if_cxx_compiler_flag_supported(${option} HAVE_${option})
if(HAVE_${option}})
target_compile_options(${target} ${option_scope}} ${option})
endif()
endforeach()
endfunction()

function(use_faster_linker)
# If a linker has already been set, don't override.
if ("${CMAKE_EXE_LINKER_FLAGS}" MATCHES "-fuse-ld=")
Expand Down Expand Up @@ -90,7 +103,7 @@ else()
if(ANDROID)
add_compile_options(-Wno-uninitialized)
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES ".*[Cc]lang")
# FIXME: Re-introduce -Wold-style-cast
# FIXME: Re-introduce -Wold-style-cast
add_compile_options(-Wunreachable-code -Wshorten-64-to-32 -Wconditional-uninitialized -Wextra-semi -Wno-nested-anon-types -Wdocumentation -Wthread-safety -Wthread-safety-negative -Wmissing-prototypes)
endif()

Expand Down Expand Up @@ -127,7 +140,7 @@ if(ANDROID)
# - `-fomit-frame-pointer` is inherited from NDK r10e.
# - On some architectures char is unsigned by default. Make it signed
# - Compile with -Oz in Release because on Android we favor code size over performance
#
#
add_compile_options(-fdata-sections -ffunction-sections -fomit-frame-pointer -fsigned-char -fstrict-aliasing -funwind-tables -no-canonical-prefixes $<$<CONFIG:Release>:-Oz>)
endif()

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_subdirectory(realm)
add_subdirectory(external/IntelRDFPMathLib20U2)
add_subdirectory(external/s2)

if(CMAKE_SYSTEM_NAME MATCHES "^Windows")
add_subdirectory(win32)
Expand Down
78 changes: 78 additions & 0 deletions src/external/s2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
cmake_minimum_required(VERSION 3.15)

project(s2geometry)

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../
${CMAKE_CURRENT_SOURCE_DIR}
)

set(S2_SOURCES
s1angle.cc
s2.cc
s2cellid.cc
s2latlng.cc
s1interval.cc
s2cap.cc
s2cell.cc
s2cellunion.cc
s2edgeindex.cc
s2edgeutil.cc
s2latlngrect.cc
s2loop.cc
s2pointregion.cc
s2polygon.cc
s2polygonbuilder.cc
s2polyline.cc
s2r2rect.cc
s2region.cc
s2regioncoverer.cc
s2regionintersection.cc
s2regionunion.cc
)

set(S2_BASE_SOURCES
base/int128.cc
base/logging.cc
base/stringprintf.cc
base/strtoint.cc
)

set(S2_STRINGS_SOURCES
strings/split.cc
strings/stringprintf.cc
strings/strutil.cc
)

set(S2_UTIL_CODING_SOURCES
util/coding/coder.cc
util/coding/varint.cc
)

set(S2_UTIL_MATH_SOURCES
util/math/mathutil.cc
)

add_library(s2geometry STATIC
${S2_SOURCES}
${S2_BASE_SOURCES}
${S2_STRINGS_SOURCES}
${S2_UTIL_CODING_SOURCES}
${S2_UTIL_MATH_SOURCES}
)

add_library(Realm::external::s2geometry ALIAS s2geometry)

target_compile_options(s2geometry PUBLIC
-Wno-macro-redefined
-Wno-deprecated-declarations
-Wno-unused-local-typedef
-Wno-unknown-pragmas
-Wno-shorten-64-to-32
-Wno-unused-parameter
-Wno-undefined-var-template
-Wno-missing-prototypes
-Wno-unused-const-variable
-Wno-unused-function
)

6 changes: 3 additions & 3 deletions src/external/s2/base/basictypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#ifndef _BASICTYPES_H_
#define _BASICTYPES_H_

#include "base/integral_types.h"
#include "base/casts.h"
#include "base/port.h"
#include "s2/base/integral_types.h"
#include "s2/base/casts.h"
#include "s2/base/port.h"

//
// Google-specific types
Expand Down
2 changes: 1 addition & 1 deletion src/external/s2/base/casts.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <limits.h> // for enumeration casts and tests
#include <typeinfo> // for enumeration casts and tests

#include "base/macros.h"
#include "s2/base/macros.h"


// Use implicit_cast as a safe version of static_cast or const_cast
Expand Down
44 changes: 44 additions & 0 deletions src/external/s2/base/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,48 @@ LogMessage::LogMessage(Severity severity, const char* file, int line)

LogMessage::~LogMessage() = default;

struct DefaultLogSink : LogMessageSink {
explicit DefaultLogSink(int verbosity) : DefaultLogSink(static_cast<LogMessage::Severity>(verbosity)) { }
explicit DefaultLogSink(LogMessage::Severity severity, const char* file = nullptr, int line = 0)
: _severity(severity) {
_os << "s2 ";
if (file)
_os << file << ":" << line << " ";
}

~DefaultLogSink() override {
std::cout << "[" << static_cast<int>(_severity) << "]: " << _os.str() << std::endl;
}

std::ostream& stream() override { return _os; }

LogMessage::Severity _severity;
std::ostringstream _os;
};

struct DefaultLoggingEnv : LoggingEnv {
DefaultLoggingEnv() = default;
~DefaultLoggingEnv() override {}

bool shouldVLog(int verbosity) override {
return static_cast<LogMessage::Severity>(verbosity) >= LogMessage::Severity::kWarning;
}

std::unique_ptr<LogMessageSink> makeSink(int verbosity) override {
return std::make_unique<DefaultLogSink>(verbosity);
}
std::unique_ptr<LogMessageSink> makeSink(LogMessage::Severity severity) override {
return std::make_unique<DefaultLogSink>(severity);
}
std::unique_ptr<LogMessageSink> makeSink(LogMessage::Severity severity,
const char* file, int line) override {
return std::make_unique<DefaultLogSink>(severity, file, line);
}
};

LoggingEnv& globalLoggingEnv() {
static DefaultLoggingEnv p;
return p;
}

} // namespace s2_env
2 changes: 1 addition & 1 deletion src/external/s2/base/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#define DCHECK_NE(x, y) DCHECK((x) != (y))
#endif

#include "base/port.h"
#include "s2/base/port.h"
#define INFO s2_env::LogMessage(s2_env::LogMessage::Severity::kInfo).stream()
#define WARN s2_env::LogMessage(s2_env::LogMessage::Severity::kWarning, __FILE__, __LINE__).stream()
#define FATAL s2_env::LogMessage(s2_env::LogMessage::Severity::kFatal, __FILE__, __LINE__).stream()
Expand Down
2 changes: 1 addition & 1 deletion src/external/s2/base/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef BASE_MACROS_H_
#define BASE_MACROS_H_

#include "base/definer.h" // For OS_WINDOWS
#include "s2/base/definer.h" // For OS_WINDOWS

#include <stddef.h> // For size_t

Expand Down
2 changes: 1 addition & 1 deletion src/external/s2/base/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef BASE_PORT_H_
#define BASE_PORT_H_

#include "base/definer.h"
#include "s2/base/definer.h"

#include <limits.h> // So we can set the bounds of our types
#include <string.h> // for memcpy()
Expand Down
16 changes: 10 additions & 6 deletions src/external/s2/s2.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#ifndef UTIL_GEOMETRY_S2_H_
#define UTIL_GEOMETRY_S2_H_

#ifndef DEBUG_MODE
#define DEBUG_MODE false
#endif

#include <algorithm>
using std::min;
using std::max;
Expand All @@ -19,12 +23,12 @@ using std::reverse;
#include "hash.h"

// To have template struct hash<T> defined
#include "third_party/s2/base/basictypes.h"
#include "third_party/s2/base/logging.h"
#include "third_party/s2/base/macros.h"
#include "third_party/s2/base/port.h" // for HASH_NAMESPACE_DECLARATION_START
#include "third_party/s2/util/math/vector3-inl.h"
#include "third_party/s2/util/math/matrix3x3.h"
#include "s2/base/basictypes.h"
#include "s2/base/logging.h"
#include "s2/base/macros.h"
#include "s2/base/port.h" // for HASH_NAMESPACE_DECLARATION_START
#include "s2/util/math/vector3-inl.h"
#include "s2/util/math/matrix3x3.h"


// An S2Point represents a point on the unit sphere as a 3D vector. Usually
Expand Down
3 changes: 1 addition & 2 deletions src/external/s2/s2polygonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ using std::make_pair;
#include <vector>
using std::vector;

#include <boost/scoped_ptr.hpp>
using boost::scoped_ptr;
#include "base/scoped_ptr.h"
#include "base/basictypes.h"
#include "s2.h"
#include "s1angle.h"
Expand Down
4 changes: 1 addition & 3 deletions src/external/s2/s2regioncoverer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ using std::make_pair;
using std::vector;

#include "base/macros.h"
#include <boost/scoped_ptr.hpp>
using boost::scoped_ptr;
//#include "base/scoped_ptr.h"
#include "base/scoped_ptr.h"
#include "s2cell.h"
#include "s2cellid.h"

Expand Down
2 changes: 1 addition & 1 deletion src/external/s2/util/math/mathlimits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ DEF_UNSIGNED_INT_LIMITS(unsigned long int)

DEF_FP_LIMITS(float, FLT)
DEF_FP_LIMITS(double, DBL)
DEF_FP_LIMITS(long double, LDBL);
DEF_FP_LIMITS(long double, LDBL)

#undef DEF_COMMON_LIMITS
#undef DEF_SIGNED_INT_LIMITS
Expand Down
4 changes: 2 additions & 2 deletions src/external/s2/util/math/mathutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ using std::reverse;
#include <vector>
using std::vector;

#include "base/basictypes.h"
#include "base/logging.h"
#include "s2/base/basictypes.h"
#include "s2/base/logging.h"

// Returns the sign of x:
// -1 if x < 0,
Expand Down
16 changes: 8 additions & 8 deletions src/external/s2/util/math/vector2-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
#ifndef UTIL_MATH_VECTOR2_INL_H__
#define UTIL_MATH_VECTOR2_INL_H__

#include "util/math/vector2.h"
#include "s2/util/math/vector2.h"

#include <math.h>
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/template_util.h"
#include "base/type_traits.h"
#include "util/math/mathutil.h"
#include "util/math/vector3.h"
#include "util/math/vector4.h"
#include "s2/base/basictypes.h"
#include "s2/base/logging.h"
#include "s2/base/template_util.h"
#include "s2/base/type_traits.h"
#include "s2/util/math/mathutil.h"
#include "s2/util/math/vector3.h"
#include "s2/util/math/vector4.h"

template <typename VType>
Vector2<VType>::Vector2() {
Expand Down
2 changes: 1 addition & 1 deletion src/external/s2/util/math/vector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using std::ostream;
using std::cout;
using std::endl;
// NOLINT(readability/streams)
#include "base/basictypes.h"
#include "s2/base/basictypes.h"

template <typename VType> class Vector2;

Expand Down
16 changes: 8 additions & 8 deletions src/external/s2/util/math/vector3-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#ifndef UTIL_MATH_VECTOR3_INL_H__
#define UTIL_MATH_VECTOR3_INL_H__

#include "util/math/vector3.h"
#include "s2/util/math/vector3.h"

#include <algorithm>
using std::min;
Expand All @@ -35,13 +35,13 @@ using std::swap;
using std::reverse;

#include <math.h>
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/template_util.h"
#include "base/type_traits.h"
#include "util/math/mathutil.h"
#include "util/math/vector2.h"
#include "util/math/vector4.h"
#include "s2/base/basictypes.h"
#include "s2/base/logging.h"
#include "s2/base/template_util.h"
#include "s2/base/type_traits.h"
#include "s2/util/math/mathutil.h"
#include "s2/util/math/vector2.h"
#include "s2/util/math/vector4.h"

template <typename VType>
Vector3<VType>::Vector3() {
Expand Down
2 changes: 1 addition & 1 deletion src/external/s2/util/math/vector3.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using std::ostream;
using std::cout;
using std::endl;
// NOLINT(readability/streams)
#include "base/basictypes.h"
#include "s2/base/basictypes.h"

template <typename VType> class Vector3;
// TODO(user): Look into creating conversion operators to remove the
Expand Down
Loading

0 comments on commit ca39b9f

Please sign in to comment.