Skip to content

Commit b20419d

Browse files
authored
Use the install method for flatc (#10859)
### Summary I came across this "cleaner" approach when setting up flatcc (#10855). So, let's do it for flatc too. ### Test plan CI cc @larryliu0820
1 parent 9ded0a2 commit b20419d

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

setup.py

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

841841
ext_modules = [
842842
BuiltFile(
843-
src_dir="%CMAKE_CACHE_DIR%/third-party/flatbuffers_external_project",
843+
src_dir="%CMAKE_CACHE_DIR%/third-party/flatbuffers_external_project/bin/%BUILD_TYPE%/",
844844
src_name="flatc",
845845
dst="executorch/data/bin/",
846846
is_executable=True,

third-party/CMakeLists.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,32 @@
1212
ExternalProject_Add(
1313
flatbuffers_external_project
1414
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/flatbuffers_external_project
15-
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/flatbuffers_external_project
1615
SOURCE_DIR ${PROJECT_SOURCE_DIR}/third-party/flatbuffers
1716
# Always use Make to avoid needing to codesign flatc if the project is using Xcode.
1817
CMAKE_GENERATOR "Unix Makefiles"
1918
CMAKE_ARGS -DFLATBUFFERS_BUILD_FLATC=ON
20-
-DFLATBUFFERS_INSTALL=OFF
19+
-DFLATBUFFERS_INSTALL=ON
2120
-DFLATBUFFERS_BUILD_FLATHASH=OFF
2221
-DFLATBUFFERS_BUILD_FLATLIB=OFF
2322
-DFLATBUFFERS_BUILD_TESTS=OFF
23+
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
2424
-DCMAKE_CXX_FLAGS="-DFLATBUFFERS_MAX_ALIGNMENT=${EXECUTORCH_FLATBUFFERS_MAX_ALIGNMENT}"
2525
# Unset the toolchain to build for the host instead of the toolchain set for the project.
2626
-DCMAKE_TOOLCHAIN_FILE=
2727
# If building for iOS, "unset" these variables to rely on the host (macOS) defaults.
2828
$<$<AND:$<BOOL:${APPLE}>,$<BOOL:$<FILTER:${PLATFORM},EXCLUDE,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
2929
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}
30-
INSTALL_COMMAND ""
31-
BUILD_BYPRODUCTS <BINARY_DIR>/flatc
30+
BUILD_BYPRODUCTS <INSTALL_DIR>/bin/flatc
3231
)
33-
ExternalProject_Get_Property(flatbuffers_external_project BINARY_DIR)
32+
ExternalProject_Get_Property(flatbuffers_external_project INSTALL_DIR)
3433
add_executable(flatc IMPORTED GLOBAL)
3534
add_dependencies(flatc flatbuffers_external_project)
3635
if(WIN32)
3736
# flatbuffers does not use CMAKE_BUILD_TYPE. Internally, the build forces Release
3837
# config, but from CMake's perspective the build type is always Debug.
39-
set_target_properties(flatc PROPERTIES IMPORTED_LOCATION ${BINARY_DIR}/$<CONFIG>/flatc.exe)
38+
set_target_properties(flatc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/$<CONFIG>/bin/flatc.exe)
4039
else()
41-
set_target_properties(flatc PROPERTIES IMPORTED_LOCATION ${BINARY_DIR}/flatc)
40+
set_target_properties(flatc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatc)
4241
endif()
4342

4443
# TODO: re-enable once flatbuffers is added as a subdirectory.
@@ -73,7 +72,7 @@ ExternalProject_Get_Property(flatcc_external_project INSTALL_DIR)
7372
add_executable(flatcc_cli IMPORTED GLOBAL)
7473
add_dependencies(flatcc_cli flatcc_external_project)
7574
if(WIN32)
76-
set_target_properties(flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/${CMAKE_BUILD_TYPE}/flatcc)
75+
set_target_properties(flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/$<CONFIG>/bin/flatcc.exe)
7776
else()
7877
set_target_properties(flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatcc)
7978
endif()

0 commit comments

Comments
 (0)