77
88# MARK: - flatbuffers
99
10+ if (WIN32 )
11+ set (_executorch_external_project_additional_args)
12+ else ()
13+ # Always use Make to avoid needing to codesign flatc if the project is using Xcode.
14+ set (_executorch_external_project_additional_args CMAKE_GENERATOR "Unix Makefiles" )
15+ endif ()
16+
1017# We use ExternalProject to build flatc from source to force it target the host.
1118# Otherwise, flatc will target the project's toolchain (i.e. iOS, or Android).
1219ExternalProject_Add(
1320 flatbuffers_external_project
1421 PREFIX ${CMAKE_CURRENT_BINARY_DIR} /flatbuffers_external_project
1522 SOURCE_DIR ${PROJECT_SOURCE_DIR} /third-party/flatbuffers
16- # Always use Make to avoid needing to codesign flatc if the project is using Xcode.
17- CMAKE_GENERATOR "Unix Makefiles"
1823 CMAKE_ARGS -DFLATBUFFERS_BUILD_FLATC=ON
1924 -DFLATBUFFERS_INSTALL=ON
2025 -DFLATBUFFERS_BUILD_FLATHASH=OFF
@@ -28,14 +33,15 @@ ExternalProject_Add(
2833 $<$<AND :$<BOOL :${APPLE} >,$<BOOL :$<FILTER :${PLATFORM} ,EXCLUDE ,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
2934 -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING =${CMAKE_OSX_DEPLOYMENT_TARGET}
3035 BUILD_BYPRODUCTS <INSTALL_DIR>/bin/flatc
36+ ${_executorch_external_project_additional_args}
3137)
3238ExternalProject_Get_Property(flatbuffers_external_project INSTALL_DIR)
3339add_executable (flatc IMPORTED GLOBAL )
3440add_dependencies (flatc flatbuffers_external_project)
3541if (WIN32 )
3642 # flatbuffers does not use CMAKE_BUILD_TYPE. Internally, the build forces Release
3743 # config, but from CMake's perspective the build type is always Debug.
38- set_target_properties (flatc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR} /$<CONFIG>/ bin/flatc.exe)
44+ set_target_properties (flatc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR} /bin/flatc.exe)
3945else ()
4046 set_target_properties (flatc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR} /bin/flatc)
4147endif ()
@@ -49,13 +55,22 @@ endif()
4955
5056# MARK: - flatcc
5157
58+ if (WIN32 )
59+ # For some reason, when configuring the external project during build
60+ # CMAKE_C_SIMULATE_ID is set to MSVC, but CMAKE_CXX_SIMULATE_ID is not set.
61+ # To make sure the external project is configured correctly, set it explicitly
62+ # here.
63+ set (_flatcc_extra_cmake_args -DCMAKE_CXX_SIMULATE_ID=MSVC )
64+ else ()
65+ set (_flatcc_extra_cmake_args)
66+ endif ()
67+
5268# Similar to flatbuffers, we want to build flatcc for the host. See inline comments
5369# in the flatbuffers ExternalProject_Add for more details.
5470ExternalProject_Add(
5571 flatcc_external_project
5672 PREFIX ${CMAKE_CURRENT_BINARY_DIR} /flatcc_external_project
5773 SOURCE_DIR ${PROJECT_SOURCE_DIR} /third-party/flatcc
58- CMAKE_GENERATOR "Unix Makefiles"
5974 CMAKE_ARGS -DFLATCC_RTONLY=OFF
6075 -DFLATCC_TEST=OFF
6176 -DFLATCC_REFLECTION=OFF
@@ -66,14 +81,16 @@ ExternalProject_Add(
6681 -DCMAKE_TOOLCHAIN_FILE=
6782 $<$<AND :$<BOOL :${APPLE} >,$<BOOL :$<FILTER :${PLATFORM} ,EXCLUDE ,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
6883 -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING =${CMAKE_OSX_DEPLOYMENT_TARGET}
84+ ${_flatcc_extra_cmake_args}
6985 BUILD_BYPRODUCTS <INSTALL_DIR>/bin/flatcc
86+ {_executorch_external_project_additional_args}
7087)
7188file (REMOVE_RECURSE ${PROJECT_SOURCE_DIR} /third-party/flatcc/lib)
7289ExternalProject_Get_Property(flatcc_external_project INSTALL_DIR)
7390add_executable (flatcc_cli IMPORTED GLOBAL )
7491add_dependencies (flatcc_cli flatcc_external_project)
7592if (WIN32 )
76- set_target_properties (flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR} /$<CONFIG>/ bin/flatcc.exe)
93+ set_target_properties (flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR} /bin/flatcc.exe)
7794else ()
7895 set_target_properties (flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR} /bin/flatcc)
7996endif ()
0 commit comments