Skip to content

Commit d9314de

Browse files
committed
Add back _refresh_cache_if_necessary
1 parent 54685fa commit d9314de

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

third-party/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ endif()
1616

1717
FetchContent_gflags()
1818
# Create a symlink from the gflags source directory to third-party/gflags
19-
message(STATUS "gflags source dir: ${gflags_SOURCE_DIR}")
19+
message(STATUS "Creating a symlink from ${gflags_SOURCE_DIR} to third-party/gflags")
2020
execute_process(
2121
COMMAND ${CMAKE_COMMAND} -E create_symlink "${gflags_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/gflags"
2222
)

tools/cmake/FetchContent.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,30 @@
88
# Make the content available at configure time so that BUCK can use it.
99
include(FetchContent)
1010

11+
# Some third-party libraries need to be materialized in the source tree for
12+
# buck. Unfortunately, FetchContent bakes in generator information in the
13+
# fetched content. Thus, if the generator is changed, it causes build failures.
14+
# So, if the generator has changed, then nuke the content.
15+
function(_refresh_cache_if_necessary DIR)
16+
set(_generator_stamp_file "${DIR}/.executorch_cmake_generator_stamp")
17+
set(_current_generator "${CMAKE_GENERATOR}")
18+
19+
if(EXISTS "${_generator_stamp_file}")
20+
file(READ "${_generator_stamp_file}" _previous_generator)
21+
string(STRIP "${_previous_generator}" _previous_generator)
22+
if(NOT _previous_generator STREQUAL _current_generator)
23+
file(REMOVE_RECURSE ${DIR})
24+
endif()
25+
endif()
26+
27+
file(WRITE "${_generator_stamp_file}" "${_current_generator}")
28+
endfunction()
29+
1130
function(FetchContent_gflags)
31+
if(NOT ${gflags_SOURCE_DIR} STREQUAL "")
32+
_refresh_cache_if_necessary(${gflags_SOURCE_DIR})
33+
endif()
34+
1235
FetchContent_Declare(
1336
gflags
1437
GIT_REPOSITORY https://github.com/gflags/gflags.git

0 commit comments

Comments
 (0)