Skip to content

Commit

Permalink
Fix build against C++03 stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Eilemann authored and Stefan Eilemann committed Aug 27, 2014
1 parent eb1e85d commit 9e3c669
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 62 deletions.
1 change: 1 addition & 0 deletions CMake/FindFlatBuffers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ if(FLATBUFFERS_FOUND)
COMMAND ${FLATBUFFERS_FLATC_EXECUTABLE}
ARGS -c -o "${CMAKE_CURRENT_BINARY_DIR}/" ${FILE}
COMMENT "Building C++ header for ${FILE}"
DEPENDS ${FILE} ${FLATBUFFERS_FLATC_EXECUTABLE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endforeach()
set(${Name}_OUTPUTS ${FLATC_OUTPUTS} PARENT_SCOPE)
Expand Down
52 changes: 0 additions & 52 deletions CMake/Findflatbuffers.cmake

This file was deleted.

9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ project(FlatBuffers)

# NOTE: Code coverage only works on Linux & OSX.
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
option(FLATBUFFERS_USE_BOOST
option(FLATBUFFERS_USE_CXX03_STDLIB
"Use boost classes to enable C++03 stdlib compatibility" OFF)

if(FLATBUFFERS_USE_BOOST)
if(FLATBUFFERS_USE_CXX03_STDLIB)
find_package(Boost 1.41.0 REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
endif()
Expand Down Expand Up @@ -65,7 +65,10 @@ set(CMAKE_BUILD_TYPE Debug)

if(APPLE)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -Wall -pedantic -Werror -Wextra")
"${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic -Werror -Wextra")
if(NOT FLATBUFFERS_USE_CXX03_STDLIB)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
elseif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra")
Expand Down
2 changes: 1 addition & 1 deletion include/flatbuffers/flatbuffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <vector>
#include <algorithm>

#ifdef FLATBUFFERS_USE_BOOST
#ifdef FLATBUFFERS_USE_CXX03_STDLIB
# include <boost/type_traits/conditional.hpp>
# include <boost/move/move.hpp>
namespace flatbufferstd = boost;
Expand Down
5 changes: 4 additions & 1 deletion include/flatbuffers/idl.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ template<typename T> class SymbolTable {
}

bool Add(const std::string &name, T *e) {
#ifdef FLATBUFFERS_USE_CXX03_STDLIB
vec.push_back(e);
#else
vec.emplace_back(e);
#endif
auto it = dict.find(name);
if (it != dict.end()) return true;
dict[name] = e;
Expand Down Expand Up @@ -386,4 +390,3 @@ extern bool GenerateJava(const Parser &parser,
} // namespace flatbuffers

#endif // FLATBUFFERS_IDL_H_

4 changes: 2 additions & 2 deletions src/flatc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ int main(int argc, const char *argv[]) {
case 'o':
if (++i >= argc) Error("missing path following", arg, true);
output_path = argv[i];
if (!(output_path.back() == flatbuffers::kPathSeparator ||
output_path.back() == flatbuffers::kPosixPathSeparator)) {
if (!(*output_path.rbegin() == flatbuffers::kPathSeparator ||
*output_path.rbegin() == flatbuffers::kPosixPathSeparator)) {
output_path += flatbuffers::kPathSeparator;
}
break;
Expand Down
5 changes: 2 additions & 3 deletions tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "monster_test_generated.h"

#include <random>
#include <cmath>

using namespace MyGame::Example;

Expand Down Expand Up @@ -503,7 +503,7 @@ void ScientificTest() {
auto root = flatbuffers::GetRoot<float>(parser.builder_.GetBufferPointer());
// root will point to the table, which is a 32bit vtable offset followed
// by a float:
TEST_EQ(fabs(root[1] - 3.14159) < 0.001, true);
TEST_EQ(::fabs(root[1] - 3.14159) < 0.001, true);
}

void EnumStringsTest() {
Expand Down Expand Up @@ -557,4 +557,3 @@ int main(int /*argc*/, const char * /*argv*/[]) {
return 1;
}
}

0 comments on commit 9e3c669

Please sign in to comment.