Skip to content

Commit 8a77f9b

Browse files
Format third-party/CMakeLists.txt using cmake-format (#18533)
Fixes #10736 Formats `third-party/CMakeLists.txt` using `cmake-format` to improve readability and consistency. **Changes:** - Reformatted `ExternalProject_Add(...)` blocks for `flatbuffers` and `flatcc` - Reflowed `set_target_properties(...)`, `set(...)` cache variables, and `install(...)` calls - No functional changes — formatting only
1 parent 2d995bc commit 8a77f9b

1 file changed

Lines changed: 78 additions & 52 deletions

File tree

third-party/CMakeLists.txt

Lines changed: 78 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ endif()
2424
if(WIN32)
2525
set(_executorch_external_project_additional_args)
2626
else()
27-
# Always use Make to avoid needing to codesign flatc if the project is using Xcode.
28-
set(_executorch_external_project_additional_args CMAKE_GENERATOR "Unix Makefiles")
27+
# Always use Make to avoid needing to codesign flatc if the project is using
28+
# Xcode.
29+
set(_executorch_external_project_additional_args CMAKE_GENERATOR
30+
"Unix Makefiles"
31+
)
2932
endif()
3033

3134
# We use ExternalProject to build flatc from source to force it target the host.
@@ -35,101 +38,124 @@ ExternalProject_Add(
3538
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/flatc_ep
3639
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/flatc_ep/src/build
3740
SOURCE_DIR ${PROJECT_SOURCE_DIR}/third-party/flatbuffers
38-
CMAKE_ARGS -DFLATBUFFERS_BUILD_FLATC=ON
39-
-DFLATBUFFERS_INSTALL=ON
40-
-DFLATBUFFERS_BUILD_FLATHASH=OFF
41-
-DFLATBUFFERS_BUILD_FLATLIB=OFF
42-
-DFLATBUFFERS_BUILD_TESTS=OFF
43-
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
44-
-DCMAKE_CXX_FLAGS="-DFLATBUFFERS_MAX_ALIGNMENT=${EXECUTORCH_FLATBUFFERS_MAX_ALIGNMENT}"
45-
# Unset the toolchain to build for the host instead of the toolchain set for the project.
46-
-DCMAKE_TOOLCHAIN_FILE=
47-
# If building for iOS, "unset" these variables to rely on the host (macOS) defaults.
48-
$<$<AND:$<BOOL:${APPLE}>,$<BOOL:$<FILTER:${PLATFORM},EXCLUDE,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
49-
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}
41+
CMAKE_ARGS
42+
-DFLATBUFFERS_BUILD_FLATC=ON
43+
-DFLATBUFFERS_INSTALL=ON
44+
-DFLATBUFFERS_BUILD_FLATHASH=OFF
45+
-DFLATBUFFERS_BUILD_FLATLIB=OFF
46+
-DFLATBUFFERS_BUILD_TESTS=OFF
47+
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
48+
-DCMAKE_CXX_FLAGS="-DFLATBUFFERS_MAX_ALIGNMENT=${EXECUTORCH_FLATBUFFERS_MAX_ALIGNMENT}"
49+
# Unset the toolchain to build for the host instead of the toolchain set for
50+
# the project.
51+
-DCMAKE_TOOLCHAIN_FILE=
52+
# If building for iOS, "unset" these variables to rely on the host (macOS)
53+
# defaults.
54+
$<$<AND:$<BOOL:${APPLE}>,$<BOOL:$<FILTER:${PLATFORM},EXCLUDE,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
55+
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}
5056
BUILD_BYPRODUCTS <INSTALL_DIR>/bin/flatc
51-
${_executorch_external_project_additional_args}
57+
${_executorch_external_project_additional_args}
5258
)
5359
ExternalProject_Get_Property(flatbuffers_ep INSTALL_DIR)
5460
add_executable(flatc IMPORTED GLOBAL)
5561
add_dependencies(flatc flatbuffers_ep)
5662
if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
57-
# flatbuffers does not use CMAKE_BUILD_TYPE. Internally, the build forces Release
58-
# config, but from CMake's perspective the build type is always Debug.
59-
set_target_properties(flatc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatc.exe)
63+
# flatbuffers does not use CMAKE_BUILD_TYPE. Internally, the build forces
64+
# Release config, but from CMake's perspective the build type is always Debug.
65+
set_target_properties(
66+
flatc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatc.exe
67+
)
6068
else()
61-
set_target_properties(flatc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatc)
69+
set_target_properties(
70+
flatc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatc
71+
)
6272
endif()
6373

6474
# TODO: re-enable once flatbuffers is added as a subdirectory.
65-
# set(FLATBUFFERS_BUILD_FLATC OFF)
66-
# set(FLATBUFFERS_INSTALL OFF)
67-
# set(FLATBUFFERS_BUILD_FLATHASH OFF)
68-
# set(FLATBUFFERS_BUILD_FLATLIB OFF)
75+
# set(FLATBUFFERS_BUILD_FLATC OFF) set(FLATBUFFERS_INSTALL OFF)
76+
# set(FLATBUFFERS_BUILD_FLATHASH OFF) set(FLATBUFFERS_BUILD_FLATLIB OFF)
6977
# set(FLATBUFFERS_BUILD_TESTS OFF)
7078

7179
# MARK: - flatcc
7280

