summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Bailey <derekbailey@google.com>2023-05-09 20:33:54 -0700
committerGitHub <noreply@github.com>2023-05-09 20:33:54 -0700
commit76f5e9816a1c3acba81c1c5c8d5e256c6e21edc5 (patch)
treea90afa72f411d2c1cd5b2ef2db9e746a433ea613
parent368428cb94dd0ae3fe5bc01080e9252579b98605 (diff)
downloadflatbuffers-76f5e9816a1c3acba81c1c5c8d5e256c6e21edc5.tar.gz
flatbuffers-76f5e9816a1c3acba81c1c5c8d5e256c6e21edc5.tar.bz2
flatbuffers-76f5e9816a1c3acba81c1c5c8d5e256c6e21edc5.zip
fix out-of-source builds with cmake (#7946)
-rw-r--r--.github/workflows/build.yml22
-rw-r--r--CMakeLists.txt7
-rw-r--r--tests/BUILD.bazel1
-rw-r--r--tests/test.cpp7
4 files changed, 28 insertions, 9 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index cc2a614f..36e6a3bd 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -76,6 +76,28 @@ jobs:
- name: build
run: make -j
+ build-linux-out-of-source:
+ name: Build Linux with out-of-source build location
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - name: make build directory
+ run: mkdir build
+ - name: cmake
+ working-directory: build
+ run: >
+ CXX=clang++-12 cmake .. -G "Unix Makefiles" -DFLATBUFFERS_STRICT_MODE=ON
+ -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_CPP_STD=17
+ - name: build
+ working-directory: build
+ run: make -j
+ - name: test
+ working-directory: build
+ run: pwd && ./flattests
+ - name: test C++17
+ working-directory: build
+ run: ./flattests_cpp17
+
build-linux-cpp-std:
name: Build Linux C++
runs-on: ubuntu-latest
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d3115d88..3b0254b0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -516,10 +516,12 @@ function(compile_schema_for_samples SRC_FBS OPT)
endfunction()
if(FLATBUFFERS_BUILD_TESTS)
- include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
add_executable(flattests ${FlatBuffers_Tests_SRCS})
target_link_libraries(flattests PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
- target_include_directories(flattests PUBLIC src)
+ target_include_directories(flattests PUBLIC src tests)
+
+ # Have tests load data from the source directory, not the build directory.
+ add_definitions(-DFLATBUFFERS_TEST_PATH_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/)
# The flattest target needs some generated files
SET(FLATC_OPT --cpp --gen-mutable --gen-object-api --reflect-names)
@@ -552,6 +554,7 @@ if(FLATBUFFERS_BUILD_TESTS)
if(FLATBUFFERS_BUILD_CPP17)
add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
target_link_libraries(flattests_cpp17 PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
+ target_include_directories(flattests_cpp17 PUBLIC src tests)
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17) # requires cmake 3.8
if(FLATBUFFERS_CODE_SANITIZE)
diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel
index 923890f6..c723eb81 100644
--- a/tests/BUILD.bazel
+++ b/tests/BUILD.bazel
@@ -71,7 +71,6 @@ cc_test(
],
copts = [
"-DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE",
- "-DBAZEL_TEST_DATA_PATH",
],
data = [
":alignment_test.fbs",
diff --git a/tests/test.cpp b/tests/test.cpp
index ec60251a..49018d1b 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -1670,12 +1670,7 @@ int FlatBufferTests(const std::string &tests_data_path) {
} // namespace flatbuffers
int main(int argc, const char *argv[]) {
- std::string tests_data_path =
-#ifdef BAZEL_TEST_DATA_PATH
- "../com_github_google_flatbuffers/tests/";
-#else
- "tests/";
-#endif
+ std::string tests_data_path = "tests/";
for (int argi = 1; argi < argc; argi++) {
std::string arg = argv[argi];