aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorfuzzard <fuzzard@kodi.tv>2022-11-06 15:31:29 +1000
committerfuzzard <fuzzard@kodi.tv>2022-11-18 08:26:36 +1100
commit1254328de47abc415d1a635dcf922d1129c5613d (patch)
treec87a10af54fcbbcbfe35fa3f253b94b5448207de /cmake
parent122916890a2b82ad8defaf2fd1934076387df84d (diff)
[cmake] Fix FlatC buildtools race
Ran across a build failure on windows hosts where flatc wasnt built prior to use This fixes that, and ensures flatc target is built as a dependency to flatbuffers::flatbuffers target if the flatc executable doesnt exist.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/modules/FindFlatBuffers.cmake3
-rw-r--r--cmake/modules/buildtools/FindFlatC.cmake25
2 files changed, 20 insertions, 8 deletions
diff --git a/cmake/modules/FindFlatBuffers.cmake b/cmake/modules/FindFlatBuffers.cmake
index 4f4c8ab1d6..fffac4fae7 100644
--- a/cmake/modules/FindFlatBuffers.cmake
+++ b/cmake/modules/FindFlatBuffers.cmake
@@ -5,10 +5,11 @@
# This will define the following variables:
#
# FLATBUFFERS_FOUND - system has FlatBuffers compiler and headers
-# FLATBUFFERS_FLATC_EXECUTABLE - the flatc compiler executable
# FLATBUFFERS_INCLUDE_DIRS - the FlatFuffers include directory
# FLATBUFFERS_MESSAGES_INCLUDE_DIR - the directory for generated headers
+find_package(FlatC REQUIRED)
+
if(ENABLE_INTERNAL_FLATBUFFERS)
include(cmake/scripts/common/ModuleHelpers.cmake)
diff --git a/cmake/modules/buildtools/FindFlatC.cmake b/cmake/modules/buildtools/FindFlatC.cmake
index 65bcbff3e4..6522f76a0b 100644
--- a/cmake/modules/buildtools/FindFlatC.cmake
+++ b/cmake/modules/buildtools/FindFlatC.cmake
@@ -4,8 +4,9 @@
#
# This will define the following variables:
#
-# FLATBUFFERS_FOUND - system has FlatBuffers compiler and headers
+# FLATBUFFERS_FLATC_EXECUTABLE_FOUND - system has FlatBuffers compiler
# FLATBUFFERS_FLATC_EXECUTABLE - the flatc compiler executable
+# FLATBUFFERS_FLATC_VERSION - the flatc compiler version
#
# and the following imported targets:
#
@@ -13,15 +14,24 @@
include(cmake/scripts/common/ModuleHelpers.cmake)
-set(MODULE_LC flatbuffers)
-
-SETUP_BUILD_VARS()
-
# Check for existing FLATC.
find_program(FLATBUFFERS_FLATC_EXECUTABLE NAMES flatc
HINTS ${NATIVEPREFIX}/bin)
-if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
+if(FLATBUFFERS_FLATC_EXECUTABLE)
+ execute_process(COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" --version
+ OUTPUT_VARIABLE FLATBUFFERS_FLATC_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REGEX MATCH "[^\n]* version [^\n]*" FLATBUFFERS_FLATC_VERSION "${FLATBUFFERS_FLATC_VERSION}")
+ string(REGEX REPLACE ".* version (.*)" "\\1" FLATBUFFERS_FLATC_VERSION "${FLATBUFFERS_FLATC_VERSION}")
+
+else()
+
+ set(MODULE_LC flatbuffers)
+ # Duplicate URL may exist from FindFlatbuffers.cmake
+ # unset otherwise it thinks we are providing a local file location and incorrect concatenation happens
+ unset(FLATBUFFERS_URL)
+ SETUP_BUILD_VARS()
# Override build type detection and always build as release
set(FLATBUFFERS_BUILD_TYPE Release)
@@ -57,6 +67,7 @@ if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
set(BUILD_NAME flatc)
set(BUILD_BYPRODUCTS ${FLATBUFFERS_FLATC_EXECUTABLE})
+ set(FLATBUFFERS_FLATC_VERSION ${FLATBUFFERS_VER})
BUILD_DEP_TARGET()
endif()
@@ -64,7 +75,7 @@ endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FlatC
REQUIRED_VARS FLATBUFFERS_FLATC_EXECUTABLE
- VERSION_VAR FLATBUFFERS_VER)
+ VERSION_VAR FLATBUFFERS_FLATC_VERSION)
if(FLATC_FOUND)