diff --git a/CMake/FindFlatBuffers.cmake b/CMake/FindFlatBuffers.cmake index 0a54e2a200c..efb0ae82214 100644 --- a/CMake/FindFlatBuffers.cmake +++ b/CMake/FindFlatBuffers.cmake @@ -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) diff --git a/CMake/Findflatbuffers.cmake b/CMake/Findflatbuffers.cmake deleted file mode 100644 index 4733d550641..00000000000 --- a/CMake/Findflatbuffers.cmake +++ /dev/null @@ -1,52 +0,0 @@ -# Find the flatbuffers schema compiler -# Copyright 2014 Stefan.Eilemann@epfl.ch -# Output Variables: -# * FLATC_EXECUTABLE the flatc compiler executable -# * FLATBUFFERS_FOUND -# -# Provides: -# * FLATC_TARGET(Name ) creates the C++ headers for the given flatbuffer -# schema files. Returns the header files in ${Name}_OUTPUTS -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -find_program(FLATC_EXECUTABLE NAMES flatc) -find_path(FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(flatbuffers DEFAULT_MSG FLATC_EXECUTABLE - FLATBUFFERS_INCLUDE_DIR) - -if(FLATBUFFERS_FOUND) - function(FLATC_TARGET Name) - set(FLATC_OUTPUTS) - foreach(FILE ${ARGN}) - get_filename_component(FLATC_OUTPUT ${FILE} NAME_WE) - set(FLATC_OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/${FLATC_OUTPUT}_generated.h") - list(APPEND FLATC_OUTPUTS ${FLATC_OUTPUT}) - - add_custom_command(OUTPUT ${FLATC_OUTPUT} - COMMAND ${FLATC_EXECUTABLE} - ARGS -c -o "${CMAKE_CURRENT_BINARY_DIR}/" ${FILE} - COMMENT "Building C++ header for ${FILE}" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - endforeach() - set(${Name}_OUTPUTS ${FLATC_OUTPUTS} PARENT_SCOPE) - endfunction() - - set(FLATBUFFERS_INCLUDE_DIRS ${FLATBUFFERS_INCLUDE_DIR}) - include_directories(${CMAKE_BINARY_DIR}) -else() - set(FLATBUFFERS_INCLUDE_DIR) -endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c88beffa08..b5c88ee34a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() @@ -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") diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index f3caf58c6a2..548486b1a64 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -32,7 +32,7 @@ #include #include -#ifdef FLATBUFFERS_USE_BOOST +#ifdef FLATBUFFERS_USE_CXX03_STDLIB # include # include namespace flatbufferstd = boost; diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 4e0bc3f69dd..c5733ad1963 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -140,7 +140,11 @@ template 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; @@ -386,4 +390,3 @@ extern bool GenerateJava(const Parser &parser, } // namespace flatbuffers #endif // FLATBUFFERS_IDL_H_ - diff --git a/src/flatc.cpp b/src/flatc.cpp index 2329a5dee16..afa33e7aaa9 100755 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -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; diff --git a/tests/test.cpp b/tests/test.cpp index edb971aab9b..72fb4b4c7e9 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -20,7 +20,7 @@ #include "monster_test_generated.h" -#include +#include using namespace MyGame::Example; @@ -503,7 +503,7 @@ void ScientificTest() { auto root = flatbuffers::GetRoot(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() { @@ -557,4 +557,3 @@ int main(int /*argc*/, const char * /*argv*/[]) { return 1; } } -