Skip to content

Commit 305bb2b

Browse files
authored
[Tidy] Flatbuffer schema updates (#94)
- Segregated flatbuffer target.fbs to target.fbs and path.fbs - Shifted to buildcc/schema directory instead of buildcc/lib/target/fbs directory
1 parent c2f16f8 commit 305bb2b

File tree

8 files changed

+52
-30
lines changed

8 files changed

+52
-30
lines changed

buildcc/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
set(BUILDCC_INSTALL_LIB_PREFIX "lib/cmake")
33
set(BUILDCC_INSTALL_HEADER_PREFIX "include/buildcc")
44

5+
# Flatbuffers schema
6+
add_subdirectory(schema)
7+
58
if(${BUILDCC_BUILD_AS_SINGLE_LIB})
69
add_library(buildcc STATIC
710
buildcc.h

buildcc/lib/target/CMakeLists.txt

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ if (${TESTING})
66
add_subdirectory(test/target)
77
endif()
88

9-
# Target flatc generator
10-
include(cmake/fbs_gen.cmake)
11-
129
# Target lib
1310
include(cmake/target.cmake)
1411

buildcc/lib/target/cmake/fbs_gen.cmake

-19
This file was deleted.

buildcc/lib/target/cmake/mock_target.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ add_library(mock_target STATIC
1818
target_include_directories(mock_target PUBLIC
1919
${CMAKE_CURRENT_SOURCE_DIR}/include
2020
${CMAKE_CURRENT_SOURCE_DIR}/mock
21-
${CMAKE_CURRENT_BINARY_DIR}/generated
21+
${SCHEMA_BUILD_DIR}
2222
)
2323

2424
target_compile_options(mock_target PUBLIC ${TEST_COMPILE_FLAGS} ${BUILD_COMPILE_FLAGS})

buildcc/lib/target/cmake/target.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if(${BUILDCC_BUILD_AS_SINGLE_LIB})
3232
$<INSTALL_INTERFACE:${BUILDCC_INSTALL_HEADER_PREFIX}>
3333
)
3434
target_include_directories(buildcc PRIVATE
35-
${CMAKE_CURRENT_BINARY_DIR}/generated
35+
${SCHEMA_BUILD_DIR}
3636
)
3737
add_dependencies(buildcc fbs_to_header)
3838
endif()
@@ -57,7 +57,7 @@ if(${BUILDCC_BUILD_AS_INTERFACE})
5757
)
5858

5959
target_include_directories(target PRIVATE
60-
${CMAKE_CURRENT_BINARY_DIR}/generated
60+
${SCHEMA_BUILD_DIR}
6161
)
6262
target_compile_options(target PRIVATE ${BUILD_COMPILE_FLAGS})
6363
target_link_options(target PRIVATE ${BUILD_LINK_FLAGS})

buildcc/schema/CMakeLists.txt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generate files
2+
set(SCHEMA_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated CACHE PATH "Generate path of flatbuffer schema")
3+
4+
set(FBS_FILES
5+
${CMAKE_CURRENT_SOURCE_DIR}/path.fbs
6+
${CMAKE_CURRENT_SOURCE_DIR}/target.fbs
7+
)
8+
set(FBS_GEN_FILES
9+
${SCHEMA_BUILD_DIR}/path_generated.h
10+
${SCHEMA_BUILD_DIR}/target_generated.h
11+
)
12+
set(FBS_GEN_OPTIONS
13+
-I ${CMAKE_CURRENT_SOURCE_DIR}
14+
--gen-object-api
15+
)
16+
17+
add_custom_command(OUTPUT ${FBS_GEN_FILES}
18+
COMMAND flatc -o ${SCHEMA_BUILD_DIR} ${FBS_GEN_OPTIONS} --cpp ${FBS_FILES}
19+
DEPENDS flatc ${FBS_FILES}
20+
)
21+
22+
add_custom_target(fbs_to_header
23+
DEPENDS ${FBS_GEN_FILES}
24+
)

buildcc/schema/path.fbs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2021 Niket Naidu. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace schema.internal;
16+
17+
table Path {
18+
pathname:string (key);
19+
last_write_timestamp:uint64;
20+
}

buildcc/lib/target/fbs/target.fbs buildcc/schema/target.fbs

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
namespace schema.internal;
15+
include "path.fbs";
1616

17-
table Path {
18-
pathname:string (key);
19-
last_write_timestamp:uint64;
20-
}
17+
namespace schema.internal;
2118

2219
enum TargetType : byte {
2320
Executable,

0 commit comments

Comments
 (0)