diff options
-rw-r--r-- | cmake/modules/FindFlatBuffers.cmake | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/cmake/modules/FindFlatBuffers.cmake b/cmake/modules/FindFlatBuffers.cmake index 6288d1021a..aba609933a 100644 --- a/cmake/modules/FindFlatBuffers.cmake +++ b/cmake/modules/FindFlatBuffers.cmake @@ -9,13 +9,10 @@ find_package(FlatC REQUIRED) if(NOT TARGET flatbuffers::flatbuffers) - if(ENABLE_INTERNAL_FLATBUFFERS) - include(cmake/scripts/common/ModuleHelpers.cmake) - set(MODULE_LC flatbuffers) - - SETUP_BUILD_VARS() + include(cmake/scripts/common/ModuleHelpers.cmake) + macro(buildflatbuffers) # Override build type detection and always build as release set(FLATBUFFERS_BUILD_TYPE Release) @@ -31,6 +28,22 @@ if(NOT TARGET flatbuffers::flatbuffers) set(BUILD_BYPRODUCTS ${DEPENDS_PATH}/include/flatbuffers/flatbuffers.h) BUILD_DEP_TARGET() + endmacro() + + set(MODULE_LC flatbuffers) + + SETUP_BUILD_VARS() + + find_package(flatbuffers CONFIG + HINTS ${DEPENDS_PATH}/lib/cmake + ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG}) + + # Check for existing Flatbuffers. If version >= FLATBUFFERS-VERSION file version, dont build + # A corner case, but if a linux/freebsd user WANTS to build internal flatbuffers, build anyway + if((flatbuffers_VERSION VERSION_LESS ${${MODULE}_VER} AND ENABLE_INTERNAL_FLATBUFFERS) OR + ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_FLATBUFFERS)) + + buildflatbuffers() else() find_path(FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h HINTS ${DEPENDS_PATH}/include @@ -52,5 +65,22 @@ if(NOT TARGET flatbuffers::flatbuffers) if(TARGET flatbuffers) add_dependencies(flatbuffers::flatbuffers flatbuffers) endif() + + # Add internal build target when a Multi Config Generator is used + # We cant add a dependency based off a generator expression for targeted build types, + # https://gitlab.kitware.com/cmake/cmake/-/issues/19467 + # therefore if the find heuristics only find the library, we add the internal build + # target to the project to allow user to manually trigger for any build type they need + # in case only a specific build type is actually available (eg Release found, Debug Required) + # This is mainly targeted for windows who required different runtime libs for different + # types, and they arent compatible + if(_multiconfig_generator) + if(NOT TARGET flatbuffers) + buildflatbuffers() + set_target_properties(flatbuffers PROPERTIES EXCLUDE_FROM_ALL TRUE) + endif() + add_dependencies(build_internal_depends flatbuffers) + endif() + set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP flatbuffers::flatbuffers) endif() |