Skip to content

Commit 9b4c04a

Browse files
committed
Fix Windows build
Summary: ## Context Fix third party `CMakeLists.txt` to allow `flatcc` to build for Windows. Some CMake configuration settings need to be adjusted for windows platforms. Test Plan: ## Test Plan ``` python install_executorch.py ```
1 parent 8953279 commit 9b4c04a

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

third-party/CMakeLists.txt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
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).
1219
ExternalProject_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
@@ -35,7 +40,7 @@ add_dependencies(flatc flatbuffers_external_project)
3540
if(WIN32)
3641
# flatbuffers does not use CMAKE_BUILD_TYPE. Internally, the build forces Release
3742
# 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)
43+
set_target_properties(flatc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatc.exe)
3944
else()
4045
set_target_properties(flatc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatc)
4146
endif()
@@ -49,13 +54,22 @@ endif()
4954

5055
# MARK: - flatcc
5156

57+
if(WIN32)
58+
# For some reason, when configuring the external project during build
59+
# CMAKE_C_SIMULATE_ID is set to MSVC, but CMAKE_CXX_SIMULATE_ID is not set.
60+
# To make sure the external project is configured correctly, set it explicitly
61+
# here.
62+
set(_flatcc_extra_cmake_args -DCMAKE_CXX_SIMULATE_ID=MSVC)
63+
else()
64+
set(_flatcc_extra_cmake_args)
65+
endif()
66+
5267
# Similar to flatbuffers, we want to build flatcc for the host. See inline comments
5368
# in the flatbuffers ExternalProject_Add for more details.
5469
ExternalProject_Add(
5570
flatcc_external_project
5671
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/flatcc_external_project
5772
SOURCE_DIR ${PROJECT_SOURCE_DIR}/third-party/flatcc
58-
CMAKE_GENERATOR "Unix Makefiles"
5973
CMAKE_ARGS -DFLATCC_RTONLY=OFF
6074
-DFLATCC_TEST=OFF
6175
-DFLATCC_REFLECTION=OFF
@@ -66,13 +80,15 @@ ExternalProject_Add(
6680
-DCMAKE_TOOLCHAIN_FILE=
6781
$<$<AND:$<BOOL:${APPLE}>,$<BOOL:$<FILTER:${PLATFORM},EXCLUDE,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
6882
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}
83+
${_flatcc_extra_cmake_args}
6984
BUILD_BYPRODUCTS <INSTALL_DIR>/bin/flatcc
85+
{_executorch_external_project_additional_args}
7086
)
7187
ExternalProject_Get_Property(flatcc_external_project INSTALL_DIR)
7288
add_executable(flatcc_cli IMPORTED GLOBAL)
7389
add_dependencies(flatcc_cli flatcc_external_project)
7490
if(WIN32)
75-
set_target_properties(flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/$<CONFIG>/bin/flatcc.exe)
91+
set_target_properties(flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatcc.exe)
7692
else()
7793
set_target_properties(flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatcc)
7894
endif()

0 commit comments

Comments
 (0)