flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

Including Flatbuffer in existing CMake project, test fails.

Open Jiboxiake opened this issue 3 years ago • 3 comments

Basically I installed flatbuffer using git clone https://github.com/google/flatbuffers.git into the root directory of my CMake project and make my CMakeList.txt like the following:

cmake_minimum_required(VERSION 3.20)
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif()
#set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(FLATBUFFERS_SRC_DIR ./flatbuffers)
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
project(road_network_routing)
SET (BOOST_ROOT "/scratch1/zhou822/old_boost/boost_1_79_0")
#set(Boost_INCLUDE_DIR "/scratch1/zhou822/old_boost/boost_1_79_0")
#set(Boost_LIBRARY_DIR "/scratch1/zhou822/old_boost/boost_1_79_0/libs")
# Add FlatBuffers directly to our build. This defines the `flatbuffers` target.
add_subdirectory(${FLATBUFFERS_SRC_DIR}
        ${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-build
        EXCLUDE_FROM_ALL)

find_package(Boost 1.79.0 COMPONENTS system filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIR})
add_executable(road_network_routing main.cpp Dijkstra/Dijkstra.cpp Graph_Load/Loader.h Graph_Load/Loader.cpp Graph_storage/Graph.h Graph_storage/Graph.cpp Global.h Query/QueryResult.h Dijkstra/Dijkstra.h Contraction_Hierarchies/Contraction_Hierarchies.h Contraction_Hierarchies/Contraction_Hierarchies.cpp Test/CH_Test.hpp Morton/Morton.hpp Morton/Morton.cpp Quadtree/Quadtree.hpp Quadtree/Quadtree.cpp Quadtree/Diameter_preprocessing.hpp Quadtree/Diameter_preprocessing.cpp DO_flatbuffer/DO_Flatbuffer.hpp)
target_link_libraries( road_network_routing ${Boost_LIBRARIES} flatbuffers )

Then when I run the flattests directly from IDE, it shows:

/scratch1/zhou822/road_network_routing/cmake-build-debug/flatbuffers-build/flattests flattests: /scratch1/zhou822/road_network_routing/flatbuffers/tests/test_assert.cpp:24: void TestFail(const char*, const char*, const char*, const char*, int, const char*): Assertion `0' failed. EXPECTED: "//../../../flatbuffers/tests/monster_test.fbs" VALUE: "//monster_test.fbs" TEST FAILED: /scratch1/zhou822/road_network_routing/flatbuffers/tests/reflection_test.cpp:34, 'root_table->declaration_file()->c_str()' != '"//monster_test.fbs"' in

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

I haven't tested in my own implementation yet, I mean if this is a negligible issue I'm happy to move forward. I did see #6838 but I'm using CMake and unfortunately do not have ctest on the server machine I'm using.

Jiboxiake avatar Nov 15 '22 16:11 Jiboxiake

I think if you turn off FLATBUFFERS_BUILD_TESTS, it will work for you

enum-class avatar Nov 17 '22 05:11 enum-class

You can chane --bfbs-filenames in compile_flatbuffers_schema_to_binary function in CMakeLists.txt to --bfbs-filenames "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS_DIR}" and then it will work

enum-class avatar Nov 17 '22 07:11 enum-class

Thank you!

Jiboxiake avatar Nov 17 '22 18:11 Jiboxiake

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar May 18 '23 20:05 github-actions[bot]

This issue was automatically closed due to no activity for 6 months plus the 14 day notice period.

github-actions[bot] avatar Jun 02 '23 20:06 github-actions[bot]