Skip to content

Commit 7c7886b

Browse files
dbortfacebook-github-bot
authored andcommitted
Use CMAKE_CURRENT_SOURCE_DIR for host flatcc paths (#2845)
Summary: The host flatcc paths were using CMAKE_SOURCE_DIR, which points to the directory of the top-most CMakeLists.txt file. This works when executorch is the top-level project, but not if another project adds executorch as a subdirectory. Instead, use paths relative to CMAKE_CURRENT_SOURCE_DIR, which points to the directory of the CMakeLists.txt file that is currently being executed. Pull Request resolved: #2845 Test Plan: With this changes we were able to successfully build the nanogpt_runner with etdump in dbort/et-tutorials#3 Reviewed By: tarun292 Differential Revision: D55720241 Pulled By: dbort fbshipit-source-id: c6c890c51853f518a19265c09e5e0eee25784dad
1 parent b5d4002 commit 7c7886b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

sdk/CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ endforeach()
5454

5555
set(FLATCC_TEST OFF CACHE BOOL "")
5656
set(FLATCC_REFLECTION OFF CACHE BOOL "")
57-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/flatcc
58-
${CMAKE_BINARY_DIR}/third-party/flatcc)
57+
set(_flatcc_source_dir ${CMAKE_CURRENT_SOURCE_DIR}/../third-party/flatcc)
58+
add_subdirectory(${_flatcc_source_dir} ${CMAKE_BINARY_DIR}/third-party/flatcc)
5959

6060
# Fix for "relocation R_X86_64_32 against `.rodata' can not be used when making
6161
# a shared object; recompile with -fPIC" when building on some x86 linux
@@ -74,7 +74,7 @@ set(_bundled_schema__include_dir "${CMAKE_BINARY_DIR}/sdk/bundled_program")
7474
ExternalProject_Add(
7575
flatcc_project
7676
PREFIX ${CMAKE_BINARY_DIR}/_host_build
77-
SOURCE_DIR ${CMAKE_SOURCE_DIR}/third-party/flatcc
77+
SOURCE_DIR ${_flatcc_source_dir}
7878
BINARY_DIR ${CMAKE_BINARY_DIR}/_host_build
7979
CMAKE_CACHE_ARGS -DFLATCC_TEST:BOOL=OFF -DFLATCC_REFLECTION:BOOL=OFF
8080
# See above comment about POSITION_INDEPENDENT_CODE.
@@ -117,7 +117,10 @@ file(MAKE_DIRECTORY
117117
add_custom_command(
118118
OUTPUT ${_etdump_schema__outputs}
119119
COMMAND
120-
${CMAKE_SOURCE_DIR}/third-party/flatcc/bin/flatcc -cwr -o
120+
# Note that the flatcc project actually writes its outputs into the source
121+
# tree instead of under the binary directory, and there's no way to change
122+
# that behavior.
123+
${_flatcc_source_dir}/bin/flatcc -cwr -o
121124
${_program_schema__include_dir}/executorch/sdk/etdump
122125
${_etdump_schema__srcs}
123126
# TODO(dbort): flatcc installs its files directly in its source directory
@@ -134,8 +137,8 @@ add_custom_command(
134137
# try to remove this hack, ideally by submitting an upstream PR that adds an
135138
# option to change the installation location.
136139
COMMAND
137-
rm -f ${CMAKE_SOURCE_DIR}/third-party/flatcc/bin/*
138-
${CMAKE_SOURCE_DIR}/third-party/flatcc/lib/*
140+
rm -f ${_flatcc_source_dir}/bin/*
141+
${_flatcc_source_dir}/lib/*
139142
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/sdk
140143
DEPENDS flatcc_project
141144
COMMENT "Generating etdump headers"
@@ -172,7 +175,7 @@ target_include_directories(
172175

173176
target_include_directories(
174177
etdump PUBLIC ${_program_schema__include_dir}
175-
${CMAKE_SOURCE_DIR}/third-party/flatcc/include)
178+
${_flatcc_source_dir}/include)
176179

177180
# Install libraries
178181
install(

0 commit comments

Comments
 (0)