Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmake:]fix the dependence to avoid generate files every time, even though no changed #258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions samples/monster/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,32 @@ set(FBS_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

include_directories("${GEN_DIR}" "${INC_DIR}")

add_custom_target(gen_monster_fbs ALL)
file(GLOB FBS_FS ${FBS_DIR}/*.fbs)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_builder.h"
OUTPUT_VARIABLE FBS_B_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_reader.h"
OUTPUT_VARIABLE FBS_R_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_verifier.h"
OUTPUT_VARIABLE FBS_V_HS
)

list(APPEND FBS_R_HS ${GEN_DIR}/flatbuffers_common_reader.h)
list(APPEND FBS_B_HS ${GEN_DIR}/flatbuffers_common_builder.h)

add_custom_command (
TARGET gen_monster_fbs
OUTPUT ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS}
COMMAND ${CMAKE_COMMAND} -E make_directory "${GEN_DIR}"
COMMAND flatcc_cli -a -o "${GEN_DIR}" "${FBS_DIR}/monster.fbs"
DEPENDS flatcc_cli "${FBS_DIR}/monster.fbs"
DEPENDS flatcc_cli "${FBS_FS}"
COMMENT "Generate monster fbs headers"
)
add_executable(monster monster.c)
add_dependencies(monster gen_monster_fbs)

add_executable(monster monster.c ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS})
target_link_libraries(monster flatccrt)

if (FLATCC_TEST)
Expand Down
16 changes: 11 additions & 5 deletions samples/reflection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ set(FBS_DIR "${PROJECT_SOURCE_DIR}/samples/monster")

include_directories("${GEN_DIR}" "${INC_DIR}")

add_custom_target(gen_monster_bfbs ALL)
file(GLOB FBS_FS ${FBS_DIR}/*.fbs)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1.bfbs"
OUTPUT_VARIABLE FBS_BFBS
)

add_custom_command (
TARGET gen_monster_bfbs
OUTPUT ${FBS_BFBS}
COMMAND ${CMAKE_COMMAND} -E make_directory "${GEN_DIR}"
COMMAND flatcc_cli --schema -o "${GEN_DIR}" "${FBS_DIR}/monster.fbs"
DEPENDS flatcc_cli "${FBS_DIR}/monster.fbs"
DEPENDS flatcc_cli "${FBS_FS}"
COMMENT "Generate bfbs2json fbs headers"
)
add_executable(bfbs2json bfbs2json.c)
add_dependencies(bfbs2json gen_monster_bfbs)

add_executable(bfbs2json bfbs2json.c ${FBS_BFBS})
target_link_libraries(bfbs2json flatccrt)

if (FLATCC_TEST)
Expand Down
27 changes: 22 additions & 5 deletions test/emit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,32 @@ set(FBS_DIR "${PROJECT_SOURCE_DIR}/test/emit_test")

include_directories("${GEN_DIR}" "${INC_DIR}")

add_custom_target(gen_emit_test ALL)
file(GLOB FBS_FS ${FBS_DIR}/*.fbs)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_builder.h"
OUTPUT_VARIABLE FBS_B_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_reader.h"
OUTPUT_VARIABLE FBS_R_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_verifier.h"
OUTPUT_VARIABLE FBS_V_HS
)

list(APPEND FBS_R_HS ${GEN_DIR}/flatbuffers_common_reader.h)
list(APPEND FBS_B_HS ${GEN_DIR}/flatbuffers_common_builder.h)

add_custom_command (
TARGET gen_emit_test
OUTPUT ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS}
COMMAND ${CMAKE_COMMAND} -E make_directory "${GEN_DIR}"
COMMAND flatcc_cli -a -o "${GEN_DIR}" "${FBS_DIR}/emit_test.fbs"
DEPENDS flatcc_cli "${FBS}"
DEPENDS flatcc_cli "${FBS_FS}"
COMMENT "Generate emit_test fbs headers"
)
add_executable(emit_test emit_test.c)
add_dependencies(emit_test gen_emit_test)

add_executable(emit_test emit_test.c ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS})
target_link_libraries(emit_test flatccrt)

add_test(emit_test emit_test${CMAKE_EXECUTABLE_SUFFIX})
27 changes: 22 additions & 5 deletions test/flatc_compat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,33 @@ set(FBS_DIR "${PROJECT_SOURCE_DIR}/test/monster_test")

include_directories("${GEN_DIR}" "${INC_DIR}")

add_custom_target(gen_flatc_compat ALL)
file(GLOB FBS_FS ${FBS_DIR}/*.fbs)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_builder.h"
OUTPUT_VARIABLE FBS_B_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_reader.h"
OUTPUT_VARIABLE FBS_R_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_verifier.h"
OUTPUT_VARIABLE FBS_V_HS
)

list(APPEND FBS_R_HS ${GEN_DIR}/flatbuffers_common_reader.h)
list(APPEND FBS_B_HS ${GEN_DIR}/flatbuffers_common_builder.h)

add_custom_command (
TARGET gen_flatc_compat
OUTPUT ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS}
COMMAND ${CMAKE_COMMAND} -E make_directory "${GEN_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/monsterdata_test.mon" ${CMAKE_CURRENT_BINARY_DIR}
COMMAND flatcc_cli -a -o "${GEN_DIR}" "${FBS_DIR}/monster_test.fbs"
DEPENDS flatcc_cli "${FBS_DIR}/monster_test.fbs" "${FBS_DIR}/include_test1.fbs" "${FBS_DIR}/include_test2.fbs"
DEPENDS flatcc_cli "${FBS_FS}"
COMMENT "Generate flatc_compat fbs headers"
)
add_executable(flatc_compat flatc_compat.c)
add_dependencies(flatc_compat gen_flatc_compat)

add_executable(flatc_compat flatc_compat.c ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS})
target_link_libraries(flatc_compat flatccrt)

add_test(flatc_compat flatc_compat${CMAKE_EXECUTABLE_SUFFIX})
34 changes: 31 additions & 3 deletions test/json_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,42 @@ set(DATA_SRC "${PROJECT_SOURCE_DIR}/test/flatc_compat")

include_directories("${GEN_DIR}" "${INC_DIR}")

add_custom_target(gen_monster_test_json ALL)
file(GLOB FBS_FS ${FBS_DIR}/*.fbs)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_builder.h"
OUTPUT_VARIABLE FBS_B_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_reader.h"
OUTPUT_VARIABLE FBS_R_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_verifier.h"
OUTPUT_VARIABLE FBS_V_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_json_printer.h"
OUTPUT_VARIABLE FBS_JPR_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_json_parser.h"
OUTPUT_VARIABLE FBS_JPA_HS
)

list(APPEND FBS_R_HS ${GEN_DIR}/flatbuffers_common_reader.h)
list(APPEND FBS_B_HS ${GEN_DIR}/flatbuffers_common_builder.h)

add_custom_command (
TARGET gen_monster_test_json
OUTPUT ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS} ${FBS_JPR_HS} ${FBS_JPA_HS}
COMMAND ${CMAKE_COMMAND} -E make_directory "${GEN_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy "${DATA_SRC}/monsterdata_test.golden" "${DATA_DST}"
COMMAND ${CMAKE_COMMAND} -E copy "${DATA_SRC}/monsterdata_test.mon" "${DATA_DST}"
COMMAND flatcc_cli -av --json -o "${GEN_DIR}" "${FBS_DIR}/monster_test.fbs"
DEPENDS flatcc_cli "${FBS_DIR}/monster_test.fbs" "${FBS_DIR}/include_test1.fbs" "${FBS_DIR}/include_test2.fbs"
DEPENDS flatcc_cli "${FBS_FS}"
COMMENT "Generate json_test fbs headers"
)
add_custom_target(gen_monster_test_json ALL
DEPENDS ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS} ${FBS_JPR_HS} ${FBS_JPA_HS}
)

add_executable(test_basic_parse test_basic_parse.c)
Expand Down
27 changes: 22 additions & 5 deletions test/load_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,32 @@ set(FBS_DIR "${PROJECT_SOURCE_DIR}/test/monster_test")

include_directories("${GEN_DIR}" "${INC_DIR}")

add_custom_target(gen_load_test ALL)
file(GLOB FBS_FS ${FBS_DIR}/*.fbs)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_builder.h"
OUTPUT_VARIABLE FBS_B_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_reader.h"
OUTPUT_VARIABLE FBS_R_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_verifier.h"
OUTPUT_VARIABLE FBS_V_HS
)

list(APPEND FBS_R_HS ${GEN_DIR}/flatbuffers_common_reader.h)
list(APPEND FBS_B_HS ${GEN_DIR}/flatbuffers_common_builder.h)

add_custom_command (
TARGET gen_load_test
OUTPUT ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS}
COMMAND ${CMAKE_COMMAND} -E make_directory "${GEN_DIR}"
COMMAND flatcc_cli -a -o "${GEN_DIR}" "${FBS_DIR}/monster_test.fbs"
DEPENDS flatcc_cli "${FBS_DIR}/monster_test.fbs" "${FBS_DIR}/include_test1.fbs" "${FBS_DIR}/include_test2.fbs"
DEPENDS flatcc_cli "${FBS_FS}"
COMMENT "Generate load_test fbs headers"
)
add_executable(load_test load_test.c)
add_dependencies(load_test gen_load_test)

add_executable(load_test load_test.c ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS})
target_link_libraries(load_test flatccrt)

add_test(load_test load_test${CMAKE_EXECUTABLE_SUFFIX})
27 changes: 22 additions & 5 deletions test/monster_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,32 @@ set(FBS_DIR "${PROJECT_SOURCE_DIR}/test/monster_test")

include_directories("${GEN_DIR}" "${INC_DIR}")

add_custom_target(gen_monster_test ALL)
file(GLOB FBS_FS ${FBS_DIR}/*.fbs)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_builder.h"
OUTPUT_VARIABLE FBS_B_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_reader.h"
OUTPUT_VARIABLE FBS_R_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_verifier.h"
OUTPUT_VARIABLE FBS_V_HS
)

list(APPEND FBS_R_HS ${GEN_DIR}/flatbuffers_common_reader.h)
list(APPEND FBS_B_HS ${GEN_DIR}/flatbuffers_common_builder.h)

add_custom_command (
TARGET gen_monster_test
OUTPUT ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS}
COMMAND ${CMAKE_COMMAND} -E make_directory "${GEN_DIR}"
COMMAND flatcc_cli -a -o "${GEN_DIR}" "${FBS_DIR}/monster_test.fbs"
DEPENDS flatcc_cli "${FBS_DIR}/monster_test.fbs" "${FBS_DIR}/include_test1.fbs" "${FBS_DIR}/include_test2.fbs"
DEPENDS flatcc_cli "${FBS_FS}"
COMMENT "Generate monster_test fbs headers"
)
add_executable(monster_test monster_test.c)
add_dependencies(monster_test gen_monster_test)

add_executable(monster_test monster_test.c ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS})
target_link_libraries(monster_test flatccrt)

add_test(monster_test monster_test${CMAKE_EXECUTABLE_SUFFIX})
13 changes: 8 additions & 5 deletions test/monster_test_concat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ set(FBS_DIR "${PROJECT_SOURCE_DIR}/test/monster_test")

include_directories("${GEN_DIR}" "${INC_DIR}")

add_custom_target(gen_monster_test_concat ALL)
file(GLOB FBS_FS ${FBS_DIR}/*.fbs)

add_custom_command (
TARGET gen_monster_test_concat
OUTPUT ${GEN_DIR}/monster_test.h
COMMAND ${CMAKE_COMMAND} -E make_directory "${GEN_DIR}"
# We could also use the recursive -r option, but this tests adding files manually to the output file.
COMMAND flatcc_cli -cwv --reader -o "${GEN_DIR}" "--outfile=monster_test.h" "${FBS_DIR}/attributes.fbs" "${FBS_DIR}/include_test2.fbs" "${FBS_DIR}/include_test1.fbs" "${FBS_DIR}/monster_test.fbs" DEPENDS flatcc_cli "${FBS_DIR}/monster_test.fbs" "${FBS_DIR}/include_test1.fbs" "${FBS_DIR}/include_test2.fbs" "${FBS_DIR}/attributes.fbs"
COMMAND flatcc_cli -cwv --reader -o "${GEN_DIR}" "--outfile=monster_test.h" "${FBS_DIR}/attributes.fbs" "${FBS_DIR}/include_test2.fbs" "${FBS_DIR}/include_test1.fbs" "${FBS_DIR}/monster_test.fbs"
DEPENDS flatcc_cli "${FBS_FS}"
COMMENT "Generate monster_test_concat fbs headers"
)

include_directories("${GEN_DIR}" "${INC_DIR}")
add_executable(monster_test_concat monster_test_concat.c)
add_dependencies(monster_test_concat gen_monster_test_concat)
add_executable(monster_test_concat monster_test_concat.c ${GEN_DIR}/monster_test.h)
target_link_libraries(monster_test_concat flatccrt)

add_test(monster_test_concat monster_test_concat${CMAKE_EXECUTABLE_SUFFIX})
26 changes: 21 additions & 5 deletions test/monster_test_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,32 @@ set(FBS_DIR "${PROJECT_SOURCE_DIR}/samples/monster")

include_directories("${GEN_DIR}" "${INC_DIR}")

add_custom_target(gen_monster_test_cpp ALL)
file(GLOB FBS_FS ${FBS_DIR}/*.fbs)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_builder.h"
OUTPUT_VARIABLE FBS_B_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_reader.h"
OUTPUT_VARIABLE FBS_R_HS
)
list(TRANSFORM FBS_FS
REPLACE "${FBS_DIR}/(.*)\\.fbs$" "${GEN_DIR}/\\1_verifier.h"
OUTPUT_VARIABLE FBS_V_HS
)

list(APPEND FBS_R_HS ${GEN_DIR}/flatbuffers_common_reader.h)
list(APPEND FBS_B_HS ${GEN_DIR}/flatbuffers_common_builder.h)

add_custom_command (
TARGET gen_monster_test_cpp
OUTPUT ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS}
COMMAND ${CMAKE_COMMAND} -E make_directory "${GEN_DIR}"
COMMAND flatcc_cli -a -o "${GEN_DIR}" "${FBS_DIR}/monster.fbs"
DEPENDS flatcc_cli "${FBS_DIR}/monster.fbs"
DEPENDS flatcc_cli "${FBS_FS}"
COMMENT "Generate monster_test_cpp fbs headers"
)

add_executable(monster_test_cpp monster_test.cpp)
add_dependencies(monster_test_cpp gen_monster_test_cpp)
add_executable(monster_test_cpp monster_test.cpp ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS})
target_link_libraries(monster_test_cpp flatccrt)

add_test(monster_test_cpp monster_test_cpp${CMAKE_EXECUTABLE_SUFFIX})
12 changes: 7 additions & 5 deletions test/monster_test_prefix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ set(FBS_DIR "${PROJECT_SOURCE_DIR}/test/monster_test")

include_directories("${GEN_DIR}" "${INC_DIR}")

add_custom_target(gen_monster_test_prefix ALL)
file(GLOB FBS_FS ${FBS_DIR}/*.fbs)
add_custom_command (
TARGET gen_monster_test_prefix
OUTPUT ${GEN_DIR}/zzz_monster_test.h
COMMAND ${CMAKE_COMMAND} -E make_directory "${GEN_DIR}"
COMMAND flatcc_cli -a --prefix=zzz_ --stdout "${FBS_DIR}/monster_test.fbs" > "${GEN_DIR}/zzz_monster_test.h"
DEPENDS flatcc_cli "${FBS_DIR}/monster_test.fbs" "${FBS_DIR}/include_test1.fbs" "${FBS_DIR}/include_test2.fbs"
DEPENDS flatcc_cli "${FBS_FS}"
COMMENT "Generate monster_test_prefix fbs headers"
)
add_executable(monster_test_prefix monster_test_prefix.c)
add_dependencies(monster_test_prefix gen_monster_test_prefix)


add_executable(monster_test_prefix monster_test_prefix.c ${GEN_DIR}/zzz_monster_test.h)
target_link_libraries(monster_test_prefix flatccrt)

add_test(monster_test_prefix monster_test_prefix${CMAKE_EXECUTABLE_SUFFIX})
11 changes: 6 additions & 5 deletions test/monster_test_solo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ set(FBS_DIR "${PROJECT_SOURCE_DIR}/test/monster_test")

include_directories("${GEN_DIR}" "${INC_DIR}")

add_custom_target(gen_monster_test_solo ALL)
file(GLOB FBS_FS ${FBS_DIR}/*.fbs)
add_custom_command (
TARGET gen_monster_test_solo
OUTPUT ${GEN_DIR}/monster_test.h
COMMAND ${CMAKE_COMMAND} -E make_directory "${GEN_DIR}"
COMMAND flatcc_cli -cwv --reader --stdout "${FBS_DIR}/attributes.fbs" "${FBS_DIR}/include_test2.fbs" "${FBS_DIR}/include_test1.fbs" "${FBS_DIR}/monster_test.fbs" > "${GEN_DIR}/monster_test.h" DEPENDS flatcc_cli "${FBS_DIR}/monster_test.fbs" "${FBS_DIR}/include_test1.fbs" "${FBS_DIR}/include_test2.fbs" "${FBS_DIR}/attributes.fbs"
COMMAND flatcc_cli -cwv --reader --stdout "${FBS_DIR}/attributes.fbs" "${FBS_DIR}/include_test2.fbs" "${FBS_DIR}/include_test1.fbs" "${FBS_DIR}/monster_test.fbs" > "${GEN_DIR}/monster_test.h"
DEPENDS flatcc_cli "${FBS_FS}"
COMMENT "Generate monster_test_solo fbs headers"
)

include_directories("${GEN_DIR}" "${INC_DIR}")
add_executable(monster_test_solo monster_test_solo.c)
add_dependencies(monster_test_solo gen_monster_test_solo)
add_executable(monster_test_solo monster_test_solo.c ${GEN_DIR}/monster_test.h)
target_link_libraries(monster_test_solo flatccrt)

add_test(monster_test_solo monster_test_solo${CMAKE_EXECUTABLE_SUFFIX})
Loading