Skip to content

Commit

Permalink
disable flatc if not supported or makes little sense
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm committed Feb 7, 2022
1 parent 97c4254 commit 8b99a52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 13 additions & 4 deletions recipes/flatbuffers/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class FlatbuffersConan(ConanFile):
def _source_subfolder(self):
return "source_subfolder"

@property
def _has_flatc(self):
# don't build flatc when it makes little sense or not supported
return not (self.settings.os in ["Android", "iOS", "watchOS", "tvOS"] or \
str(self.settings.os).upper() == "QNX")

def export_sources(self):
self.copy("CMakeLists.txt")
self.copy(os.path.join("cmake", "FlatcTargets.cmake"))
Expand All @@ -62,6 +68,8 @@ def validate(self):
tools.check_min_cppstd(self, 11)

def package_id(self):
if self.options.header_only and not self._has_flatc:
self.info.header_only()
# deprecated options
del self.info.options.flatc
del self.info.options.flatbuffers
Expand Down Expand Up @@ -93,7 +101,7 @@ def _configure_cmake(self):
self._cmake.definitions["FLATBUFFERS_BUILD_TESTS"] = False
self._cmake.definitions["FLATBUFFERS_INSTALL"] = True
self._cmake.definitions["FLATBUFFERS_BUILD_FLATLIB"] = not self.options.header_only and not self.options.shared
self._cmake.definitions["FLATBUFFERS_BUILD_FLATC"] = True
self._cmake.definitions["FLATBUFFERS_BUILD_FLATC"] = self._has_flatc
self._cmake.definitions["FLATBUFFERS_STATIC_FLATC"] = False
self._cmake.definitions["FLATBUFFERS_BUILD_FLATHASH"] = False
self._cmake.definitions["FLATBUFFERS_BUILD_SHAREDLIB"] = not self.options.header_only and self.options.shared
Expand Down Expand Up @@ -157,9 +165,10 @@ def package_info(self):
os.path.join(self._module_path, "BuildFlatBuffers.cmake"),
]
self.cpp_info.set_property("cmake_build_modules", build_modules)
bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
self.env_info.PATH.append(bindir)
if self._has_flatc:
bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
self.env_info.PATH.append(bindir)

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.filenames["cmake_find_package"] = "FlatBuffers"
Expand Down
8 changes: 6 additions & 2 deletions recipes/flatbuffers/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
add_executable(sample_binary sample_binary.cpp)
target_link_libraries(sample_binary ${FLATBUFFERS_TARGET})
set_property(TARGET sample_binary PROPERTY CXX_STANDARD 11)

set(MONSTER_GENERATED_HEADER ${CMAKE_CURRENT_BINARY_DIR}/monster_generated.h)
add_custom_target(generate_monster_header DEPENDS ${MONSTER_GENERATED_HEADER})
set(MONSTER_FBS ${CMAKE_CURRENT_SOURCE_DIR}/monster.fbs)
add_custom_command(
OUTPUT ${MONSTER_GENERATED_HEADER}
COMMAND $<TARGET_FILE:flatbuffers::flatc> --cpp -o ${CMAKE_CURRENT_BINARY_DIR} ${MONSTER_FBS}
COMMAND $<TARGET_FILE:flatbuffers::flatc>
--cpp
-o ${CMAKE_CURRENT_BINARY_DIR}
${MONSTER_FBS}
DEPENDS ${MONSTER_FBS}
)
add_custom_target(generate_monster_header DEPENDS ${MONSTER_GENERATED_HEADER})
add_dependencies(sample_binary generate_monster_header)
target_include_directories(sample_binary PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

0 comments on commit 8b99a52

Please sign in to comment.