Skip to content

Commit cb3eba0

Browse files
authored
Fix Windows build (#10946)
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 9aedbeb commit cb3eba0

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ def get_ext_modules() -> List[Extension]:
835835

836836
ext_modules = [
837837
BuiltFile(
838-
src_dir="%CMAKE_CACHE_DIR%/third-party/flatbuffers_external_project/bin/%BUILD_TYPE%/",
838+
src_dir="%CMAKE_CACHE_DIR%/third-party/flatbuffers_external_project/bin/",
839839
src_name="flatc",
840840
dst="executorch/data/bin/",
841841
is_executable=True,

third-party/CMakeLists.txt

Lines changed: 22 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
@@ -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
)
3238
ExternalProject_Get_Property(flatbuffers_external_project INSTALL_DIR)
3339
add_executable(flatc IMPORTED GLOBAL)
3440
add_dependencies(flatc flatbuffers_external_project)
3541
if(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)
3945
else()
4046
set_target_properties(flatc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatc)
4147
endif()
@@ -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.
5470
ExternalProject_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
)
7188
file(REMOVE_RECURSE ${PROJECT_SOURCE_DIR}/third-party/flatcc/lib)
7289
ExternalProject_Get_Property(flatcc_external_project INSTALL_DIR)
7390
add_executable(flatcc_cli IMPORTED GLOBAL)
7491
add_dependencies(flatcc_cli flatcc_external_project)
7592
if(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)
7794
else()
7895
set_target_properties(flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatcc)
7996
endif()

0 commit comments

Comments
 (0)