diff options
author | Derek Bailey <derekbailey@google.com> | 2023-05-12 17:11:18 -0700 |
---|---|---|
committer | Derek Bailey <derekbailey@google.com> | 2023-05-12 17:11:18 -0700 |
commit | cbc8872b99a55a66900e9821ac8f9f54c4fb1064 (patch) | |
tree | cf76582b26fed8cad59e432bebd2d7f0eafdc08c | |
parent | 05743591e13938c05a3621f09d4a41d078aacec0 (diff) | |
download | flatbuffers-cbc8872b99a55a66900e9821ac8f9f54c4fb1064.tar.gz flatbuffers-cbc8872b99a55a66900e9821ac8f9f54c4fb1064.tar.bz2 flatbuffers-cbc8872b99a55a66900e9821ac8f9f54c4fb1064.zip |
fix Mac build about gen sources and multiple targets
-rw-r--r-- | CMakeLists.txt | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index bdabaf45..74f59661 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,7 +247,6 @@ set(FlatBuffers_Tests_CPP17_SRCS ) set(FlatBuffers_Sample_Binary_SRCS - include/flatbuffers/flatbuffers.h samples/sample_binary.cpp ) @@ -510,9 +509,7 @@ endfunction() function(compile_schema_for_samples SRC_FBS OPT) compile_schema("${SRC_FBS}" "${OPT}" GEN_FILE) - target_sources(flatsamplebinary PRIVATE ${GEN_FILE}) - target_sources(flatsampletext PRIVATE ${GEN_FILE}) - target_sources(flatsamplebfbs PRIVATE ${GEN_FILE}) + target_sources(sample_lib PRIVATE ${GEN_FILE}) endfunction() if(FLATBUFFERS_BUILD_TESTS) @@ -553,13 +550,20 @@ if(FLATBUFFERS_BUILD_TESTS) add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS}) add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS}) add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS}) - - target_link_libraries(flatsamplebinary PRIVATE $<BUILD_INTERFACE:ProjectConfig>) - target_link_libraries(flatsampletext PRIVATE $<BUILD_INTERFACE:ProjectConfig>) - target_link_libraries(flatsamplebfbs PRIVATE $<BUILD_INTERFACE:ProjectConfig>) + # Add a library so there is a single target that the generated samples can + # link too. + add_library(sample_lib STATIC) + + # Since sample_lib has no sources, we have to explicitly set the linker lang. + set_target_properties(sample_lib PROPERTIES LINKER_LANGUAGE CXX) + compile_schema_for_samples(samples/monster.fbs "${FLATC_OPT_COMP}") + target_link_libraries(flatsamplebinary PRIVATE $<BUILD_INTERFACE:ProjectConfig> sample_lib) + target_link_libraries(flatsampletext PRIVATE $<BUILD_INTERFACE:ProjectConfig> sample_lib) + target_link_libraries(flatsamplebfbs PRIVATE $<BUILD_INTERFACE:ProjectConfig> sample_lib) + if(FLATBUFFERS_BUILD_CPP17) add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS}) target_link_libraries(flattests_cpp17 PRIVATE $<BUILD_INTERFACE:ProjectConfig>) |