Commit 01b87a0f authored by Craig Scott's avatar Craig Scott
Browse files

FetchContent: Avoid including ExternalProject more than once

Even with the call to include_guard() at the top of the ExternalProject
module, including it still shows up in profiling runs. It only needs to be
included once when we include FetchContent, not every time we do a
population.

Relates: #21703
parent efd1127d
......@@ -1241,21 +1241,10 @@ if(NOT DEFINED CMAKE_SCRIPT_MODE_FILE)
)
endif()
# Unlike configure_file(), this implementation avoids writing any files at all
# if the new contents match existing contents. This makes it more efficient on
# systems where writing files has poor performance.
function(_ep_configure_file source_filename destination_filename)
file(READ ${destination_filename} existing_contents)
file(READ ${source_filename} source_template)
string(CONFIGURE "${source_template}" new_contents ${ARGN})
if(NOT new_contents STREQUAL existing_contents)
file(WRITE ${destination_filename} "${new_contents}")
endif()
endfunction()
# A more specialized version of the above where we already have the new
# contents and just want to avoid writing a file if the existing contents
# already match.
# Unlike configure_file(), the implementations of this function and the next
# avoid writing any files at all if the new contents match existing contents.
# This makes them more efficient on systems where writing files has poor
# performance.
function(_ep_write_if_different filename new_contents)
if(EXISTS ${filename})
file(READ ${filename} existing_contents)
......@@ -1266,6 +1255,14 @@ function(_ep_write_if_different filename new_contents)
file(WRITE ${filename} "${new_contents}")
endfunction()
# More efficient drop-in replacement for configure_file()
function(_ep_configure_file source_filename destination_filename)
file(READ ${source_filename} source_template)
string(CONFIGURE "${source_template}" new_contents ${ARGN})
_ep_write_if_different(${destination_filename} "${new_contents}")
endfunction()
function(_ep_write_gitclone_script
script_filename
source_dir
......
......@@ -836,6 +836,7 @@ endfunction()
#=======================================================================
# Performing the population
#=======================================================================
include(ExternalProject) # Only need to do this once, not per call
# The value of contentName will always have been lowercased by the caller.
# All other arguments are assumed to be options that are understood by
......@@ -899,7 +900,6 @@ function(__FetchContent_directPopulate contentName)
message(STATUS "Populating ${contentName}")
endif()
include(ExternalProject)
set(argsQuoted)
foreach(__item IN LISTS ARG_UNPARSED_ARGUMENTS)
string(APPEND argsQuoted " [==[${__item}]==]")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment