7
7
8
8
# MARK: - flatbuffers
9
9
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
+
10
17
# We use ExternalProject to build flatc from source to force it target the host.
11
18
# Otherwise, flatc will target the project's toolchain (i.e. iOS, or Android).
12
19
ExternalProject_Add(
13
20
flatbuffers_external_project
14
21
PREFIX ${CMAKE_CURRENT_BINARY_DIR} /flatbuffers_external_project
15
22
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"
18
23
CMAKE_ARGS -DFLATBUFFERS_BUILD_FLATC=ON
19
24
-DFLATBUFFERS_INSTALL=ON
20
25
-DFLATBUFFERS_BUILD_FLATHASH=OFF
@@ -28,14 +33,15 @@ ExternalProject_Add(
28
33
$<$<AND :$<BOOL :${APPLE} >,$<BOOL :$<FILTER :${PLATFORM} ,EXCLUDE ,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
29
34
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING =${CMAKE_OSX_DEPLOYMENT_TARGET}
30
35
BUILD_BYPRODUCTS <INSTALL_DIR>/bin/flatc
36
+ ${_executorch_external_project_additional_args}
31
37
)
32
38
ExternalProject_Get_Property(flatbuffers_external_project INSTALL_DIR)
33
39
add_executable (flatc IMPORTED GLOBAL )
34
40
add_dependencies (flatc flatbuffers_external_project)
35
41
if (WIN32 )
36
42
# flatbuffers does not use CMAKE_BUILD_TYPE. Internally, the build forces Release
37
43
# 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)
39
45
else ()
40
46
set_target_properties (flatc PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR} /bin/flatc)
41
47
endif ()
@@ -49,13 +55,22 @@ endif()
49
55
50
56
# MARK: - flatcc
51
57
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
+
52
68
# Similar to flatbuffers, we want to build flatcc for the host. See inline comments
53
69
# in the flatbuffers ExternalProject_Add for more details.
54
70
ExternalProject_Add(
55
71
flatcc_external_project
56
72
PREFIX ${CMAKE_CURRENT_BINARY_DIR} /flatcc_external_project
57
73
SOURCE_DIR ${PROJECT_SOURCE_DIR} /third-party/flatcc
58
- CMAKE_GENERATOR "Unix Makefiles"
59
74
CMAKE_ARGS -DFLATCC_RTONLY=OFF
60
75
-DFLATCC_TEST=OFF
61
76
-DFLATCC_REFLECTION=OFF
@@ -66,14 +81,16 @@ ExternalProject_Add(
66
81
-DCMAKE_TOOLCHAIN_FILE=
67
82
$<$<AND :$<BOOL :${APPLE} >,$<BOOL :$<FILTER :${PLATFORM} ,EXCLUDE ,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
68
83
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING =${CMAKE_OSX_DEPLOYMENT_TARGET}
84
+ ${_flatcc_extra_cmake_args}
69
85
BUILD_BYPRODUCTS <INSTALL_DIR>/bin/flatcc
86
+ {_executorch_external_project_additional_args}
70
87
)
71
88
file (REMOVE_RECURSE ${PROJECT_SOURCE_DIR} /third-party/flatcc/lib)
72
89
ExternalProject_Get_Property(flatcc_external_project INSTALL_DIR)
73
90
add_executable (flatcc_cli IMPORTED GLOBAL )
74
91
add_dependencies (flatcc_cli flatcc_external_project)
75
92
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)
77
94
else ()
78
95
set_target_properties (flatcc_cli PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR} /bin/flatcc)
79
96
endif ()
0 commit comments