7381
if(WIN32)
7482
# For some reason, when configuring the external project during build
75-
# CMAKE_C_SIMULATE_ID is set to MSVC, but CMAKE_CXX_SIMULATE_ID is not set.
76-
# To make sure the external project is configured correctly, set it explicitly
83+
# CMAKE_C_SIMULATE_ID is set to MSVC, but CMAKE_CXX_SIMULATE_ID is not set. To
84+
# make sure the external project is configured correctly, set it explicitly
7785
# here.
7886
set(_flatcc_extra_cmake_args -DCMAKE_CXX_SIMULATE_ID=MSVC)
7987
else()
8088
set(_flatcc_extra_cmake_args)
8189
endif()
8290

83-
# Similar to flatbuffers, we want to build flatcc for the host. See inline comments
84-
# in the flatbuffers ExternalProject_Add for more details.
91+
# Similar to flatbuffers, we want to build flatcc for the host. See inline
92+
# comments in the flatbuffers ExternalProject_Add for more details.
8593
ExternalProject_Add(
8694
flatcc_ep
8795
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/flatcc_ep
8896
SOURCE_DIR ${PROJECT_SOURCE_DIR}/third-party/flatcc
8997
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/flatcc_ep/src/build
90-
CMAKE_ARGS -DFLATCC_RTONLY=OFF
91-
-DFLATCC_TEST=OFF
92-
-DFLATCC_REFLECTION=OFF
93-
-DFLATCC_DEBUG_CLANG_SANITIZE=OFF
94-
-DFLATCC_INSTALL=ON
95-
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
96-
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
97-
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
98-
-DCMAKE_TOOLCHAIN_FILE=
99-
$<$<AND:$<BOOL:${APPLE}>,$<BOOL:$<FILTER:${PLATFORM},EXCLUDE,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
100-
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}
101-
${_flatcc_extra_cmake_args}
98+
CMAKE_ARGS
99+
-DFLATCC_RTONLY=OFF
100+
-DFLATCC_TEST=OFF
101+
-DFLATCC_REFLECTION=OFF
102+
-DFLATCC_DEBUG_CLANG_SANITIZE=OFF
103+
-DFLATCC_INSTALL=ON
104+
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
105+
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
106+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
107+
-DCMAKE_TOOLCHAIN_FILE=
108+
$<$<AND:$<BOOL:${APPLE}>,$<BOOL:$<FILTER:${PLATFORM},EXCLUDE,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
109+
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET}
110+
${_flatcc_extra_cmake_args}
102111
BUILD_BYPRODUCTS <INSTALL_DIR>/bin/flatcc
103-
{_executorch_external_project_additional_args}
112+
${_executorch_external_project_additional_args}
104113
)
105114
file(REMOVE_RECURSE ${PROJECT_SOURCE_DIR}/third-party/flatcc/lib)
106115
ExternalProject_Get_Property(flatcc_ep INSTALL_DIR)
107116
add_executable(flatcc_cli IMPORTED GLOBAL)
108117
add_dependencies(flatcc_cli flatcc_ep)
109118
if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
110-
set_target_properties(flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatcc.exe)
119+
set_target_properties(
120+
flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatcc.exe
121+
)
111122
else()
112-
set_target_properties(flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatcc)
123+
set_target_properties(
124+
flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/bin/flatcc
125+
)
113126
endif()
114127

115-
set(FLATCC_RTONLY ON CACHE BOOL "")
116-
set(FLATCC_TEST OFF CACHE BOOL "")
117-
set(FLATCC_REFLECTION OFF CACHE BOOL "")
118-
set(FLATCC_DEBUG_CLANG_SANITIZE OFF CACHE BOOL "")
119-
set(FLATCC_INSTALL OFF CACHE BOOL "")
128+
set(FLATCC_RTONLY
129+
ON
130+
CACHE BOOL ""
131+
)
132+
set(FLATCC_TEST
133+
OFF
134+
CACHE BOOL ""
135+
)
136+
set(FLATCC_REFLECTION
137+
OFF
138+
CACHE BOOL ""
139+
)
140+
set(FLATCC_DEBUG_CLANG_SANITIZE
141+
OFF
142+
CACHE BOOL ""
143+
)
144+
set(FLATCC_INSTALL
145+
OFF
146+
CACHE BOOL ""
147+
)
120148
add_subdirectory(flatcc)
121149
# Unfortunately flatcc writes libs directly in to the source tree [1]. So to
122150
# ensure the target lib is created last, force flatcc_cli to build first.
123151
#
124-
# [1] https://github.com/dvidelabs/flatcc/blob/896db54787e8b730a6be482c69324751f3f5f117/CMakeLists.txt#L168
152+
# [1]
153+
# https://github.com/dvidelabs/flatcc/blob/896db54787e8b730a6be482c69324751f3f5f117/CMakeLists.txt#L168
125154
add_dependencies(flatccrt flatcc_cli)
126155
# Fix for "relocation R_X86_64_32 against `.rodata' can not be used when making
127156
# a shared object; recompile with -fPIC" when building on some x86 linux
128157
# systems.
129158
#
130159
# Learn more: https://github.com/pytorch/executorch/pull/2467
131160
set_property(TARGET flatccrt PROPERTY POSITION_INDEPENDENT_CODE ON)
132-
install(
133-
TARGETS flatccrt
134-
DESTINATION ${CMAKE_BINARY_DIR}/lib
135-
)
161+
install(TARGETS flatccrt DESTINATION ${CMAKE_BINARY_DIR}/lib)

0 commit comments

Comments
 (0)