From b640c08c9cfc26571a35262c9ad5cd5d97f64184 Mon Sep 17 00:00:00 2001 From: Lixiaoyu Date: Tue, 6 Dec 2022 20:52:29 +0800 Subject: [PATCH] [cmake:]fix the dependence to avoid generate files every time, even though no changed --- samples/monster/CMakeLists.txt | 27 +++++++++++++---- samples/reflection/CMakeLists.txt | 16 ++++++---- test/emit_test/CMakeLists.txt | 27 +++++++++++++---- test/flatc_compat/CMakeLists.txt | 27 +++++++++++++---- test/json_test/CMakeLists.txt | 34 +++++++++++++++++++-- test/load_test/CMakeLists.txt | 27 +++++++++++++---- test/monster_test/CMakeLists.txt | 27 +++++++++++++---- test/monster_test_concat/CMakeLists.txt | 13 ++++---- test/monster_test_cpp/CMakeLists.txt | 26 ++++++++++++---- test/monster_test_prefix/CMakeLists.txt | 12 ++++---- test/monster_test_solo/CMakeLists.txt | 11 +++---- test/optional_scalars_test/CMakeLists.txt | 36 ++++++++++++++++++++--- test/reflection_test/CMakeLists.txt | 11 +++---- 13 files changed, 232 insertions(+), 62 deletions(-) diff --git a/samples/monster/CMakeLists.txt b/samples/monster/CMakeLists.txt index 1c034553..9a9c820e 100644 --- a/samples/monster/CMakeLists.txt +++ b/samples/monster/CMakeLists.txt @@ -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) diff --git a/samples/reflection/CMakeLists.txt b/samples/reflection/CMakeLists.txt index cfbef1c0..d46b5c5f 100644 --- a/samples/reflection/CMakeLists.txt +++ b/samples/reflection/CMakeLists.txt @@ -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) diff --git a/test/emit_test/CMakeLists.txt b/test/emit_test/CMakeLists.txt index 54f3b286..b506ab68 100644 --- a/test/emit_test/CMakeLists.txt +++ b/test/emit_test/CMakeLists.txt @@ -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}) diff --git a/test/flatc_compat/CMakeLists.txt b/test/flatc_compat/CMakeLists.txt index a4729795..d57ea920 100644 --- a/test/flatc_compat/CMakeLists.txt +++ b/test/flatc_compat/CMakeLists.txt @@ -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}) diff --git a/test/json_test/CMakeLists.txt b/test/json_test/CMakeLists.txt index 332905d6..f431adb5 100644 --- a/test/json_test/CMakeLists.txt +++ b/test/json_test/CMakeLists.txt @@ -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) diff --git a/test/load_test/CMakeLists.txt b/test/load_test/CMakeLists.txt index 0c146d11..39127f7a 100644 --- a/test/load_test/CMakeLists.txt +++ b/test/load_test/CMakeLists.txt @@ -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}) diff --git a/test/monster_test/CMakeLists.txt b/test/monster_test/CMakeLists.txt index 5860a37e..e77c66ac 100644 --- a/test/monster_test/CMakeLists.txt +++ b/test/monster_test/CMakeLists.txt @@ -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}) diff --git a/test/monster_test_concat/CMakeLists.txt b/test/monster_test_concat/CMakeLists.txt index dab13f59..49ae2af8 100644 --- a/test/monster_test_concat/CMakeLists.txt +++ b/test/monster_test_concat/CMakeLists.txt @@ -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}) diff --git a/test/monster_test_cpp/CMakeLists.txt b/test/monster_test_cpp/CMakeLists.txt index dd576ca8..0e066294 100644 --- a/test/monster_test_cpp/CMakeLists.txt +++ b/test/monster_test_cpp/CMakeLists.txt @@ -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}) diff --git a/test/monster_test_prefix/CMakeLists.txt b/test/monster_test_prefix/CMakeLists.txt index 1e267613..758c04d3 100644 --- a/test/monster_test_prefix/CMakeLists.txt +++ b/test/monster_test_prefix/CMakeLists.txt @@ -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}) diff --git a/test/monster_test_solo/CMakeLists.txt b/test/monster_test_solo/CMakeLists.txt index a974434f..9ec1a2a3 100644 --- a/test/monster_test_solo/CMakeLists.txt +++ b/test/monster_test_solo/CMakeLists.txt @@ -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}) diff --git a/test/optional_scalars_test/CMakeLists.txt b/test/optional_scalars_test/CMakeLists.txt index b13c1b9e..64763a9a 100644 --- a/test/optional_scalars_test/CMakeLists.txt +++ b/test/optional_scalars_test/CMakeLists.txt @@ -6,14 +6,42 @@ set(FBS_DIR "${PROJECT_SOURCE_DIR}/test/optional_scalars_test") include_directories("${GEN_DIR}" "${INC_DIR}") -add_custom_target(gen_optional_scalars_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(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_optional_scalars_test + 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 flatcc_cli -a --json -o "${GEN_DIR}" "${FBS_DIR}/optional_scalars_test.fbs" + DEPENDS flatcc_cli "${FBS_FS}" + COMMENT "Generate optional_scalars_test fbs headers" ) -add_executable(optional_scalars_test optional_scalars_test.c) -add_dependencies(optional_scalars_test gen_optional_scalars_test) + +add_executable(optional_scalars_test optional_scalars_test.c + ${FBS_B_HS} ${FBS_R_HS} ${FBS_V_HS} ${FBS_JPR_HS} ${FBS_JPA_HS}) + target_link_libraries(optional_scalars_test flatccrt) add_test(optional_scalars_test optional_scalars_test${CMAKE_EXECUTABLE_SUFFIX}) diff --git a/test/reflection_test/CMakeLists.txt b/test/reflection_test/CMakeLists.txt index f82d1f53..23e0e9bb 100644 --- a/test/reflection_test/CMakeLists.txt +++ b/test/reflection_test/CMakeLists.txt @@ -6,15 +6,16 @@ set(FBS_DIR "${PROJECT_SOURCE_DIR}/test/monster_test") include_directories("${GEN_DIR}" "${INC_DIR}") -add_custom_target(gen_reflection_test ALL) +file(GLOB FBS_FS ${FBS_DIR}/*.fbs) add_custom_command ( - TARGET gen_reflection_test + OUTPUT ${GEN_DIR}/monster_test.bfbs COMMAND ${CMAKE_COMMAND} -E make_directory "${GEN_DIR}" COMMAND flatcc_cli --schema -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 reflection_test fbs headers" ) -add_executable(reflection_test reflection_test.c) -add_dependencies(reflection_test gen_reflection_test) + +add_executable(reflection_test reflection_test.c ${GEN_DIR}/monster_test.bfbs) target_link_libraries(reflection_test flatccrt) add_test(reflection_test reflection_test${CMAKE_EXECUTABLE_SUFFIX})